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(_root) binary supports it. If so, it creates a symlink to /bin/busybox(_root).
10 # NB The busybox binary needs to support the install applet
12 # By Dennis Groenen <tj.groenen@gmail.com>
15 # Version 0.41 09-10-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
22 # 0.4: Add support for symlinking against busybox_root
23 # Update email address
24 # 0.41: Minor fix in SYMLINK(), SUID symlinking part
26 INSTALLDIR="/opt/busybox-power"
27 EXECPWR="$INSTALLDIR/busybox.power"
28 BUSYBOXROOT="/bin/busybox_root"
31 # Print extra information in verbose mode
32 if test $VERBOSE == 1; then
33 echo "busybox-power: verbose mode" \
34 echo " binary: $EXECPWR" \
35 echo " version string: `$EXECPWR | $EXECPWR head -n 1`"
40 if test -d /scratchbox
44 PROD=$($EXECPWR cat /proc/component_version | $EXECPWR grep product | $EXECPWR cut -d" " -f 6)
50 # Unsupported, use the least strict environment (SDK)
56 if test $VERBOSE == 1; then echo " environment: $ENVIRONMENT"; fi
59 # Environment-independent checks before continuing
61 #if test -n "`pgrep dpkg`" -o "`pgrep apt`"
62 if ! lsof /var/lib/dpkg/lock >> /dev/null; then
63 echo "error: you're running me as a stand-alone application"
64 echo " do not do this, I will be called automatically upon"
65 echo " installation of busybox-power"
69 if test ! -e $INSTALLDIR/functions; then
70 echo "error: cannot find list of defined functions"
74 if test -e $INSTALLDIR/busybox-power.symlinks; then
75 echo "error: symlinks already seem to be made?"
76 echo " this script is not supposed to be ran twice"
81 # Additional checks for the N900
83 if test "`$EXECPWR id -u`" -ne 0; then
84 echo "error: you're not running me as root, aborting"
85 echo " also, DO NOT run me as a stand-alone application"
86 echo " I will be called automatically upon installation"
87 echo " of busybox-power"
92 # N900-specific code executed prior to installing the enhanced binary
94 md5sum $INSTALLDIR/busybox.power | $EXECPWR awk '{ print $1 }' > $INSTALLDIR/busybox.power.md5
95 md5sum /bin/busybox | $EXECPWR awk '{ print $1 }' > $INSTALLDIR/busybox.original.md5
97 # Check whether busybox-power isn't installed already
98 INSTBINARY_MD5=`$EXECPWR cat $INSTALLDIR/busybox.power.md5`
99 ORIGBINARY_MD5=`$EXECPWR cat $INSTALLDIR/busybox.original.md5`
100 if test "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"
102 echo "warning: installed busybox binary matches the binary"
103 echo " that is to be installed"
104 if ! test -e $INSTALLDIR/busybox.original; then
105 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original; fi
107 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original
111 # SDK-specific code executed prior to installing the enhanced binary
113 if test -e /bin/busybox
115 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original
119 # Overwrite old busybox binary with bbpower's one
121 $EXECPWR cp -f $INSTALLDIR/busybox.power /bin/busybox
124 # Creates missing symlinks to busybox' binary
126 # Load defined BusyBox functions
127 source $INSTALLDIR/functions
129 # Get a list of supported functions by busybox-power (including busybox_root)
130 if test -d /tmp/busybox-power; then $EXECPWR rm -Rf /tmp/busybox-power; fi
131 $EXECPWR mkdir -p /tmp/busybox-power
132 $INSTALLDIR/busybox.power --install -s /tmp/busybox-power
133 $BUSYBOXROOT --install -s /tmp/busybox-power
134 $EXECPWR ls /tmp/busybox-power/ > $INSTALLDIR/functions_supported
135 $EXECPWR rm -Rf /tmp/busybox-power
137 # Prepare file which keeps track of installed symlinks by busybox-power
138 echo "# Automatically generated by busybox-power. DO NOT EDIT" > $INSTALLDIR/busybox-power.symlinks
139 echo -e "\nDESTINATIONS=\"$DESTINATIONS\"" >> $INSTALLDIR/busybox-power.symlinks
140 echo -e "\n# Installed symlinks" >> $INSTALLDIR/busybox-power.symlinks
143 # Walk through all possible destinations
144 for DESTDIR in $DESTINATIONS
146 # Enable us to see all entries in $DESTINATION as variables
147 eval "APPLICATIONS=\$$DESTDIR"
149 # Set destination directory accordingly
165 # Determine whether we have to symlink to busybox or busybox_root
166 if test `echo $DESTDIR | $EXECPWR cut -c1-1` == "S"
167 then SUID=1; else SUID=0; fi
169 # Keep track of installed symlinks per destination
170 SYMLINKS="$DESTDIR=\""
172 if test $VERBOSE == 1; then echo -e "\nSymlinking functions in $DIR (SUID=$SUID)"; fi
173 # Walk through all applications from the current destination
174 for APP in $APPLICATIONS
176 # The following code is executed for every application in the current destination
177 if test ! -e $DIR/$APP
179 # Check whether the function is supported by the busybox binary
180 if `$EXECPWR grep -Fq "$APP" $INSTALLDIR/functions_supported`
184 if test $VERBOSE == 1; then echo "Symlinking: /bin/busybox -> $DIR/$APP"; fi
185 $EXECPWR ln -s /bin/busybox $DIR/$APP
187 if test $VERBOSE == 1; then echo "Symlinking: $BUSYBOXROOT -> $DIR/$APP"; fi
188 $EXECPWR ln -s $BUSYBOXROOT $DIR/$APP
190 SYMLINKS="$SYMLINKS $APP"
193 if test $SUID == 1; then
194 if test -h $DIR/$APP # Check if the app is a symbolic link
196 if test -n "`$EXECPWR ls -l $DIR/$APP | $EXECPWR grep busybox`" # Check if the symbolic link points to busybox
198 if test $VERBOSE == 1; then echo "Re-symlinking: $BUSYBOXROOT -> $DIR/$APP"; fi
199 $EXECPWR rm $DIR/$APP
200 $EXECPWR ln -s $BUSYBOXROOT $DIR/$APP
201 SYMLINKS="$SYMLINKS $APP"
209 # Write out installed symlinks
210 echo "$SYMLINKS\"" >> $INSTALLDIR/busybox-power.symlinks
213 echo "$RESYM\"" >> $INSTALLDIR/busybox-power.symlinks
214 $EXECPWR rm $INSTALLDIR/functions_supported