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 <dennis_groenen@hotmail.com>
12 # Version 0.3 06-03-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
19 INSTALLDIR="/opt/busybox-power"
20 EXECPWR="$INSTALLDIR/busybox.power"
23 # Print extra information in verbose mode
24 if test $VERBOSE == 1; then
25 echo "busybox-power: verbose mode" \
26 echo " binary: $EXECPWR" \
27 echo " version string: `$EXECPWR | $EXECPWR head -n 1`"
32 if test -d /scratchbox
36 PROD=$(cat /proc/component_version | grep product | cut -d" " -f 6)
42 # Unsupported, use the least strict environment (SDK)
48 if test $VERBOSE == 1; then echo " environment: $ENVIRONMENT"; fi
51 # Environment-independent checks before continuing
53 #if test -n "`pgrep dpkg`" -o "`pgrep apt`"
54 if ! lsof /var/lib/dpkg/lock >> /dev/null; then
55 echo "error: you're running me as a stand-alone application"
56 echo " do not do this, I will be called automatically upon"
57 echo " deinstallation of busybox-power"
61 if test ! -e $INSTALLDIR/busybox-power.symlinks; then
62 echo -e "Error: cannot find the list of symlinks to be removed. No symlinks will be removed at all!\n" >> /tmp/busybox-power-error
66 # Additional checks for the N900
68 if test "`id -u`" -ne 0; then
69 echo "error: you're not running me as root, aborting"
70 echo " also, DO NOT run me as a stand-alone application"
71 echo " I will be called automatically upon deinstallation"
72 echo " of busybox-power"
76 if test ! -e $INSTALLDIR/busybox.original; then
77 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
81 # N900-specific code executed prior to uninstalling the enhanced binary
83 if test -e $INSTALLDIR/busybox.power.md5
85 INSTBINARY_MD5=`md5sum /bin/busybox | awk '{ print $1 }'`
86 ORIGBINARY_MD5=`cat $INSTALLDIR/busybox.power.md5`
87 if test ! "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"; then
88 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
92 if test -e $INSTALLDIR/busybox.original.md5
94 INSTBINARY_MD5=`cat $INSTALLDIR/busybox.original.md5`
95 ORIGBINARY_MD5=`md5sum $INSTALLDIR/busybox.original | awk '{ print $1 }'`
96 if test ! "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"; then
97 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
100 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
104 # Display encountered errors
108 echo -e "\n\n-----------Attention!-----------"
109 cat /tmp/busybox-power-error
110 rm /tmp/busybox-power-error
111 echo "-> Please press [enter] to ignore the above errors/warnings. Hit [ctrl-c] to break"
115 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
116 maemo-confirm-text "Attention!" /tmp/busybox-power-error
118 rm /tmp/busybox-power-error
119 if test ! $res == 0; then exit 1; fi
123 touch $INSTALLDIR/busybox-power.symlinks
126 # Uninstallation of the enhanced binary on the N900
128 if test -e $INSTALLDIR/busybox.original
130 cp -f $INSTALLDIR/busybox.original /bin/busybox
131 if test -e /bin/busybox; then rm $INSTALLDIR/busybox.original; fi
135 # Uninstallation of the enhanced binary in Maemo's SDK
137 if test -e $INSTALLDIR/busybox.original
139 cp -f $INSTALLDIR/busybox.original /bin/busybox
140 if test -e /bin/busybox; then rm $INSTALLDIR/busybox.original; fi
146 # Remove all symlinks that busybox-power has made
148 # Load list of installed symlinks
149 source $INSTALLDIR/busybox-power.symlinks
151 # Walk through all possible destinations
152 for DESTDIR in $DESTINATIONS
154 # Enable us to see all entries in $DESTIONATION as variables
155 eval "APPLICATIONS=\$$DESTDIR"
156 # Set destination dirrectory accordingly
172 if test $VERBOSE == 1; then echo -e "\nRemoving symlinks in $DIR"; 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 -h $DIR/$APP # Check if the app is a symbolic link
179 if test -n "`ls -l $DIR/$APP | grep busybox`" # Check if the symbolic link points to busybox
181 if test $VERBOSE == 1; then echo "Removing link: $DIR/$APP"; fi
189 # Action to be performed after restoring original busybox
191 OLDFILES="busybox-power.symlinks
193 busybox.original.md5"
195 for file in $OLDFILES
197 if test -e $INSTALLDIR/$file; then
208 # Check for errors before restoring BusyBox
209 if test -e /tmp/busybox-power-error
210 then DISPLAY_ERRORS; fi
216 # Check for errors before restoring BusyBox
217 if test -e /tmp/busybox-power-error
218 then DISPLAY_ERRORS; fi