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>
14 INSTALLDIR="/opt/busybox-power"
15 EXECPWR="$INSTALLDIR/busybox.power"
19 # Load shared functions
20 source $INSTALLDIR/functions
22 # Check whether we can load the list of created symlinks during installation
23 CHECK_SYMLINKSFILE() {
24 if test ! -e $INSTALLDIR/busybox-power.symlinks; then
25 echo -e "Error: cannot find the list of symlinks to be removed. No symlinks will be removed at all!\n" >> /tmp/busybox-power-error
29 # Check the (integrity) of our BusyBox backup
31 # Firstly, check whether the backup still exists
32 if test ! -e $INSTALLDIR/busybox.original; then
33 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
37 # Secondly, check the integrity of the backup
38 if test -e $INSTALLDIR/busybox.original.sha1; then
39 INSTBINARY_SHA1=`cat $INSTALLDIR/busybox.original.sha1`
40 ORIGBINARY_SHA1=`sha1sum $INSTALLDIR/busybox.original | awk '{ print $1 }'`
41 if test ! "$INSTBINARY_SHA1" == "$ORIGBINARY_SHA1"; then
42 echo -e "Warning: the backed-up original binary has been modified since installing busybox-power (invalid SHA1 checksum). Do not continue unless you're sure $INSTALLDIR/busybox.original isn't corrupted.\n" >> /tmp/busybox-power-error
45 echo -e "Warning: couldn't load the saved SHA1 checksum of the original binary; the integrity of the backup of the original binary can not be guaranteed.\n" >> /tmp/busybox-power-error
49 # Check whether /bin/busybox has been modified after bb-power's installation
50 CHECK_INSTALLEDBIN() {
51 if test -e $INSTALLDIR/busybox.power.sha1; then
52 INSTBINARY_SHA1=`sha1sum /bin/busybox | awk '{ print $1 }'`
53 ORIGBINARY_SHA1=`cat $INSTALLDIR/busybox.power.sha1`
54 if test ! "$INSTBINARY_SHA1" == "$ORIGBINARY_SHA1"; then
55 echo -e "Warning: /bin/busybox has been modified since installing busybox-power (invalid SHA1 checksum). This can be the result of a busybox upgrade, e.g. from CSSU. Your current /bin/busybox won't be touched, our backup of the original /bin/busybox will be copied to /opt/busybox.original. \n" >> /tmp/busybox-power-error
61 # Display encountered errors
65 echo -e "\n\n-----------Attention!-----------"
66 cat /tmp/busybox-power-error
67 rm /tmp/busybox-power-error
68 echo "-> Please press [enter] to ignore the above errors/warnings."
69 echo " Hit [ctrl-c] to break"
73 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
74 echo "Please confirm the text on the screen of your device"
75 maemo-confirm-text "Attention!" /tmp/busybox-power-error
77 rm /tmp/busybox-power-error
78 if test ! $res == 0; then exit 1; fi
83 # Uninstallation of the enhanced binary
85 if test $MODIFIEDBIN == 1; then
86 # /bin/busybox has been modified since installing busybox-power
87 # Do not overwrite this modified version with our backup
88 mv $INSTALLDIR/busybox.original /opt/busybox.original
91 if test -e $INSTALLDIR/busybox.original; then
92 cp -f $INSTALLDIR/busybox.original /bin/busybox
93 if test -e /bin/busybox; then
94 rm $INSTALLDIR/busybox.original; fi
96 if test "$ENVIRONMENT" == "SDK"; then
97 # There was no /bin/busybox to begin with..
103 # Remove all symlinks that the installation script has made
105 # Load list of installed symlinks
106 touch $INSTALLDIR/busybox-power.symlinks
107 source $INSTALLDIR/busybox-power.symlinks
109 # Walk through all possible destinations
110 for DESTDIR in $DESTINATIONS; do
111 # Enable us to see all entries in $DESTINATIONS as variables
112 eval "APPLICATIONS=\$$DESTDIR"
113 # Set destination directory accordingly
129 ECHO_VERBOSE "\nRemoving symlinks in $DIR"
130 # Walk through all applications from the current destination
131 for APP in $APPLICATIONS; do
132 # The following code is executed for every application in the current destination
133 if test -h $DIR/$APP; then
134 # Good, this app is still a symbolic link ..
135 if test -n "`ls -l $DIR/$APP | grep busybox`"; then
136 ECHO_VERBOSE "Removing link: $DIR/$APP"
144 # Action to be performed after restoring original busybox
146 OLDFILES="busybox-power.symlinks
148 busybox.original.sha1"
150 for file in $OLDFILES; do
151 if test -e $INSTALLDIR/$file; then
158 ECHO_VERBOSE "busybox-power: verbose mode"
159 ECHO_VERBOSE " binary: $EXECPWR"
160 ECHO_VERBOSE " version string: `$EXECPWR | $EXECPWR head -n 1`"
161 CHECK_ENV && ECHO_VERBOSE " environment: $ENVIRONMENT"
165 if test "$ENVIRONMENT" != "SDK"; then
170 if test -e /tmp/busybox-power-error; then
171 # An error has occured during the checks