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"
20 INSTBINARY_SHA1=`sha1sum $EXECPWR | awk '{ print $1 }'`
21 if test -e $DISTBIN; then
22 ORIGBINARY_SHA1=`sha1sum $DISTBIN | awk '{ print $1 }'`; fi
24 # Load shared functions
25 source $INSTALLDIR/functions
27 # Check whether we can load the list of created symlinks during installation
28 CHECK_SYMLINKSFILE() {
29 if test ! -e $INSTALLDIR/busybox-power.symlinks; then
30 echo -e "Error: cannot find the list of symlinks to be removed. No symlinks will be removed at all!\n" >> /tmp/busybox-power-error
34 # Check the (integrity) of our BusyBox backup
36 # SDK doesn't ship with BusyBox by default, there might be no backup at all
37 if test ! -e $DISTBIN -a "$ENVIRONMENT" == "SDK" ; then
40 # Firstly, check whether the backup still exists
41 if test ! -e $DISTBIN; then
42 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
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 backed-up original binary has been modified since installing busybox-power (invalid SHA1 checksum). Do not continue unless you're sure $DISTBIN isn't corrupted.\n" >> /tmp/busybox-power-error
55 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
59 # Check whether /bin/busybox has been modified after bb-power's installation
60 CHECK_INSTALLEDBIN() {
61 if test ! "$INSTBINARY_SHA1" == "`sha1sum /bin/busybox | awk '{ print $1 }'`"; then
62 echo -e "Warning: /bin/busybox has been modified since installing busybox-power (invalid SHA1 checksum). Your current /bin/busybox won't be touched and the diversion of /bin/busybox to $DISTBIN will not be removed. \n" >> /tmp/busybox-power-error
67 # Display encountered errors
71 echo -e "\n\n-----------Attention!-----------"
72 cat /tmp/busybox-power-error
73 rm /tmp/busybox-power-error
74 echo "-> Please press [enter] to ignore the above errors/warnings."
75 echo " Hit [ctrl-c] to break"
79 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
80 echo "Please confirm the text on the screen of your device"
81 maemo-confirm-text "Attention!" /tmp/busybox-power-error
83 rm /tmp/busybox-power-error
84 if test ! $res == 0; then exit 1; fi
89 # Uninstallation of the enhanced binary
91 if test $MODIFIEDBIN == 1; then
92 # /bin/busybox has been modified since installing busybox-power
93 # Leave both the file and the diversion in place
95 elif test -e $DISTBIN; then
96 cp -af $DISTBIN /bin/busybox
97 if test -e /bin/busybox; then
99 elif test "$ENVIRONMENT" == "SDK"; then
100 # There was no /bin/busybox to begin with..
104 /usr/sbin/dpkg-divert --remove /bin/busybox
107 # Remove all symlinks that the installation script has made
109 # Load list of installed symlinks
110 touch $INSTALLDIR/busybox-power.symlinks
111 source $INSTALLDIR/busybox-power.symlinks
113 # Walk through all possible destinations
114 for DESTDIR in $DESTINATIONS; do
115 # Enable us to see all entries in $DESTINATIONS as variables
116 eval "APPLICATIONS=\$$DESTDIR"
117 # Set destination directory accordingly
133 ECHO_VERBOSE "\nRemoving symlinks in $DIR"
134 # Walk through all applications from the current destination
135 for APP in $APPLICATIONS; do
136 # The following code is executed for every application in the current destination
137 if test -h $DIR/$APP; then
138 # Good, this app is still a symbolic link ..
139 if test -n "`ls -l $DIR/$APP | grep busybox`"; then
140 ECHO_VERBOSE "Removing link: $DIR/$APP"
148 # Action to be performed after restoring original busybox
150 OLDFILES="busybox-power.symlinks
151 busybox.distrib.version
152 busybox.distrib.sha1"
154 for file in $OLDFILES; do
155 if test -e $INSTALLDIR/$file; then
162 ECHO_VERBOSE "busybox-power: verbose mode"
163 ECHO_VERBOSE " binary: $EXECPWR"
164 ECHO_VERBOSE " version string: `$EXECPWR | $EXECPWR head -n 1`"
165 CHECK_ENV && ECHO_VERBOSE " environment: $ENVIRONMENT"
169 if test "$ENVIRONMENT" != "SDK"; then
174 if test -e /tmp/busybox-power-error; then
175 # An error has occured during the checks