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"
20 # Load shared functions
21 source $INSTALLDIR/functions
23 # Check whether we can load the list of created symlinks during installation
24 CHECK_SYMLINKSFILE() {
25 if test ! -e $INSTALLDIR/busybox-power.symlinks; then
26 echo -e "Error: cannot find the list of symlinks to be removed. No symlinks will be removed at all!\n" >> /tmp/busybox-power-error
30 # Check for a diversion of /bin/busybox
32 if test -e /bin/busybox.distrib; then
36 # Check the (integrity) of our BusyBox backup
38 # Firstly, check whether the backup still exists
39 if test ! -e $INSTALLDIR/busybox.original; then
40 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
44 # Secondly, check the integrity of the backup
45 if test -e $INSTALLDIR/busybox.original.sha1; then
46 INSTBINARY_SHA1=`cat $INSTALLDIR/busybox.original.sha1`
47 ORIGBINARY_SHA1=`sha1sum $INSTALLDIR/busybox.original | awk '{ print $1 }'`
48 if test ! "$INSTBINARY_SHA1" == "$ORIGBINARY_SHA1"; then
49 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
52 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
56 # Check whether /bin/busybox has been modified after bb-power's installation
57 CHECK_INSTALLEDBIN() {
58 if test -e $INSTALLDIR/busybox.power.sha1; then
59 INSTBINARY_SHA1=`sha1sum /bin/busybox | awk '{ print $1 }'`
60 ORIGBINARY_SHA1=`cat $INSTALLDIR/busybox.power.sha1`
61 if test ! "$INSTBINARY_SHA1" == "$ORIGBINARY_SHA1"; 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, our backup of the original /bin/busybox will be copied to /opt/busybox.original. \n" >> /tmp/busybox-power-error
68 # Display encountered errors
72 echo -e "\n\n-----------Attention!-----------"
73 cat /tmp/busybox-power-error
74 rm /tmp/busybox-power-error
75 echo "-> Please press [enter] to ignore the above errors/warnings."
76 echo " Hit [ctrl-c] to break"
80 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
81 echo "Please confirm the text on the screen of your device"
82 maemo-confirm-text "Attention!" /tmp/busybox-power-error
84 rm /tmp/busybox-power-error
85 if test ! $res == 0; then exit 1; fi
90 # Uninstallation of the enhanced binary
92 if test $DIVERTED == 1; then
93 # A package tried to install /bin/busybox since installing busybox-power
94 # This binary has priority over our own (old) backup
95 mv -f /bin/busybox.distrib /bin/busybox
96 rm $INSTALLDIR/busybox.original
97 elif test $MODIFIEDBIN == 1; then
98 # /bin/busybox has been modified since installing busybox-power
99 # Do not overwrite this modified version with our backup
100 mv -f $INSTALLDIR/busybox.original /opt/busybox.original
101 elif test -e $INSTALLDIR/busybox.original; then
102 cp -f $INSTALLDIR/busybox.original /bin/busybox
103 if test -e /bin/busybox; then
104 rm $INSTALLDIR/busybox.original; fi
105 elif test "$ENVIRONMENT" == "SDK"; then
106 # There was no /bin/busybox to begin with..
110 /usr/sbin/dpkg-divert --remove /bin/busybox
113 # Remove all symlinks that the installation script has made
115 # Load list of installed symlinks
116 touch $INSTALLDIR/busybox-power.symlinks
117 source $INSTALLDIR/busybox-power.symlinks
119 # Walk through all possible destinations
120 for DESTDIR in $DESTINATIONS; do
121 # Enable us to see all entries in $DESTINATIONS as variables
122 eval "APPLICATIONS=\$$DESTDIR"
123 # Set destination directory accordingly
139 ECHO_VERBOSE "\nRemoving symlinks in $DIR"
140 # Walk through all applications from the current destination
141 for APP in $APPLICATIONS; do
142 # The following code is executed for every application in the current destination
143 if test -h $DIR/$APP; then
144 # Good, this app is still a symbolic link ..
145 if test -n "`ls -l $DIR/$APP | grep busybox`"; then
146 ECHO_VERBOSE "Removing link: $DIR/$APP"
154 # Action to be performed after restoring original busybox
156 OLDFILES="busybox-power.symlinks
158 busybox.original.sha1"
160 for file in $OLDFILES; do
161 if test -e $INSTALLDIR/$file; then
168 ECHO_VERBOSE "busybox-power: verbose mode"
169 ECHO_VERBOSE " binary: $EXECPWR"
170 ECHO_VERBOSE " version string: `$EXECPWR | $EXECPWR head -n 1`"
171 CHECK_ENV && ECHO_VERBOSE " environment: $ENVIRONMENT"
176 if test "$ENVIRONMENT" != "SDK"; then
181 if test -e /tmp/busybox-power-error; then
182 # An error has occured during the checks