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 # Last updated: 11-22-2011 (MM-DD-YYYY)
15 INSTALLDIR="/opt/busybox-power"
16 EXECPWR="$INSTALLDIR/busybox.power"
19 # Print extra information in verbose mode
20 if test $VERBOSE == 1; then
21 echo "busybox-power: verbose mode" \
22 echo " binary: $EXECPWR" \
23 echo " version string: `$EXECPWR | $EXECPWR head -n 1`"
28 if test -d /scratchbox
32 PROD=$(cat /proc/component_version | grep product | cut -d" " -f 6)
38 # Unsupported, use the least strict environment (SDK)
44 if test $VERBOSE == 1; then echo " environment: $ENVIRONMENT"; fi
47 # Environment-independent checks before continuing
49 #if test -n "`pgrep dpkg`" -o "`pgrep apt`"
50 if ! lsof /var/lib/dpkg/lock >> /dev/null; then
51 echo "error: you're running me as a stand-alone application"
52 echo " do not do this, I will be called automatically upon"
53 echo " deinstallation of busybox-power"
57 if test ! -e $INSTALLDIR/busybox-power.symlinks; then
58 echo -e "Error: cannot find the list of symlinks to be removed. No symlinks will be removed at all!\n" >> /tmp/busybox-power-error
62 # Additional checks for the N900
64 if test "`id -u`" -ne 0; then
65 echo "error: you're not running me as root, aborting"
66 echo " also, DO NOT run me as a stand-alone application"
67 echo " I will be called automatically upon deinstallation"
68 echo " of busybox-power"
72 if test ! -e $INSTALLDIR/busybox.original; then
73 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
77 # N900-specific code executed prior to uninstalling the enhanced binary
79 if test -e $INSTALLDIR/busybox.power.md5
81 INSTBINARY_MD5=`md5sum /bin/busybox | awk '{ print $1 }'`
82 ORIGBINARY_MD5=`cat $INSTALLDIR/busybox.power.md5`
83 if test ! "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"; then
84 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
88 if test -e $INSTALLDIR/busybox.original.md5
90 INSTBINARY_MD5=`cat $INSTALLDIR/busybox.original.md5`
91 ORIGBINARY_MD5=`md5sum $INSTALLDIR/busybox.original | awk '{ print $1 }'`
92 if test ! "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"; then
93 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
96 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
100 # Display encountered errors
104 echo -e "\n\n-----------Attention!-----------"
105 cat /tmp/busybox-power-error
106 rm /tmp/busybox-power-error
107 echo "-> Please press [enter] to ignore the above errors/warnings. Hit [ctrl-c] to break"
111 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
112 maemo-confirm-text "Attention!" /tmp/busybox-power-error
114 rm /tmp/busybox-power-error
115 if test ! $res == 0; then exit 1; fi
119 touch $INSTALLDIR/busybox-power.symlinks
122 # Uninstallation of the enhanced binary on the N900
124 if test -e $INSTALLDIR/busybox.original
126 cp -f $INSTALLDIR/busybox.original /bin/busybox
127 if test -e /bin/busybox; then rm $INSTALLDIR/busybox.original; fi
131 # Uninstallation of the enhanced binary in Maemo's SDK
133 if test -e $INSTALLDIR/busybox.original
135 cp -f $INSTALLDIR/busybox.original /bin/busybox
136 if test -e /bin/busybox; then rm $INSTALLDIR/busybox.original; fi
142 # Remove all symlinks that busybox-power has made
144 # Load list of installed symlinks
145 source $INSTALLDIR/busybox-power.symlinks
147 # Walk through all possible destinations
148 for DESTDIR in $DESTINATIONS
150 # Enable us to see all entries in $DESTIONATION as variables
151 eval "APPLICATIONS=\$$DESTDIR"
152 # Set destination dirrectory accordingly
168 if test $VERBOSE == 1; then echo -e "\nRemoving symlinks in $DIR"; fi
169 # Walk through all applications from the current destination
170 for APP in $APPLICATIONS
172 # The following code is executed for every application in the current destination
173 if test -h $DIR/$APP # Check if the app is a symbolic link
175 if test -n "`ls -l $DIR/$APP | grep busybox`" # Check if the symbolic link points to busybox
177 if test $VERBOSE == 1; then echo "Removing link: $DIR/$APP"; fi
185 # Action to be performed after restoring original busybox
187 OLDFILES="busybox-power.symlinks
189 busybox.original.md5"
191 for file in $OLDFILES
193 if test -e $INSTALLDIR/$file; then
204 # Check for errors before restoring BusyBox
205 if test -e /tmp/busybox-power-error
206 then DISPLAY_ERRORS; fi
212 # Check for errors before restoring BusyBox
213 if test -e /tmp/busybox-power-error
214 then DISPLAY_ERRORS; fi