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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
#!/bin/bash -e
show_help() {
echo "usage: tests.pkgs install [--no-install-recommends] [PACKAGE...]"
echo " tests.pkgs remove [PACKAGE...]"
echo " tests.pkgs download [PACKAGE...]"
echo " tests.pkgs is-installed [PACKAGE]"
echo " tests.pkgs query [PACKAGE]"
echo " tests.pkgs list-installed"
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_install_local() {
# This is re-defined by the backend file.
unsupported
}
cmd_download() {
# 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_list_installed() {
# 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() {
local TOOLS_DIR
TOOLS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
if [ -n "$TESTSTOOLS" ]; then
TOOLS_DIR="$TESTSTOOLS"
fi
if os.query is-core; then
echo "tests.pkgs: Ubuntu Core is not supported" >&2
return 1
elif os.query is-ubuntu || os.query is-debian; then
# Disabled because when the project is imported as a submodule the
# source is not found failing with SC1090 and SC1091
#shellcheck disable=SC1090,SC1091
. "$TOOLS_DIR/tests.pkgs.apt.sh"
elif os.query is-fedora || os.query is-centos || os.query is-amazon-linux; then
# Disabled because when the project is imported as a submodule the
# source is not found failing with SC1090 and SC1091
#shellcheck disable=SC1090,SC1091
. "$TOOLS_DIR/tests.pkgs.dnf-yum.sh"
elif os.query is-opensuse; then
# Disabled because when the project is imported as a submodule the
# source is not found failing with SC1090 and SC1091
#shellcheck disable=SC1090,SC1091
. "$TOOLS_DIR/tests.pkgs.zypper.sh"
elif os.query is-arch-linux; then
# Disabled because when the project is imported as a submodule the
# source is not found failing with SC1090 and SC1091
#shellcheck disable=SC1090,SC1091
. "$TOOLS_DIR/tests.pkgs.pacman.sh"
else
echo "tests.pkgs: cannot import packaging backend" >&2
return 1
fi
}
main() {
if [ $# -eq 0 ]; then
show_help
exit 1
fi
import_backend
action=
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
show_help
exit 0
;;
--)
shift
break
;;
install|remove|query|is-installed|list-installed|download)
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)
# shellcheck disable=SC2046
cmd_install $(remap_many "$@")
;;
is-installed)
cmd_is_installed "$(remap_one "$@")"
;;
query)
cmd_query "$(remap_one "$@")"
;;
list-installed)
cmd_list_installed
;;
remove)
# shellcheck disable=SC2046
cmd_remove $(remap_many "$@")
;;
download)
# shellcheck disable=SC2046
cmd_download $(remap_many "$@")
;;
*)
echo "tests.pkgs: unknown action $action" >&2
exit 1
;;
esac
}
main "$@"
|