File: bash_os_linux_conditional.bats.jinja

package info (click to toggle)
scap-security-guide 0.1.76-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 110,644 kB
  • sloc: xml: 241,883; sh: 73,777; python: 32,527; makefile: 27
file content (119 lines) | stat: -rw-r--r-- 4,772 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash

set -pu

is_old_bats=0

setup() {
    if [[ -z "${BATS_TEST_TMPDIR:-}" ]] || [[ ! -d "${BATS_TEST_TMPDIR}" ]]; then
        BATS_TEST_TMPDIR="$(mktemp -d)"  # 1.4.0
        # shellcheck disable=SC2034
        BATS_TEARDOWN_STARTED=  # 1.3.0
        is_old_bats=1
    else
        is_old_bats=0
    fi
    pushd "${BATS_TEST_TMPDIR}" || exit 1
    os_release_path="os-release"
}

teardown() {
    if (( is_old_bats )); then
        if [[ -z "${BATS_TEST_TMPDIR:-}" ]] || [[ ! -d "${BATS_TEST_TMPDIR}" ]]; then
            >&2 echo "INTERNAL ERROR"
            exit 3
        fi
        local tmppath xpwd
        tmppath="$(readlink -f -- "${BATS_TEST_TMPDIR}")"
        if [[ ! "${tmppath}" =~ ^/tmp/ ]] || [[ ! -d "${tmppath}" ]]; then
            >&2 echo "INTERNAL ERROR"
            exit 3
        fi
        xpwd="$(readlink -f -- .)"
        if [[ "${tmppath}" != "${xpwd}" ]]; then
            >&2 echo "INTERNAL ERROR"
            exit 3
        fi
        popd || exit 1
        rm -rf -- "${tmppath}"
        BATS_TEST_TMPDIR=""
    fi
}

@test "bash_os_linux_conditional - test OS release - RHEL" {
    cat << EOF > "$os_release_path"
NAME="Red Hat Enterprise Linux"
VERSION="9.2 (Plow)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="9.2"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Red Hat Enterprise Linux 9.2 Beta (Plow)"
ANSI_COLOR="0;31"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:redhat:enterprise_linux:9::baseos"
HOME_URL="https://www.redhat.com/"
DOCUMENTATION_URL="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 9"
REDHAT_BUGZILLA_PRODUCT_VERSION=9.2
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.2 Beta"
EOF

    {{{ bash_os_linux_conditional("rhel", os_release_path="$os_release_path") }}}
    ! ( {{{ bash_os_linux_conditional("ubuntu", os_release_path="$os_release_path") }}} )

    {{{ bash_os_linux_conditional("rhel", "9", ">", "$os_release_path") }}}
    {{{ bash_os_linux_conditional("rhel", "9.1", ">", "$os_release_path") }}}
    {{{ bash_os_linux_conditional("rhel", "9.1.4", ">", "$os_release_path") }}}
    {{{ bash_os_linux_conditional("rhel", "9.2", ">=", "$os_release_path") }}}
    {{{ bash_os_linux_conditional("rhel", "9.2", "==", "$os_release_path") }}}
    {{{ bash_os_linux_conditional("rhel", "9.2", "<=", "$os_release_path") }}}
    {{{ bash_os_linux_conditional("rhel", "9.4", "!=", "$os_release_path") }}}
    {{{ bash_os_linux_conditional("rhel", "9.4", "<", "$os_release_path") }}}
    {{{ bash_os_linux_conditional("rhel", "9.2.7", "<", "$os_release_path") }}}
    {{{ bash_os_linux_conditional("rhel", "10", "<", "$os_release_path") }}}
    {{{ bash_os_linux_conditional("rhel", "10.2", "<", "$os_release_path") }}}

    ! ( {{{ bash_os_linux_conditional("fedora", "38", "==", "$os_release_path") }}} )
    ! ( {{{ bash_os_linux_conditional("fedora", "9.2", "==", "$os_release_path") }}} )
    ! ( {{{ bash_os_linux_conditional("fedora", "9.4", "<", "$os_release_path") }}} )
}

@test "bash_os_linux_conditional - test OS release - Ubuntu" {
    cat << EOF > "$os_release_path"
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
EOF


    {{{ bash_os_linux_conditional("ubuntu", os_release_path="$os_release_path") }}}
    ! ( {{{ bash_os_linux_conditional("rhel", os_release_path="$os_release_path") }}} )

    {{{ bash_os_linux_conditional("ubuntu", "20.10", ">", "$os_release_path") }}}
    {{{ bash_os_linux_conditional("ubuntu", "22.03", ">", "$os_release_path") }}}
    {{{ bash_os_linux_conditional("ubuntu", "22.04", ">=", "$os_release_path") }}}
    {{{ bash_os_linux_conditional("ubuntu", "22.04", "==", "$os_release_path") }}}
    {{{ bash_os_linux_conditional("ubuntu", "22.04", "<=", "$os_release_path") }}}
    {{{ bash_os_linux_conditional("ubuntu", "22.10", "!=", "$os_release_path") }}}
    {{{ bash_os_linux_conditional("ubuntu", "22.10", "<=", "$os_release_path") }}}
    {{{ bash_os_linux_conditional("ubuntu", "22.10", "<", "$os_release_path") }}}

    ! ( {{{ bash_os_linux_conditional("ubuntu", "20.10", "<", "$os_release_path") }}} )
    ! ( {{{ bash_os_linux_conditional("ubuntu", "22.10", ">", "$os_release_path") }}} )

    ! ( {{{ bash_os_linux_conditional("fedora", "38", "==", "$os_release_path") }}} )
    ! ( {{{ bash_os_linux_conditional("fedora", "22.10", "<", "$os_release_path") }}} )
}