File: tests.pkgs

package info (click to toggle)
snapd 2.49-1%2Bdeb11u2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 36,432 kB
  • sloc: ansic: 12,125; sh: 8,453; python: 2,163; makefile: 1,284; exp: 173; xml: 22
file content (143 lines) | stat: -rwxr-xr-x 3,374 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash -e

show_help() {
    echo "usage: tests.pkgs {install,remove} [PACKAGE...]"
    echo "       tests.pkgs {is-installed,query} [PACKAGE]"
    echo
    echo "Package names are standardized based on Debian package names"
    echo "internally, package names are re-mapped to fit the convention"
    echo "of the used system."
}

unsupported() {
    echo "tests.pkgs: cannot manage packages on this system" >&2
    exit 1
}

cmd_install() {
    # This is re-defined by the backend file.
    unsupported
}

cmd_is_installed() {
    # This is re-defined by the backend file.
    unsupported
}

cmd_query() {
    # This is re-defined by the backend file.
    unsupported
}

cmd_remove() {
    # This is re-defined by the backend file.
    unsupported
}

remap_one() {
    # This may be re-defined by the backend file.
    echo "$1"
}

remap_many() {
    local many
    many=""
    for pkg in "$@"; do
        if [ -z "$many" ]; then
            many="$(remap_one "$pkg")"
        else
            many="$many $(remap_one "$pkg")"
        fi
    done
    echo "$many"
}

import_backend() {
    case "$1" in
        ubuntu-core-*)
            echo "tests.pkgs: Ubuntu Core is not supported" >&2
            exit 1
            ;;
        ubuntu-*|debian-*)
            #shellcheck source=tests/lib/tools/tests.pkgs.apt.sh
            . "$TESTSLIB/tools/tests.pkgs.apt.sh"
            ;;
        fedora-*|centos-*|redhat-*|amazon-*)
            #shellcheck source=tests/lib/tools/tests.pkgs.dnf-yum.sh
            . "$TESTSLIB/tools/tests.pkgs.dnf-yum.sh"
            ;;
        opensuse-*)
            #shellcheck source=tests/lib/tools/tests.pkgs.zypper.sh
            . "$TESTSLIB/tools/tests.pkgs.zypper.sh"
            ;;
        arch-*)
            #shellcheck source=tests/lib/tools/tests.pkgs.pacman.sh
            . "$TESTSLIB/tools/tests.pkgs.pacman.sh"
            ;;
        *)
            echo "tests.pkgs: cannot import packaging backend $1" >&2
            exit 1
            ;;
    esac
}

main() {
    if [ $# -eq 0 ]; then
        show_help
        exit 1
    fi

    if [ -z "${SPREAD_SYSTEM:-}" ]; then
        echo "tests.pkg: cannot manage packages without knowing SPREAD_SYSTEM" >&2
        exit 1
    fi
    import_backend "$SPREAD_SYSTEM"

    action=
    while [ $# -gt 0 ]; do
        case "$1" in
            -h|--help)
                show_help
                exit 0
                ;;
            --)
                shift
                break
                ;;
            install|remove|query|is-installed)
                action="$1"
                shift
                break  # consume remaining arguments
                ;;
            -*)
                echo "tests.pkgs: unknown option $1" >&2
                exit 1
                ;;
            *)
                echo "tests.pkgs: unknown command $1" >&2
                exit 1
                ;;
        esac
    done

    case "$action" in
        install)
            cmd_install "$(remap_many "$@")"
            ;;
        is-installed)
            cmd_is_installed "$(remap_one "$@")"
            ;;
        query)
            cmd_query "$(remap_one "$@")"
            ;;
        remove)
            cmd_remove "$(remap_many "$@")"
            ;;
        *)
            echo "tests.pkgs: unknown action $action" >&2
            exit 1
            ;;
    esac
}

main "$@"