2 # A script to replace /bin/busybox and creates symlinks to new functions.
3 # The default locations of busybox' functions (applets) are defined in the file $INSTALLDIR/functions
4 # It keeps track of the installed symlinks by writing them to $INSTALLDIR/installed-symlinks in
5 # a similiar fashion as locations are defined in the "functions" file.
7 # The scripts check whether symlinks/binaries of the utilities already exist, and if not,
8 # it checks whether the new busybox binary supports it. If so, it creates a symlink to /bin/busybox.
10 # NB The busybox binary needs to support the install applet
12 # By Dennis Groenen <dennis_groenen@hotmail.com>
15 # Version 0.3 07-03-2011 (MM-DD-YYYY)
16 # 0.1: Initial release
17 # 0.2: Use $EXECPWR to not have to rely on /bin/busybox' functions
18 # Minor clean-ups and be quieter
19 # 0.3: Add support for multiple environments
20 # Make use of functions in this script
21 # Implement additional checks
23 INSTALLDIR="/opt/busybox-power"
24 EXECPWR="$INSTALLDIR/busybox.power"
27 # Print extra information in verbose mode
28 if test $VERBOSE == 1; then
29 echo "busybox-power: verbose mode" \
30 echo " binary: $EXECPWR" \
31 echo " version string: `$EXECPWR | $EXECPWR head -n 1`"
36 if test -d /scratchbox
40 PROD=$($EXECPWR cat /proc/component_version | $EXECPWR grep product | $EXECPWR cut -d" " -f 6)
46 # Unsupported, use the least strict environment (SDK)
52 if test $VERBOSE == 1; then echo " environment: $ENVIRONMENT"; fi
55 # Environment-independent checks before continuing
57 #if test -n "`pgrep dpkg`" -o "`pgrep apt`"
58 if ! lsof /var/lib/dpkg/lock >> /dev/null; then
59 echo "error: you're running me as a stand-alone application"
60 echo " do not do this, I will be called automatically upon"
61 echo " installation of busybox-power"
65 if test ! -e $INSTALLDIR/functions; then
66 echo "error: cannot find list of defined functions"
70 if test -e $INSTALLDIR/busybox-power.symlinks; then
71 echo "error: symlinks already seem to be made?"
72 echo " this script is not supposed to be ran twice"
77 # Additional checks for the N900
79 if test "`$EXECPWR id -u`" -ne 0; then
80 echo "error: you're not running me as root, aborting"
81 echo " also, DO NOT run me as a stand-alone application"
82 echo " I will be called automatically upon installation"
83 echo " of busybox-power"
88 # N900-specific code executed prior to installing the enhanced binary
90 md5sum $INSTALLDIR/busybox.power | $EXECPWR awk '{ print $1 }' > $INSTALLDIR/busybox.power.md5
91 md5sum /bin/busybox | $EXECPWR awk '{ print $1 }' > $INSTALLDIR/busybox.original.md5
93 # Check whether busybox-power isn't installed already
94 INSTBINARY_MD5=`$EXECPWR cat $INSTALLDIR/busybox.power.md5`
95 ORIGBINARY_MD5=`$EXECPWR cat $INSTALLDIR/busybox.original.md5`
96 if test "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"
98 echo "warning: installed busybox binary matches the binary"
99 echo " that is to be installed"
100 if ! test -e $INSTALLDIR/busybox.original; then
101 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original; fi
103 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original
107 # SDK-specific code executed prior to installing the enhanced binary
109 if test -e /bin/busybox
111 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original
115 # Overwrite old busybox binary with bbpower's one
117 $EXECPWR cp -f $INSTALLDIR/busybox.power /bin/busybox
120 # Creates missing symlinks to busybox' binary
122 # Load defined BusyBox functions
123 source $INSTALLDIR/functions
125 # Get a list of supported functions by the new binary
126 if test -d /tmp/busybox-power; then $EXECPWR rm -Rf /tmp/busybox-power; fi
127 $EXECPWR mkdir -p /tmp/busybox-power
128 $INSTALLDIR/busybox.power --install -s /tmp/busybox-power
129 $EXECPWR ls /tmp/busybox-power/ > $INSTALLDIR/functions_supported
130 $EXECPWR rm -Rf /tmp/busybox-power
132 # Prepare file which keeps track of installed symlinks by busybox-power
133 echo "# Automatically generated by busybox-power. DO NOT EDIT" > $INSTALLDIR/busybox-power.symlinks
134 echo -e "\nDESTINATIONS=\"$DESTINATIONS\"" >> $INSTALLDIR/busybox-power.symlinks
135 echo -e "\n# Installed symlinks" >> $INSTALLDIR/busybox-power.symlinks
137 # Walk through all possible destinations
138 for DESTDIR in $DESTINATIONS
140 # Enable us to see all entries in $DESTINATION as variables
141 eval "APPLICATIONS=\$$DESTDIR"
143 # Set destination directory accordingly
159 # Keep track of installed symlinks per destination
160 SYMLINKS="$DESTDIR=\""
162 if test $VERBOSE == 1; then echo -e "\nSymlinking functions in $DIR"; fi
163 # Walk through all applications from the current destination
164 for APP in $APPLICATIONS
166 # The following code is executed for every application in the current destination
167 if test ! -e $DIR/$APP
169 # Check whether the function is supported by the busybox binary
170 if `$EXECPWR grep -Fq "$APP" $INSTALLDIR/functions_supported`
172 if test $VERBOSE == 1; then echo Symlinking: $DIR/$APP; fi
173 $EXECPWR ln -s /bin/busybox $DIR/$APP
174 SYMLINKS="$SYMLINKS $APP"
179 # Write out installed symlinks
180 echo "$SYMLINKS\"" >> $INSTALLDIR/busybox-power.symlinks
183 $EXECPWR rm $INSTALLDIR/functions_supported