Skip to content

Commit

Permalink
toltecctl: Honour dependencies when uninstalling (#456)
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.
  • Loading branch information
matteodelabre authored and Eeems committed Oct 22, 2021
1 parent 42948cb commit 23cea4d
Show file tree
Hide file tree
Showing 2 changed files with 39 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
38 changes: 36 additions & 2 deletions package/toltec-bootstrap/toltecctl
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,44 @@ 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_list_to_graph='
/^.* depends on:$/{
from=$1;
print from " " from;
}
/^\t/{
print from " " $1;
}
'
opkg depends '*' | awk "$awk_list_to_graph" | 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
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 23cea4d

Please sign in to comment.