Skip to content

Commit

Permalink
tools: fix support for multi-arch packages on apt-based systems (#54)
Browse files Browse the repository at this point in the history
* tests.pkg: fix missing quoting around $@

While fixing that, fix the "remove many packages" subcommand not to
quote all the list as one large argument.

Signed-off-by: Zygmunt Krynicki <[email protected]>

* tests.pkg: fix handling of architecture specific packages

The tests.pkg file, when using an apt backend, would easily get confused
when a test had installed a package from another architecture, such as
i386, as the architecture would be discarded by the logic. This could
easily lead to attempt to remove the amd64 version of the package,
causing utter havoc.

Signed-off-by: Zygmunt Krynicki <[email protected]>

* tests.pkg: use --allow-remove-essential

This allows removal of base i386 packages that got pulled in on an amd64
host while installing multi-arch packages.

Signed-off-by: Zygmunt Krynicki <[email protected]>

* tests: test multi-arch logic

Signed-off-by: Zygmunt Krynicki <[email protected]>

* adapt packages by system and fix test

---------

Signed-off-by: Zygmunt Krynicki <[email protected]>
Co-authored-by: Sergio Cazzolato <[email protected]>
  • Loading branch information
zyga and sergiocazzolato authored Aug 12, 2024
1 parent 33aa8d1 commit 8743cea
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
8 changes: 8 additions & 0 deletions tests/tests.pkgs/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ execute: |
tests.pkgs noexist test-snapd-pkg-1 2>&1 | MATCH 'tests.pkgs: unknown command noexist'
tests.pkgs -install test-snapd-pkg-1 2>&1 | MATCH 'tests.pkgs: unknown option -install'
# Install the test pkg and check it is installed and query it
# run this just on amd64 architecture and skip trusty
if ( os.query is-debian || os.query is-ubuntu-ge 1604 ) && os.query is-pc-amd64 ; then
dpkg --add-architecture i386
tests.pkgs install test-snapd-pkg-3
tests.pkgs is-installed test-snapd-pkg-3
tests.pkgs remove test-snapd-pkg-3
fi
3 changes: 2 additions & 1 deletion tools/tests.pkgs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ main() {
cmd_list_installed
;;
remove)
cmd_remove "$(remap_many "$@")"
# shellcheck disable=SC2046
cmd_remove $(remap_many "$@")
;;
*)
echo "tests.pkgs: unknown action $action" >&2
Expand Down
28 changes: 22 additions & 6 deletions tools/tests.pkgs.apt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ remap_one() {
test-snapd-pkg-2)
echo "robotfindskitten"
;;
test-snapd-pkg-3)
if os.query is-debian || os.query is-trusty; then
echo cpp:i386
elif os.query is-xenial || os.query is-bionic; then
echo cpp-5:i386
else
echo cpp-9:i386
fi
;;
*)
echo "$1"
;;
Expand All @@ -43,23 +52,30 @@ cmd_install() {
;;
esac
done
# shellcheck disable=SC2068,SC2086
apt-get install $APT_FLAGS $@
# shellcheck disable=SC2086
apt-get install $APT_FLAGS "$@"
}

cmd_is_installed() {
dpkg -S "$1" >/dev/null 2>&1
dpkg -l "$1" | grep -E "ii +$1" >/dev/null 2>&1
}

cmd_query() {
apt-cache policy "$1"
}

cmd_list_installed() {
apt list --installed | cut -d/ -f1 | sort
apt list --installed | cut -d ' ' -f 1,3 | sed -e 's@/.*\s@:@g' | sort
}

cmd_remove() {
# shellcheck disable=SC2068
apt-get remove --yes $@
# Allow removing essential packages, that may get installed when using i386
# packages on amd64 system. Normally they would be really essential but in
# this case they are not really as essential.
local REMOVE_FLAGS="--allow-remove-essential"
if os.query is-trusty; then
REMOVE_FLAGS=""
fi
# shellcheck disable=SC2086
apt-get remove --yes $REMOVE_FLAGS "$@"
}

0 comments on commit 8743cea

Please sign in to comment.