Bug#152361: links to busybox binary for every applet compiled in
Package: busybox
Version: 1:1.17.1-8
Severity: normal
Hi,
The busybox package does not provide automatic link generation (neither by
diversion nor by update-alternative mechanism).
As far as I understood diversion, every package involved need to be updated in
post/preinstall and post/preremove. That's a bit heavy just for a low number of
users who like to use busybox for small sized rootfs (embedded, containers,
thinclients). Because busybox does not provide the FULL functionality of the
GNU version, the update-alternative mechanism propably does not apply here,
too.
So I have written a simple script which looks for the big gnu version of the
applets currently compiled in busybox and creates the links to the busybox
binary. Feel free to integrate it in /usr/share/busybox or something similar
location.
Regards,
Marcus
-- System Information:
Debian Release: 6.0.3
APT prefers stable
APT policy: (500, 'stable')
Architecture: amd64 (x86_64)
Kernel: Linux 3.1.0-1-amd64 (SMP w/1 CPU core)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages busybox depends on:
ii libc6 2.11.2-10 Embedded GNU C Library: Shared lib
busybox recommends no packages.
busybox suggests no packages.
-- no debconf information
#!/bin/sh
##!/bin/busybox sh #works too
#
# Simple script which tries to set a link
# for all busybox applets currently compiled in busybox executable
#
# Author: Marcus Osdoba, BSD 2-clause license
#
# set -x
TARGET_LINKDIR=${TARGET_LINKDIR:-/usr/local/bin}
BB_BINARY=${BB_BINARY:-/bin/busybox}
TMPDIR=${TMPDIR:-/tmp}
[ -w $TMPDIR/BB_LINK_CREATED ] && ${BB_BINARY} rm $TMPDIR/BB_LINK_CREATED; ${BB_BINARY} touch $TMPDIR/BB_LINK_CREATED
[ -w $TMPDIR/BB_GNU_FOUND ] && ${BB_BINARY} rm $TMPDIR/BB_GNU_FOUND ; ${BB_BINARY} touch $TMPDIR/BB_GNU_FOUND
[ -w $TMPDIR/BB_LINK_FAILED ] && ${BB_BINARY} rm $TMPDIR/BB_LINK_FAILED ; ${BB_BINARY} touch $TMPDIR/BB_LINK_FAILED
usage() {
${BB_BINARY} echo "This script launches busybox and generates links in \$TARGET_LINKDIR (default: /usr/local/bin)."
${BB_BINARY} echo "If you like to place the links in a different directory call:"
${BB_BINARY} echo "#>export TARGET_LINKDIR=/home/me/bin; $0 "
${BB_BINARY} echo "The links are created for every applet compiled in and whose GNU brother is NOT found."
${BB_BINARY} echo "Existing links to the busybox binary are deleted if the GNU version is present"
${BB_BINARY} echo "(e.g. because of subsequent installation)."
}
checks() {
if [ ! -x $BB_BINARY ]
then
${BB_BINARY} echo "Could not find busybox using location: $BB_BINARY."
return 1
fi
if [ ! -w $TARGET_LINKDIR ]
then
${BB_BINARY} echo "Target directory $TARGET_LINKDIR is not writable. Cannot create links."
return 1
fi
if [ ! -w $TARGET_LINKDIR ]
then
${BB_BINARY} echo "Target directory $TARGET_LINKDIR is not writable. Cannot create links."
return 1
fi
if [ ! -w $TMPDIR ]
then
${BB_BINARY} echo "Temp directory is not writable. Cannot create temporary output."
return 1
fi
return 0
}
createlinks() {
$BB_BINARY > $TMPDIR/BB_OUTPUT
BIG_GNUVERSION_LOCATION=$(${BB_BINARY} echo $PATH|${BB_BINARY} sed 's/:/ /g')
${BB_BINARY} echo "Searching for big GNU version of applets in $BIG_GNUVERSION_LOCATION ."
${BB_BINARY} sed -e '/./{H;$!d;}' -e 'x;/Currently defined functions:/!d;' $TMPDIR/BB_OUTPUT| ${BB_BINARY} egrep -v "Currently defined functions|^$$" | ${BB_BINARY} sed -e 's/[ \t]//g' | ${BB_BINARY} sed -e :a -e '$!N; s/\n//; ta' | ${BB_BINARY} sed -e 's/,/\n/g'| \
while read busyboxapplet; do
if [ $(${BB_BINARY} find $BIG_GNUVERSION_LOCATION -name ${busyboxapplet} -perm -550 ! -type d 2>/dev/null |${BB_BINARY} wc -l) -eq 0 ]; then
${BB_BINARY} ln -s $BB_BINARY $TARGET_LINKDIR/$busyboxapplet > /dev/null 2>&1 && ${BB_BINARY} echo "${busyboxapplet}" >> $TMPDIR/BB_LINK_CREATED || ${BB_BINARY} echo "${busyboxapplet}" >> $TMPDIR/BB_LINK_FAILED
else
SUMMARY_GNUFOUND="${SUMMARY_GNUFOUND} "
${BB_BINARY} echo "${busyboxapplet}" >> $TMPDIR/BB_GNU_FOUND
if [ -L $TARGET_LINKDIR/$busyboxapplet ]
then
if [ "$(${BB_BINARY} readlink ${TARGET_LINKDIR}/${busyboxapplet})" = "${BB_BINARY}" ]
then
${BB_BINARY} rm $TARGET_LINKDIR/$busyboxapplet && ${BB_BINARY} echo "Removed link $TARGET_LINKDIR/$busyboxapplet because the big GNU version was found."
else
${BB_BINARY} echo "Another link ${TARGET_LINKDIR}/${busyboxapplet} was found, not pointing to ${BB_BINARY} ."
fi
fi
fi;
done
${BB_BINARY} rm $TMPDIR/BB_OUTPUT
}
case "$1" in
--help|-h|-?|/h|/?)
usage
exit 0
;;
esac
checks || exit 1
createlinks || exit 1
SUMMARY_GNUFOUND=$(${BB_BINARY} cat $TMPDIR/BB_GNU_FOUND| ${BB_BINARY} tr '\n' ',')
SUMMARY_CREATED=$(${BB_BINARY} cat $TMPDIR/BB_LINK_CREATED| ${BB_BINARY} tr '\n' ',')
SUMMARY_FAILED=$(${BB_BINARY} cat $TMPDIR/BB_LINK_FAILED| ${BB_BINARY} tr '\n' ',')
${BB_BINARY} rm $TMPDIR/BB_LINK_CREATED
${BB_BINARY} rm $TMPDIR/BB_GNU_FOUND
${BB_BINARY} rm $TMPDIR/BB_LINK_FAILED
if [ $(${BB_BINARY} length "${SUMMARY_GNUFOUND}") -gt 1 ]
then
${BB_BINARY} echo -e "\nThe following big GNU versions have been found : "
${BB_BINARY} echo "$SUMMARY_GNUFOUND"
fi
if [ $(${BB_BINARY} length "${SUMMARY_CREATED}") -gt 1 ]
then
${BB_BINARY} echo -e "\nThe following links have been created : "
${BB_BINARY} echo "$SUMMARY_CREATED"
fi
if [ $(${BB_BINARY} length "${SUMMARY_FAILED}") -gt 1 ]
then
${BB_BINARY} echo -e "\nThe following links could not be created (maybe they existed before) : "
${BB_BINARY} echo "$SUMMARY_FAILED"
fi
#EOF
Reply to: