Skip to content

Commit c913a96

Browse files
matteodelabreEeems
authored andcommitted
toltecctl: Honour dependencies when uninstalling (#456)
`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.
1 parent 07564af commit c913a96

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

package/toltec-bootstrap/package

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
pkgnames=(toltec-bootstrap)
66
pkgdesc="Manage your Toltec install"
77
url=https://toltec-dev.org/
8-
pkgver=0.2.0-1
9-
timestamp=2021-09-25T10:36Z
8+
pkgver=0.2.1-1
9+
timestamp=2021-10-06T07:51Z
1010
section="utils"
1111
maintainer="Eeems <eeems@eeems.email>"
1212
license=MIT
13+
installdepends=(coreutils-tsort)
1314

1415
source=(
1516
toltecctl

package/toltec-bootstrap/toltecctl

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,44 @@ reenable() {
305305
set-path
306306
}
307307

308-
# Remove all installed packages
308+
# List all installed packages such that any package comes before
309+
# its dependencies. Dependency cycles are broken arbitrarily
310+
list-installed-ordered() {
311+
# shellcheck disable=SC2016
312+
local awk_list_to_graph='
313+
/^.* depends on:$/{
314+
from=$1;
315+
print from " " from;
316+
}
317+
318+
/^\t/{
319+
print from " " $1;
320+
}
321+
'
322+
opkg depends '*' | awk "$awk_list_to_graph" | tsort 2> /dev/null || true
323+
# tsort reports errors if there are dependency cycles, we ignore them
324+
}
325+
326+
# Remove Toltec completely
309327
uninstall() {
310-
opkg remove --force-depends --force-remove "*"
328+
# Fetch standalone opkg used to uninstall packages
329+
local opkg_path=/home/root/.local/bin/opkg
330+
local opkg_remote=https://bin.entware.net/armv7sf-k3.2/installer/opkg
331+
332+
if ! wget --no-verbose "$opkg_remote" --output-document "$opkg_path"; then
333+
echo "Unable to fetch standalone opkg, make sure you have a stable Wi-Fi connection"
334+
return 1
335+
fi
336+
337+
chmod u+x "$opkg_path"
338+
339+
# Remove installed packages in reverse dependency order
340+
list-installed-ordered | while read -r pkgname; do
341+
"$opkg_path" remove --force-depends --force-remove "$pkgname"
342+
done
343+
311344
systemctl daemon-reload
345+
rm -f "$opkg_path"
312346

313347
# Remove mount point
314348
remove-bind-mount "$toltec_dest"

0 commit comments

Comments
 (0)