Skip to content

Commit

Permalink
toltecctl: Honour dependencies when uninstalling
Browse files Browse the repository at this point in the history
`toltecctl uninstall` will now try to uninstall packages in the reverse order of their dependencies, so that a package can use binaries it depends on during its removal scripts (see #448). Packages in a dependency cycle are removed in an unspecified order.

Test plan: Upgrade `toltec-bootstrap`, install some packages, then run `toltecctl uninstall`. You should see packages removed in reverse dependency order, so for example:

* `libc`, `libpthread`, `libgcc` should generally be the last removed packages
* graphical apps should get removed before `display`
* `toltec-bootstrap` should get removed before `coreutils-tsort`
  • Loading branch information
matteodelabre committed Oct 6, 2021
1 parent b297c1d commit fdafa6c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
5 changes: 3 additions & 2 deletions package/toltec-bootstrap/package
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
pkgnames=(toltec-bootstrap)
pkgdesc="Manage your Toltec install"
url=https://toltec-dev.org/
pkgver=0.2.0-1
timestamp=2021-09-25T10:36Z
pkgver=0.2.1-1
timestamp=2021-10-06T07:51Z
section="utils"
maintainer="Eeems <[email protected]>"
license=MIT
installdepends=(coreutils-tsort)

source=(
toltecctl
Expand Down
40 changes: 38 additions & 2 deletions package/toltec-bootstrap/toltecctl
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,46 @@ reenable() {
set-path
}

# Remove all installed packages
# List all installed packages such that any package comes before
# its dependencies. Dependency cycles are broken arbitrarily
list-installed-ordered() {
# shellcheck disable=SC2016
local awk_trim='NR>1 {print gensub(/^[ \t]+|[ \t]+$/, "", "g", $0);}'

opkg list-installed | awk -F' - ' '{print $1}' | while read -r srcpkg; do
# Make sure all packages are included even when they don’t have
# any dependencies
echo "$srcpkg $srcpkg"

# List all dependencies for this package
opkg depends "$srcpkg" | awk "$awk_trim" | while read -r dstpkg; do
echo "$srcpkg $dstpkg"
done
done | tsort 2> /dev/null || true
# tsort reports errors if there are dependency cycles, we ignore them
}

# Remove Toltec completely
uninstall() {
opkg remove --force-depends --force-remove "*"
# Fetch standalone opkg used to uninstall packages
local opkg_path=/home/root/.local/bin/opkg
local opkg_remote=https://bin.entware.net/armv7sf-k3.2/installer/opkg

if ! wget --no-verbose "$opkg_remote" --output-document "$opkg_path"; then
echo "Unable to fetch standalone opkg, make sure you have a stable Wi-Fi connection"
return 1
fi

chmod u+x "$opkg_path"

# Remove installed packages in reverse dependency order
echo "Collecting installed packages"
list-installed-ordered | while read -r pkgname; do
"$opkg_path" remove --force-depends --force-remove "$pkgname"
done

systemctl daemon-reload
rm -f "$opkg_path"

# Remove mount point
remove-bind-mount "$toltec_dest"
Expand Down

0 comments on commit fdafa6c

Please sign in to comment.