summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2020-11-11 16:49:17 (EST)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2020-11-22 16:57:57 (EST)
commitdd3d64da2f1fb5966b7b1bd36b20ab902f1ccedd (patch)
tree224dbdae4be0cbac547aa67200fbd0a0fef5f687
parent0a3062c451449727488fa29236822c2715ceca81 (diff)
opkg: Save /bin/busybox and make links
This works around a regression in opkg-lede that thoroughly breaks upgrading the busybox package and also allows all of busybox's utility links to be managed using update-alternatives. /bin/busybox is copied instead of hard linked, because /var might be on a separate file system (e.g. tmpfs).
-rw-r--r--changelog10
-rwxr-xr-xopkg45
2 files changed, 51 insertions, 4 deletions
diff --git a/changelog b/changelog
index d14b168..c72e1be 100644
--- a/changelog
+++ b/changelog
@@ -1,8 +1,12 @@
opkg-lede (0+git20190131.d4ba162-7) trunk
- * opkg-lede: Add a multiarch support wrapper script as "/usr/bin/opkg"
- and move the real opkg binary back to its default location at
- "/usr/bin/opkg-cl".
+ * opkg-lede: Add a wrapper script as "/usr/bin/opkg" and move the real
+ opkg binary back to its default location at "/usr/bin/opkg-cl".
+ This wrapper script:
+ - Enables the busybox package to be safely upgraded (opkg-lede
+ attempts to execute gzip after removing busybox, whereas opkg
+ didn't) and
+ - Accepts an -a/--host-architecture option for multiarch support.
-- Patrick McDermott <patrick.mcdermott@libiquity.com> Thu, 18 Jun 2020 12:50:01 -0400
diff --git a/opkg b/opkg
index 54e2886..33ec19f 100755
--- a/opkg
+++ b/opkg
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/busybox sh
#
# opkg - Multiarch support wrapper for opkg
#
@@ -19,6 +19,45 @@
set -eu
+BB='/bin/busybox'
+BIN='/var/lib/opkg/bin'
+
+save_bb()
+{
+ local file=
+ local link=
+ local name=
+ local prio=
+
+ "${BB}" mkdir "${BIN}" 2>/dev/null || :
+ "${BB}" cp -p "${BB}" "${BIN}/busybox"
+
+ while read file; do
+ case "${file}" in
+ /bin/busybox) ;;
+ /bin/?* | /sbin/?* | /usr/bin/?* | /usr/sbin/?*)
+ "${BB}" ln -sf 'busybox' "${BIN}/${file##*/}"
+ ;;
+ esac
+ done 0<<-EOF
+ $(/usr/bin/opkg-cl files busybox)
+ EOF
+
+ while read link name prio; do
+ "${BB}" ln -sf 'busybox' "${BIN}/${link##*/}"
+ done 0</usr/share/busybox/alternatives
+
+ export PATH="${PATH}:${BIN}"
+ export OPKG_BUSYBOX_SAVED='1'
+
+ return 0
+}
+
+unsave_bb()
+{
+ rm -f "${BIN}/"*
+}
+
main()
{
local first_arg=
@@ -80,9 +119,13 @@ main()
return 1
fi
+ save_bb
+
if /usr/bin/opkg-cl "${@}"; then
+ unsave_bb
return 0
else
+ unsave_bb
return ${?}
fi
}