From: Jeremy Puhlman <[email protected]>
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.
Backported from master and reworked for thud since the postinst
scripts are handled slightly differently in the metadata.
[YOCTO 13850]
---
meta/recipes-core/busybox/busybox.inc | 51 +++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/meta/recipes-core/busybox/busybox.inc
b/meta/recipes-core/busybox/busybox.inc
index 0c0d26ed3a..571a9dd626 100644
--- a/meta/recipes-core/busybox/busybox.inc
+++ b/meta/recipes-core/busybox/busybox.inc
@@ -418,6 +418,40 @@ pkg_postinst_${PN} () {
fi
}
+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
+}
+
+busybox_postinst_close () {
+ # 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
+}
+
+populate_packages_updatealternatives_append () {
+ pkg=d.getVar("PN")
+ closing = d.getVar("busybox_postinst_close")
+ postinst = d.getVar('pkg_postinst_%s' % pkg)
+ postinst += closing
+ d.setVar('pkg_postinst_%s' % pkg, postinst)
+}
+
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
@@ -438,9 +472,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
--
2.20.1
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#137004):
https://lists.openembedded.org/g/openembedded-core/message/137004
Mute This Topic: https://lists.openembedded.org/mt/72763574/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-