summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/busybox
diff options
context:
space:
mode:
authorJeremy Puhlman <jpuhlman@mvista.com>2020-04-02 15:58:20 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-04-03 14:49:13 +0100
commita9d2af8f5b3da8239cf00a52883ca596a19ea23a (patch)
tree03df75a661fd5ceef452709f9fc47bdfe9ff35a5 /meta/recipes-core/busybox
parenta22200a646eaf42cd4902a2fe3358d29717ac129 (diff)
downloadopenembedded-core-contrib-a9d2af8f5b3da8239cf00a52883ca596a19ea23a.tar.gz
busybox: on upgrade save busybox if it is the last shell
During a busybox upgrade on a ipk based system, it is possible that busybox is the only shell in the system. During the uninstall the alternative for /bin/sh is removed and everything after that goes down hill. * Add a check to verify if busybox is the shell, and save it to the busyboxrm directory created in tmp. Then add an alternative for /bin/sh that points to that busybox at the lowest priority. * Add PATH to the busyboxrm directory using shell(as during an upgrade busybox and its links are missing). * When install over remove extra busybox if present. deb and rpm are uneffected by the bug because they both drag in bash, however neither upgrade seemed to have issue with the changes. [YOCTO 13850] Signed-off-by: Jeremy A. Puhlman <jpuhlman@mvista.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-core/busybox')
-rw-r--r--meta/recipes-core/busybox/busybox.inc43
1 files changed, 43 insertions, 0 deletions
diff --git a/meta/recipes-core/busybox/busybox.inc b/meta/recipes-core/busybox/busybox.inc
index 1a82f23b0f..344e891f7a 100644
--- a/meta/recipes-core/busybox/busybox.inc
+++ b/meta/recipes-core/busybox/busybox.inc
@@ -433,6 +433,32 @@ fi
d.prependVar('pkg_postinst_%s' % pkg, postinst)
}
+pkg_postinst_${PN}_prepend () {
+ # Need path to saved utils, but they may have be removed on upgrade of busybox
+ # Only use shell to get paths. Also capture if busybox was saved.
+ BUSYBOX=""
+ if [ "x$D" = "x" ] ; then
+ for busybox_rmdir in /tmp/busyboxrm-*; do
+ if [ "$busybox_rmdir" != '/tmp/busyboxrm-*' ] ; then
+ export PATH=$busybox_rmdir:$PATH
+ if [ -e $busybox_rmdir/busybox* ] ; then
+ BUSYBOX="$busybox_rmdir/busybox*"
+ fi
+ fi
+ done
+ fi
+}
+
+pkg_postinst_${PN}_append () {
+ # If busybox exists in the remove directory it is because it was the only shell left.
+ if [ "x$D" = "x" ] ; then
+ if [ "x$BUSYBOX" != "x" ] ; then
+ update-alternatives --remove sh $BUSYBOX
+ rm -f $BUSYBOX
+ fi
+ fi
+}
+
pkg_prerm_${PN} () {
# This is so you can make busybox commit suicide - removing busybox with no other packages
# providing its files, this will make update-alternatives work, but the update-rc.d part
@@ -453,9 +479,26 @@ pkg_prerm_${PN} () {
ln -s ${base_bindir}/busybox $tmpdir/grep
ln -s ${base_bindir}/busybox $tmpdir/tail
export PATH=$PATH:$tmpdir
+
+ # If busybox is the shell, we need to save it since its the lowest priority shell
+ # Register saved bitbake as the lowest priority shell possible as back up.
+ if [ -n "$(readlink -f /bin/sh | grep busybox)" ] ; then
+ BUSYBOX=$(readlink -f /bin/sh)
+ cp $BUSYBOX $tmpdir/$(basename $BUSYBOX)
+ update-alternatives --install /bin/sh sh $tmpdir/$(basename $BUSYBOX) 1
+ fi
}
pkg_postrm_${PN} () {
+ # Add path to remove dir in case we removed our only grep
+ if [ "x$D" = "x" ] ; then
+ for busybox_rmdir in /tmp/busyboxrm-*; do
+ if [ "$busybox_rmdir" != '/tmp/busyboxrm-*' ] ; then
+ export PATH=$busybox_rmdir:$PATH
+ fi
+ done
+ fi
+
if grep -q "^${base_bindir}/bash$" $D${sysconfdir}/busybox.links* && [ ! -e $D${base_bindir}/bash ]; then
printf "$(grep -v "^${base_bindir}/bash$" $D${sysconfdir}/shells)\n" > $D${sysconfdir}/shells
fi