2 # A script to replace /bin/busybox and create missing symlinks to its applets.
4 # The target directories for BusyBox' applets are defined in the "applets" file.
5 # This script will only create symbolic links when 1) they do not already exist
6 # in the filesystem, and 2) the BusyBox binary supports the applet. A list of
7 # all made symbolic links is written out to the file "busybox-power.symlinks",
8 # which will be used during uninstallation of busybox-power.
10 # NB The BusyBox binary needs to support the install applet.
12 # By Dennis Groenen <tj.groenen@gmail.com>
16 INSTALLDIR="/opt/busybox-power"
17 EXECPWR="$INSTALLDIR/busybox.power"
18 DISTBIN="/bin/busybox.distrib"
21 INSTBINARY_SHA1=`$EXECPWR sha1sum $EXECPWR | $EXECPWR awk '{ print $1 }'`
22 ORIGBINARY_SHA1=`$EXECPWR sha1sum /bin/busybox | $EXECPWR awk '{ print $1 }'`
24 # Load shared functions
25 source $INSTALLDIR/functions
27 # Check whether the applets file exists
29 if test ! -e $INSTALLDIR/applets; then
30 echo "error: cannot find list of defined applets"
35 # Check whether symlinks have been made before
36 CHECK_SYMLINKSFILE() {
37 if test -e $INSTALLDIR/busybox-power.symlinks; then
38 echo "error: symlinks already seem to be made?"
39 echo " this script is not supposed to be ran twice"
44 # Backup the original BusyBox binary
46 if test ! -e /bin/busybox; then
47 # Scratchbox does not ship with BusyBox by default
51 if ! test "$INSTBINARY_SHA1" == "$ORIGBINARY_SHA1"; then
52 $EXECPWR cp -a /bin/busybox $DISTBIN
53 $EXECPWR sha1sum $DISTBIN | $EXECPWR awk '{ print $1 }' \
54 > $INSTALLDIR/busybox.distrib.sha1
58 # Overwrite the installed binary with the enhanced binary
60 /usr/sbin/dpkg-divert --local --divert $DISTBIN /bin/busybox
61 $EXECPWR cp -f $EXECPWR /bin/busybox
64 # Create missing symlinks to the enhanced binary
66 # Load defined BusyBox applets
67 source $INSTALLDIR/applets
69 # Get a list of supported applets by busybox-power
70 if test -d /tmp/busybox-power; then
71 $EXECPWR rm -Rf /tmp/busybox-power; fi
72 $EXECPWR mkdir -p /tmp/busybox-power
73 $EXECPWR --install -s /tmp/busybox-power
74 $EXECPWR ls /tmp/busybox-power/ > $INSTALLDIR/applets_supported
75 $EXECPWR rm -Rf /tmp/busybox-power
77 # Prepare file that will keep track of installed symlinks by busybox-power
78 echo "# Automatically generated by busybox-power. DO NOT EDIT" > $INSTALLDIR/busybox-power.symlinks
79 echo -e "\nDESTINATIONS=\"$DESTINATIONS\"" >> $INSTALLDIR/busybox-power.symlinks
80 echo -e "\n# Installed symlinks" >> $INSTALLDIR/busybox-power.symlinks
82 # Walk through all possible destinations
83 for DESTDIR in $DESTINATIONS; do
84 # Enable us to see all entries in $DESTINATION as variables
85 eval "APPLICATIONS=\$$DESTDIR"
87 # Set destination directory accordingly
103 # Keep track of installed symlinks per destination
104 SYMLINKS="$DESTDIR=\""
106 ECHO_VERBOSE "\nSymlinking applets in $DIR"
107 # Walk through all applications from the current destination
108 for APP in $APPLICATIONS; do
109 # The following code is executed for all applets in the current destination
110 if test ! -e $DIR/$APP; then
111 # Check whether the applet is supported by the busybox binary
112 if `$EXECPWR grep -Fq "$APP" $INSTALLDIR/applets_supported`; then
113 ECHO_VERBOSE "Symlinking: /bin/busybox -> $DIR/$APP"
114 $EXECPWR ln -s /bin/busybox $DIR/$APP
115 SYMLINKS="$SYMLINKS $APP"
120 # Write out installed symlinks
121 echo "$SYMLINKS\"" >> $INSTALLDIR/busybox-power.symlinks
124 $EXECPWR rm $INSTALLDIR/applets_supported
128 ECHO_VERBOSE "busybox-power: verbose mode"
129 ECHO_VERBOSE " binary: $EXECPWR"
130 ECHO_VERBOSE " version string: `$EXECPWR | $EXECPWR head -n 1`"
131 CHECK_ENV && ECHO_VERBOSE " environment: $ENVIRONMENT"
136 if test "$ENVIRONMENT" != "SDK"; then