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>
15 # Last updated: 03-11-2012 (MM-DD-YYYY)
18 INSTALLDIR="/opt/busybox-power"
19 EXECPWR="$INSTALLDIR/busybox.power"
23 if test $VERBOSE == 1; then
29 if test -d /scratchbox; then
32 PROD=$($EXECPWR cat /proc/component_version | $EXECPWR grep product | $EXECPWR cut -d" " -f 6)
38 # Unsupported, use the least strict environment (SDK)
45 # Environment-independent checks before continuing
47 #if test -n "`pgrep dpkg`" -o "`pgrep apt`"
48 if ! lsof /var/lib/dpkg/lock >> /dev/null; then
49 echo "error: you're running me as a stand-alone application"
50 echo " do not do this, I will be called automatically upon"
51 echo " installation of busybox-power"
55 if test ! -e $INSTALLDIR/applets; then
56 echo "error: cannot find list of defined applets"
60 if test -e $INSTALLDIR/busybox-power.symlinks; then
61 echo "error: symlinks already seem to be made?"
62 echo " this script is not supposed to be ran twice"
67 # Additional checks for the N900
69 if test "`$EXECPWR id -u`" -ne 0; then
70 echo "error: you're not running me as root, aborting"
71 echo " also, DO NOT run me as a stand-alone application"
72 echo " I will be called automatically upon installation"
73 echo " of busybox-power"
78 # N900-specific code executed prior to installing the enhanced binary
80 $EXECPWR md5sum $INSTALLDIR/busybox.power | $EXECPWR awk '{ print $1 }' \
81 > $INSTALLDIR/busybox.power.md5
82 $EXECPWR md5sum /bin/busybox | $EXECPWR awk '{ print $1 }' \
83 > $INSTALLDIR/busybox.original.md5
85 # Check whether busybox-power isn't installed already
86 INSTBINARY_MD5=`$EXECPWR cat $INSTALLDIR/busybox.power.md5`
87 ORIGBINARY_MD5=`$EXECPWR cat $INSTALLDIR/busybox.original.md5`
88 if test "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"; then
89 echo "warning: installed busybox binary matches the binary"
90 echo " that is to be installed"
91 if ! test -e $INSTALLDIR/busybox.original; then
92 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original; fi
94 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original
98 # SDK-specific code executed prior to installing the enhanced binary
100 if test -e /bin/busybox; then
101 $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original; fi
104 # Overwrite the installed binary with the enhanced binary
106 $EXECPWR cp -f $INSTALLDIR/busybox.power /bin/busybox
109 # Creates missing symlinks to the enhanced binary
111 # Load defined BusyBox applets
112 source $INSTALLDIR/applets
114 # Get a list of supported applets by busybox-power
115 if test -d /tmp/busybox-power; then
116 $EXECPWR rm -Rf /tmp/busybox-power; fi
117 $EXECPWR mkdir -p /tmp/busybox-power
118 $EXECPWR --install -s /tmp/busybox-power
119 $EXECPWR ls /tmp/busybox-power/ > $INSTALLDIR/applets_supported
120 $EXECPWR rm -Rf /tmp/busybox-power
122 # Prepare file that will keep track of installed symlinks by busybox-power
123 echo "# Automatically generated by busybox-power. DO NOT EDIT" > $INSTALLDIR/busybox-power.symlinks
124 echo -e "\nDESTINATIONS=\"$DESTINATIONS\"" >> $INSTALLDIR/busybox-power.symlinks
125 echo -e "\n# Installed symlinks" >> $INSTALLDIR/busybox-power.symlinks
127 # Walk through all possible destinations
128 for DESTDIR in $DESTINATIONS; do
129 # Enable us to see all entries in $DESTINATION as variables
130 eval "APPLICATIONS=\$$DESTDIR"
132 # Set destination directory accordingly
148 # Keep track of installed symlinks per destination
149 SYMLINKS="$DESTDIR=\""
151 ECHO_VERBOSE "\nSymlinking applets in $DIR"
152 # Walk through all applications from the current destination
153 for APP in $APPLICATIONS; do
154 # The following code is executed for all applets in the current destination
155 if test ! -e $DIR/$APP; then
156 # Check whether the applet is supported by the busybox binary
157 if `$EXECPWR grep -Fq "$APP" $INSTALLDIR/applets_supported`; then
158 ECHO_VERBOSE "Symlinking: /bin/busybox -> $DIR/$APP"
159 $EXECPWR ln -s /bin/busybox $DIR/$APP
160 SYMLINKS="$SYMLINKS $APP"
165 # Write out installed symlinks
166 echo "$SYMLINKS\"" >> $INSTALLDIR/busybox-power.symlinks
169 $EXECPWR rm $INSTALLDIR/applets_supported
173 ECHO_VERBOSE "busybox-power: verbose mode"
174 ECHO_VERBOSE " binary: $EXECPWR"
175 ECHO_VERBOSE " version string: `$EXECPWR | $EXECPWR head -n 1`"
176 CHECK_ENV && ECHO_VERBOSE " environment: $ENVIRONMENT"