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"
16 DISTBIN="/bin/busybox.distrib"
21 INSTBINARY_SHA1=`sha1sum $EXECPWR | awk '{ print $1 }'`
22 if test -e $DISTBIN; then
23 ORIGBINARY_SHA1=`sha1sum $DISTBIN | awk '{ print $1 }'`; fi
25 # Load shared functions
26 source $INSTALLDIR/functions
28 # Check whether we can load the list of created symlinks during installation
29 CHECK_SYMLINKSFILE() {
30 if test ! -e $INSTALLDIR/busybox-power.symlinks; then
31 echo -e "Warning: cannot find the list of symlinks to be removed. No" \
32 "symlinks will be removed at all!\n" >> /tmp/busybox-power-error
36 # Check the (integrity) of our BusyBox backup
38 # Firstly, check whether the backup still exists
39 if test ! -e $DISTBIN; then
40 if test "$ENVIRONMENT" == "SDK"; then return; fi # SDK comes without BB
41 echo -e "Warning: the backup of the original BusyBox binary is missing!" \
42 "/bin/busybox will not be touched.\n" >> /tmp/busybox-power-error
46 # Secondly, check the integrity of the backup
47 if test -e $INSTALLDIR/busybox.distrib.sha1; then
48 if test "`cat $INSTALLDIR/busybox.distrib.sha1`" != "$ORIGBINARY_SHA1"; then
49 if test "`cat $INSTALLDIR/busybox.distrib.version`" == "`GETBBVERSION`"; then
50 # The backup has been changed whilst busybox hasn't been upgraded
51 echo -e "Warning: the backup of the original BusyBox binary has" \
52 "been modified since installing busybox-power (invalid SHA1" \
53 "checksum). Do not continue unless you're sure that $DISTBIN" \
54 "is not corrupted.\n" >> /tmp/busybox-power-error
58 echo -e "Warning: could not load the saved SHA1 checksum of the backup" \
59 "of the original BusyBox binary; the integrity of the backup of the" \
60 "original binary can not be guaranteed.\n" >> /tmp/busybox-power-error
64 # Check whether /bin/busybox has been modified after bb-power's installation
65 CHECK_INSTALLEDBIN() {
66 if test "$INSTBINARY_SHA1" != "`sha1sum /bin/busybox | awk '{ print $1 }'`"; then
67 echo -e "Warning: /bin/busybox has been modified since installing" \
68 "busybox-power (invalid SHA1 checksum). Your current /bin/busybox" \
69 "won't be touched and the diversion of /bin/busybox to $DISTBIN will" \
70 "not be removed. \n" >> /tmp/busybox-power-error
75 # Display encountered errors
79 echo -e "\n\n-----------Attention!-----------"
80 cat /tmp/busybox-power-error
81 rm /tmp/busybox-power-error
82 echo "-> Please press [enter] to ignore the above errors/warnings."
83 echo " Hit [ctrl-c] to break"
87 echo "Click \"I Agree\" to ignore the above errors/warnings. Ask for" \
88 "help if you don't know what to do." >> /tmp/busybox-power-error
89 echo "Please confirm the text on the screen of your device"
90 maemo-confirm-text "Attention!" /tmp/busybox-power-error
92 rm /tmp/busybox-power-error
93 if test ! $res == 0; then exit 1; fi
98 # Uninstallation of the enhanced binary
100 if test $MODIFIEDBIN == 1; then
101 # /bin/busybox has been modified since installing busybox-power
102 # Leave both the file and the diversion in place
104 elif test -e $DISTBIN; then
105 cp -af $DISTBIN /bin/busybox
106 if test -e /bin/busybox; then
108 elif test "$ENVIRONMENT" == "SDK"; then
109 # There was no /bin/busybox to begin with..
113 /usr/sbin/dpkg-divert --remove /bin/busybox
116 # Remove all symlinks that the installation script has made
118 # Load list of installed symlinks
119 touch $INSTALLDIR/busybox-power.symlinks
120 source $INSTALLDIR/busybox-power.symlinks
122 # Walk through all possible destinations
123 for DESTDIR in $DESTINATIONS; do
124 # Enable us to see all entries in $DESTINATIONS as variables
125 eval "APPLICATIONS=\$$DESTDIR"
126 # Set destination directory accordingly
142 ECHO_VERBOSE "\nRemoving symlinks in $DIR"
143 # Walk through all applications from the current destination
144 for APP in $APPLICATIONS; do
145 # The following code is executed for every application in the current
147 if test -h $DIR/$APP; then
148 # Good, this app is still a symbolic link ..
149 if test -n "`ls -l $DIR/$APP | grep busybox`"; then
150 ECHO_VERBOSE "Removing link: $DIR/$APP"
158 # Action to be performed after restoring original busybox
160 OLDFILES="busybox-power.symlinks
161 busybox.distrib.version
162 busybox.distrib.sha1"
164 for file in $OLDFILES; do
165 if test -e $INSTALLDIR/$file; then
172 ECHO_VERBOSE "busybox-power: verbose mode"
173 ECHO_VERBOSE " binary: $EXECPWR"
174 ECHO_VERBOSE " version string: `$EXECPWR | $EXECPWR head -n 1`"
175 CHECK_ENV && ECHO_VERBOSE " environment: $ENVIRONMENT"
179 if test "$ENVIRONMENT" != "SDK"; then
184 if test -e /tmp/busybox-power-error; then
185 # An error has occured during the checks