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 <tj.groenen@gmail.com>
15 # Last updated: 11-22-2011 (MM-DD-YYYY)
18 INSTALLDIR="/opt/busybox-power"
19 EXECPWR="$INSTALLDIR/busybox.power"
22 # Print extra information in verbose mode
23 if test $VERBOSE == 1; then
24 echo "busybox-power: verbose mode" \
25 echo " binary: $EXECPWR" \
26 echo " version string: `$EXECPWR | $EXECPWR head -n 1`"
31 if test -d /scratchbox
35 PROD=$($EXECPWR cat /proc/component_version | $EXECPWR grep product | $EXECPWR cut -d" " -f 6)
41 # Unsupported, use the least strict environment (SDK)
47 if test $VERBOSE == 1; then echo " environment: $ENVIRONMENT"; fi
50 # Environment-independent checks before continuing
52 #if test -n "`pgrep dpkg`" -o "`pgrep apt`"
53 if ! lsof /var/lib/dpkg/lock >> /dev/null; then
54 echo "error: you're running me as a stand-alone application"
55 echo " do not do this, I will be called automatically upon"
56 echo " installation of busybox-power"
60 if test ! -e $INSTALLDIR/functions; then
61 echo "error: cannot find list of defined functions"
65 if test -e $INSTALLDIR/busybox-power.symlinks; then
66 echo "error: symlinks already seem to be made?"
67 echo " this script is not supposed to be ran twice"
72 # Additional checks for the N900
74 if test "`$EXECPWR id -u`" -ne 0; then
75 echo "error: you're not running me as root, aborting"
76 echo " also, DO NOT run me as a stand-alone application"
77 echo " I will be called automatically upon installation"
78 echo " of busybox-power"
83 # N900-specific code executed prior to installing the enhanced binary
85 md5sum $INSTALLDIR/busybox.power | $EXECPWR awk '{ print $1 }' > $INSTALLDIR/busybox.power.md5
86 md5sum /bin/busybox | $EXECPWR awk '{ print $1 }' > $INSTALLDIR/busybox.original.md5
88 # Check whether busybox-power isn't installed already
89 INSTBINARY_MD5=`$EXECPWR cat $INSTALLDIR/busybox.power.md5`
90 ORIGBINARY_MD5=`$EXECPWR cat $INSTALLDIR/busybox.original.md5`
91 if test "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"
93 echo "warning: installed busybox binary matches the binary"
94 echo " that is to be installed"
95 if ! test -e $INSTALLDIR/busybox.original; then
96 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original; fi
98 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original
102 # SDK-specific code executed prior to installing the enhanced binary
104 if test -e /bin/busybox
106 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original
110 # Overwrite old busybox binary with bbpower's one
112 $EXECPWR cp -f $INSTALLDIR/busybox.power /bin/busybox
115 # Creates missing symlinks to busybox' binary
117 # Load defined BusyBox functions
118 source $INSTALLDIR/functions
120 # Get a list of supported functions by busybox-power
121 if test -d /tmp/busybox-power; then $EXECPWR rm -Rf /tmp/busybox-power; fi
122 $EXECPWR mkdir -p /tmp/busybox-power
123 $INSTALLDIR/busybox.power --install -s /tmp/busybox-power
124 $EXECPWR ls /tmp/busybox-power/ > $INSTALLDIR/functions_supported
125 $EXECPWR rm -Rf /tmp/busybox-power
127 # Prepare file which keeps track of installed symlinks by busybox-power
128 echo "# Automatically generated by busybox-power. DO NOT EDIT" > $INSTALLDIR/busybox-power.symlinks
129 echo -e "\nDESTINATIONS=\"$DESTINATIONS\"" >> $INSTALLDIR/busybox-power.symlinks
130 echo -e "\n# Installed symlinks" >> $INSTALLDIR/busybox-power.symlinks
132 # Walk through all possible destinations
133 for DESTDIR in $DESTINATIONS
135 # Enable us to see all entries in $DESTINATION as variables
136 eval "APPLICATIONS=\$$DESTDIR"
138 # Set destination directory accordingly
154 # Keep track of installed symlinks per destination
155 SYMLINKS="$DESTDIR=\""
157 if test $VERBOSE == 1; then echo -e "\nSymlinking functions in $DIR"; fi
158 # Walk through all applications from the current destination
159 for APP in $APPLICATIONS
161 # The following code is executed for every application in the current destination
162 if test ! -e $DIR/$APP
164 # Check whether the function is supported by the busybox binary
165 if `$EXECPWR grep -Fq "$APP" $INSTALLDIR/functions_supported`
167 if test $VERBOSE == 1; then echo "Symlinking: /bin/busybox -> $DIR/$APP"; fi
168 $EXECPWR ln -s /bin/busybox $DIR/$APP
169 SYMLINKS="$SYMLINKS $APP"
174 # Write out installed symlinks
175 echo "$SYMLINKS\"" >> $INSTALLDIR/busybox-power.symlinks
178 $EXECPWR rm $INSTALLDIR/functions_supported