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 # Load shared functions
21 source $INSTALLDIR/functions
23 # Check whether the applets file exists
25 if test ! -e $INSTALLDIR/applets; then
26 echo "error: cannot find list of defined applets"
31 # Check whether symlinks have been made before
32 CHECK_SYMLINKSFILE() {
33 if test -e $INSTALLDIR/busybox-power.symlinks; then
34 echo "error: symlinks already seem to be made?"
35 echo " this script is not supposed to be ran twice"
40 # Create MD5 hashes of relevant binaries
42 $EXECPWR md5sum $INSTALLDIR/busybox.power | $EXECPWR awk '{ print $1 }' \
43 > $INSTALLDIR/busybox.power.md5
44 $EXECPWR md5sum /bin/busybox | $EXECPWR awk '{ print $1 }' \
45 > $INSTALLDIR/busybox.original.md5
48 # Backup the original BusyBox binary
52 # Scratchbox does not ship with BusyBox by default
53 if test -e /bin/busybox; then
54 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original; fi
57 # Check whether busybox-power isn't somehow installed already
58 INSTBINARY_MD5=`$EXECPWR cat $INSTALLDIR/busybox.power.md5`
59 ORIGBINARY_MD5=`$EXECPWR cat $INSTALLDIR/busybox.original.md5`
60 if test "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"; then
61 echo "warning: installed busybox binary matches the binary"
62 echo " that is to be installed"
63 if ! test -e $INSTALLDIR/busybox.original; then
64 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original; fi
66 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original
72 # Overwrite the installed binary with the enhanced binary
74 $EXECPWR cp -f $INSTALLDIR/busybox.power /bin/busybox
77 # Create missing symlinks to the enhanced binary
79 # Load defined BusyBox applets
80 source $INSTALLDIR/applets
82 # Get a list of supported applets by busybox-power
83 if test -d /tmp/busybox-power; then
84 $EXECPWR rm -Rf /tmp/busybox-power; fi
85 $EXECPWR mkdir -p /tmp/busybox-power
86 $EXECPWR --install -s /tmp/busybox-power
87 $EXECPWR ls /tmp/busybox-power/ > $INSTALLDIR/applets_supported
88 $EXECPWR rm -Rf /tmp/busybox-power
90 # Prepare file that will keep track of installed symlinks by busybox-power
91 echo "# Automatically generated by busybox-power. DO NOT EDIT" > $INSTALLDIR/busybox-power.symlinks
92 echo -e "\nDESTINATIONS=\"$DESTINATIONS\"" >> $INSTALLDIR/busybox-power.symlinks
93 echo -e "\n# Installed symlinks" >> $INSTALLDIR/busybox-power.symlinks
95 # Walk through all possible destinations
96 for DESTDIR in $DESTINATIONS; do
97 # Enable us to see all entries in $DESTINATION as variables
98 eval "APPLICATIONS=\$$DESTDIR"
100 # Set destination directory accordingly
116 # Keep track of installed symlinks per destination
117 SYMLINKS="$DESTDIR=\""
119 ECHO_VERBOSE "\nSymlinking applets in $DIR"
120 # Walk through all applications from the current destination
121 for APP in $APPLICATIONS; do
122 # The following code is executed for all applets in the current destination
123 if test ! -e $DIR/$APP; then
124 # Check whether the applet is supported by the busybox binary
125 if `$EXECPWR grep -Fq "$APP" $INSTALLDIR/applets_supported`; then
126 ECHO_VERBOSE "Symlinking: /bin/busybox -> $DIR/$APP"
127 $EXECPWR ln -s /bin/busybox $DIR/$APP
128 SYMLINKS="$SYMLINKS $APP"
133 # Write out installed symlinks
134 echo "$SYMLINKS\"" >> $INSTALLDIR/busybox-power.symlinks
137 $EXECPWR rm $INSTALLDIR/applets_supported
141 ECHO_VERBOSE "busybox-power: verbose mode"
142 ECHO_VERBOSE " binary: $EXECPWR"
143 ECHO_VERBOSE " version string: `$EXECPWR | $EXECPWR head -n 1`"
144 CHECK_ENV && ECHO_VERBOSE " environment: $ENVIRONMENT"
149 if test "$ENVIRONMENT" != "SDK"; then