2 # A script to restore /bin/busybox and delete created symlinks as defined in $INSTALLDIR/installed-symlinks
4 # Symbolic links are only removed if they are
5 # a) created by the installer script ("install-binary.sh")
6 # b) not replaced by a binary (i.e. they are still a symbolic link)
7 # c) pointing to a busybox binary
9 # By Dennis Groenen <tj.groenen@gmail.com>
12 # Version 0.4 08-02-2011 (MM-DD-YYYY)
13 # 0.1: Initial release
14 # 0.2: Minor clean-ups and be quieter
15 # 0.3: Add support for multiple environments
16 # Make use of functions in this script
17 # Implement additional checks
18 # 0.4: Add support for undoing symlinks to busybox_root
19 # Update email address
21 INSTALLDIR="/opt/busybox-power"
22 EXECPWR="$INSTALLDIR/busybox.power"
25 # Print extra information in verbose mode
26 if test $VERBOSE == 1; then
27 echo "busybox-power: verbose mode" \
28 echo " binary: $EXECPWR" \
29 echo " version string: `$EXECPWR | $EXECPWR head -n 1`"
34 if test -d /scratchbox
38 PROD=$(cat /proc/component_version | grep product | cut -d" " -f 6)
44 # Unsupported, use the least strict environment (SDK)
50 if test $VERBOSE == 1; then echo " environment: $ENVIRONMENT"; fi
53 # Environment-independent checks before continuing
55 #if test -n "`pgrep dpkg`" -o "`pgrep apt`"
56 if ! lsof /var/lib/dpkg/lock >> /dev/null; then
57 echo "error: you're running me as a stand-alone application"
58 echo " do not do this, I will be called automatically upon"
59 echo " deinstallation of busybox-power"
63 if test ! -e $INSTALLDIR/busybox-power.symlinks; then
64 echo -e "Error: cannot find the list of symlinks to be removed. No symlinks will be removed at all!\n" >> /tmp/busybox-power-error
68 # Additional checks for the N900
70 if test "`id -u`" -ne 0; then
71 echo "error: you're not running me as root, aborting"
72 echo " also, DO NOT run me as a stand-alone application"
73 echo " I will be called automatically upon deinstallation"
74 echo " of busybox-power"
78 if test ! -e $INSTALLDIR/busybox.original; then
79 echo -e "Error: original binary is missing! Continuing will only remove the symlinks made during installation, /bin/busybox stays untouched.\n" >> /tmp/busybox-power-error
83 # N900-specific code executed prior to uninstalling the enhanced binary
85 if test -e $INSTALLDIR/busybox.power.md5
87 INSTBINARY_MD5=`md5sum /bin/busybox | awk '{ print $1 }'`
88 ORIGBINARY_MD5=`cat $INSTALLDIR/busybox.power.md5`
89 if test ! "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"; then
90 echo -e "Warning: /bin/busybox has been modified since installing busybox-power (invalid md5 checksum). The original BusyBox binary at the time of installation will replace it if you continue.\n" >> /tmp/busybox-power-error
94 if test -e $INSTALLDIR/busybox.original.md5
96 INSTBINARY_MD5=`cat $INSTALLDIR/busybox.original.md5`
97 ORIGBINARY_MD5=`md5sum $INSTALLDIR/busybox.original | awk '{ print $1 }'`
98 if test ! "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"; then
99 echo -e "Warning: the backed-up original binary has been modified since installing busybox-power (invalid md5 checksum). Do not continue unless you're sure $INSTALLDIR/busybox.original isn't corrupted.\n" >> /tmp/busybox-power-error
102 echo -e "Warning: couldn't load the saved md5 checksum of the original binary; the integrity of the backup of the original binary can not be guaranteed.\n" >> /tmp/busybox-power-error
106 # Display encountered errors
110 echo -e "\n\n-----------Attention!-----------"
111 cat /tmp/busybox-power-error
112 rm /tmp/busybox-power-error
113 echo "-> Please press [enter] to ignore the above errors/warnings. Hit [ctrl-c] to break"
117 echo "Click \"I Agree\" to ignore the above errors/warnings. Ask for help if you don't know what to do." >> /tmp/busybox-power-error
118 maemo-confirm-text "Attention!" /tmp/busybox-power-error
120 rm /tmp/busybox-power-error
121 if test ! $res == 0; then exit 1; fi
125 touch $INSTALLDIR/busybox-power.symlinks
128 # Uninstallation of the enhanced binary on the N900
130 if test -e $INSTALLDIR/busybox.original
132 cp -f $INSTALLDIR/busybox.original /bin/busybox
133 if test -e /bin/busybox; then rm $INSTALLDIR/busybox.original; fi
137 # Uninstallation of the enhanced binary in Maemo's SDK
139 if test -e $INSTALLDIR/busybox.original
141 cp -f $INSTALLDIR/busybox.original /bin/busybox
142 if test -e /bin/busybox; then rm $INSTALLDIR/busybox.original; fi
148 # Remove all symlinks that busybox-power has made
150 # Load list of installed symlinks
151 source $INSTALLDIR/busybox-power.symlinks
153 # Walk through all possible destinations
154 for DESTDIR in $DESTINATIONS
156 # Enable us to see all entries in $DESTIONATION as variables
157 eval "APPLICATIONS=\$$DESTDIR"
158 # Set destination dirrectory accordingly
174 # Determine whether we've symlinked to busybox or busybox_root
175 if test `echo $DESTDIR | cut -c1-1` == "S"
176 then SUID=1; else SUID=0; fi
178 if test $VERBOSE == 1; then echo -e "\nRemoving symlinks in $DIR (SUID=$SUID)"; fi
179 # Walk through all applications from the current destination
180 for APP in $APPLICATIONS
182 # The following code is executed for every application in the current destination
183 if test -h $DIR/$APP # Check if the app is a symbolic link
185 if test -n "`ls -l $DIR/$APP | grep busybox`" # Check if the symbolic link points to busybox
189 if test $VERBOSE == 1; then echo "Removing link: $DIR/$APP"; fi
192 if test -n "`echo $RESYM | grep $APP`"
194 if test $VERBOSE == 1; then echo "Restoring link: /bin/busybox -> $DIR/$APP"; fi
196 ln -s /bin/busybox $DIR/$APP
198 if test $VERBOSE == 1; then echo "Removing link: $DIR/$APP"; fi
208 # Action to be performed after restoring original busybox
210 OLDFILES="busybox-power.symlinks
212 busybox.original.md5"
214 for file in $OLDFILES
216 if test -e $INSTALLDIR/$file; then
227 # Check for errors before restoring BusyBox
228 if test -e /tmp/busybox-power-error
229 then DISPLAY_ERRORS; fi
235 # Check for errors before restoring BusyBox
236 if test -e /tmp/busybox-power-error
237 then DISPLAY_ERRORS; fi