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"
20 INSTBINARY_SHA1=`$EXECPWR sha1sum $EXECPWR | $EXECPWR awk '{ print $1 }'`
21 ORIGBINARY_SHA1=`$EXECPWR sha1sum /bin/busybox | $EXECPWR awk '{ print $1 }'`
23 # Load shared functions
24 source $INSTALLDIR/functions
26 # Check whether the applets file exists
28 if test ! -e $INSTALLDIR/applets; then
29 echo "error: cannot find list of defined applets"
34 # Check whether symlinks have been made before
35 CHECK_SYMLINKSFILE() {
36 if test -e $INSTALLDIR/busybox-power.symlinks; then
37 echo "error: symlinks already seem to be made?"
38 echo " this script is not supposed to be ran twice"
43 # Backup the original BusyBox binary
45 if test ! -e /bin/busybox; then
46 # Scratchbox does not ship with BusyBox by default
50 if ! test "$INSTBINARY_SHA1" == "$ORIGBINARY_SHA1"; then
51 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original
52 $EXECPWR sha1sum $INSTALLDIR/busybox.original | $EXECPWR awk '{ print $1 }' \
53 > $INSTALLDIR/busybox.original.sha1
57 # Overwrite the installed binary with the enhanced binary
59 /usr/sbin/dpkg-divert --local --divert /bin/busybox.distrib /bin/busybox
60 $EXECPWR cp -f $EXECPWR /bin/busybox
63 # Create missing symlinks to the enhanced binary
65 # Load defined BusyBox applets
66 source $INSTALLDIR/applets
68 # Get a list of supported applets by busybox-power
69 if test -d /tmp/busybox-power; then
70 $EXECPWR rm -Rf /tmp/busybox-power; fi
71 $EXECPWR mkdir -p /tmp/busybox-power
72 $EXECPWR --install -s /tmp/busybox-power
73 $EXECPWR ls /tmp/busybox-power/ > $INSTALLDIR/applets_supported
74 $EXECPWR rm -Rf /tmp/busybox-power
76 # Prepare file that will keep track of installed symlinks by busybox-power
77 echo "# Automatically generated by busybox-power. DO NOT EDIT" > $INSTALLDIR/busybox-power.symlinks
78 echo -e "\nDESTINATIONS=\"$DESTINATIONS\"" >> $INSTALLDIR/busybox-power.symlinks
79 echo -e "\n# Installed symlinks" >> $INSTALLDIR/busybox-power.symlinks
81 # Walk through all possible destinations
82 for DESTDIR in $DESTINATIONS; do
83 # Enable us to see all entries in $DESTINATION as variables
84 eval "APPLICATIONS=\$$DESTDIR"
86 # Set destination directory accordingly
102 # Keep track of installed symlinks per destination
103 SYMLINKS="$DESTDIR=\""
105 ECHO_VERBOSE "\nSymlinking applets in $DIR"
106 # Walk through all applications from the current destination
107 for APP in $APPLICATIONS; do
108 # The following code is executed for all applets in the current destination
109 if test ! -e $DIR/$APP; then
110 # Check whether the applet is supported by the busybox binary
111 if `$EXECPWR grep -Fq "$APP" $INSTALLDIR/applets_supported`; then
112 ECHO_VERBOSE "Symlinking: /bin/busybox -> $DIR/$APP"
113 $EXECPWR ln -s /bin/busybox $DIR/$APP
114 SYMLINKS="$SYMLINKS $APP"
119 # Write out installed symlinks
120 echo "$SYMLINKS\"" >> $INSTALLDIR/busybox-power.symlinks
123 $EXECPWR rm $INSTALLDIR/applets_supported
127 ECHO_VERBOSE "busybox-power: verbose mode"
128 ECHO_VERBOSE " binary: $EXECPWR"
129 ECHO_VERBOSE " version string: `$EXECPWR | $EXECPWR head -n 1`"
130 CHECK_ENV && ECHO_VERBOSE " environment: $ENVIRONMENT"
135 if test "$ENVIRONMENT" != "SDK"; then