2 # A script to restore /bin/busybox and delete the symlinks made during
5 # Symbolic links to applets are only removed if they are
6 # 1) created by the installer script ("install-binary.sh")
7 # 2) not replaced by a binary (i.e. they are still a symbolic link)
8 # 3) pointing to a busybox binary
10 # By Dennis Groenen <tj.groenen@gmail.com>
13 # Last updated: 03-11-2012 (MM-DD-YYYY)
16 INSTALLDIR="/opt/busybox-power"
17 EXECPWR="$INSTALLDIR/busybox.power"
21 if test $VERBOSE == 1; then
27 if test -d /scratchbox; then
30 PROD=$(cat /proc/component_version | grep product | cut -d" " -f 6)
36 # Unsupported, use the least strict environment (SDK)
43 # Environment-independent checks before continuing
45 #if test -n "`pgrep dpkg`" -o "`pgrep apt`"
46 if ! lsof /var/lib/dpkg/lock >> /dev/null; then
47 echo "error: you're running me as a stand-alone application"
48 echo " do not do this, I will be called automatically upon"
49 echo " deinstallation of busybox-power"
53 if test ! -e $INSTALLDIR/busybox-power.symlinks; then
54 echo -e "Error: cannot find the list of symlinks to be removed. No symlinks will be removed at all!\n" >> /tmp/busybox-power-error
58 # Additional checks for the N900
60 if test "`id -u`" -ne 0; then
61 echo "error: you're not running me as root, aborting"
62 echo " also, DO NOT run me as a stand-alone application"
63 echo " I will be called automatically upon deinstallation"
64 echo " of busybox-power"
68 if test ! -e $INSTALLDIR/busybox.original; then
69 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
73 # N900-specific code executed prior to uninstalling the enhanced binary
75 if test -e $INSTALLDIR/busybox.power.md5; then
76 INSTBINARY_MD5=`md5sum /bin/busybox | awk '{ print $1 }'`
77 ORIGBINARY_MD5=`cat $INSTALLDIR/busybox.power.md5`
78 if test ! "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"; then
79 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
83 if test -e $INSTALLDIR/busybox.original.md5; then
84 INSTBINARY_MD5=`cat $INSTALLDIR/busybox.original.md5`
85 ORIGBINARY_MD5=`md5sum $INSTALLDIR/busybox.original | awk '{ print $1 }'`
86 if test ! "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"; then
87 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
90 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
94 # Display encountered errors
98 echo -e "\n\n-----------Attention!-----------"
99 cat /tmp/busybox-power-error
100 rm /tmp/busybox-power-error
101 echo "-> Please press [enter] to ignore the above errors/warnings."
102 echo " Hit [ctrl-c] to break"
106 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
107 echo "Please confirm the text on the screen of your device"
108 maemo-confirm-text "Attention!" /tmp/busybox-power-error
110 rm /tmp/busybox-power-error
111 if test ! $res == 0; then exit 1; fi
116 # Uninstallation of the enhanced binary
118 if test -e $INSTALLDIR/busybox.original; then
119 cp -f $INSTALLDIR/busybox.original /bin/busybox
120 if test -e /bin/busybox; then
121 rm $INSTALLDIR/busybox.original; fi
123 if test "$ENVIRONMENT" == "SDK"; then
124 # There was no /bin/busybox to begin with..
130 # Remove all symlinks that the installation script has made
132 # Load list of installed symlinks
133 touch $INSTALLDIR/busybox-power.symlinks
134 source $INSTALLDIR/busybox-power.symlinks
136 # Walk through all possible destinations
137 for DESTDIR in $DESTINATIONS; do
138 # Enable us to see all entries in $DESTINATIONS as variables
139 eval "APPLICATIONS=\$$DESTDIR"
140 # Set destination directory accordingly
156 ECHO_VERBOSE "\nRemoving symlinks in $DIR"
157 # Walk through all applications from the current destination
158 for APP in $APPLICATIONS; do
159 # The following code is executed for every application in the current destination
160 if test -h $DIR/$APP; then
161 # Good, this app is still a symbolic link ..
162 if test -n "`ls -l $DIR/$APP | grep busybox`"; then
163 ECHO_VERBOSE "Removing link: $DIR/$APP"
171 # Action to be performed after restoring original busybox
173 OLDFILES="busybox-power.symlinks
175 busybox.original.md5"
177 for file in $OLDFILES; do
178 if test -e $INSTALLDIR/$file; then
185 ECHO_VERBOSE "busybox-power: verbose mode"
186 ECHO_VERBOSE " binary: $EXECPWR"
187 ECHO_VERBOSE " version string: `$EXECPWR | $EXECPWR head -n 1`"
188 CHECK_ENV && ECHO_VERBOSE " environment: $ENVIRONMENT"
196 if test -e /tmp/busybox-power-error; then
197 # An error has occured during the checks