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: 08-24-2012 (MM-DD-YYYY)
16 INSTALLDIR="/opt/busybox-power"
17 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 the (integrity) of our BusyBox backup
32 # Firstly, check whether the backup still exists
33 if test ! -e $INSTALLDIR/busybox.original; then
34 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
38 # Secondly, check the integrity of the backup
39 if test -e $INSTALLDIR/busybox.original.md5; then
40 INSTBINARY_MD5=`cat $INSTALLDIR/busybox.original.md5`
41 ORIGBINARY_MD5=`md5sum $INSTALLDIR/busybox.original | awk '{ print $1 }'`
42 if test ! "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"; then
43 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
46 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
50 # Check whether /bin/busybox has been modified after bb-power's installation
51 CHECK_INSTALLEDBIN() {
52 if test -e $INSTALLDIR/busybox.power.md5; then
53 INSTBINARY_MD5=`md5sum /bin/busybox | awk '{ print $1 }'`
54 ORIGBINARY_MD5=`cat $INSTALLDIR/busybox.power.md5`
55 if test ! "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"; then
56 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
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 -e $INSTALLDIR/busybox.original; then
86 cp -f $INSTALLDIR/busybox.original /bin/busybox
87 if test -e /bin/busybox; then
88 rm $INSTALLDIR/busybox.original; fi
90 if test "$ENVIRONMENT" == "SDK"; then
91 # There was no /bin/busybox to begin with..
97 # Remove all symlinks that the installation script has made
99 # Load list of installed symlinks
100 touch $INSTALLDIR/busybox-power.symlinks
101 source $INSTALLDIR/busybox-power.symlinks
103 # Walk through all possible destinations
104 for DESTDIR in $DESTINATIONS; do
105 # Enable us to see all entries in $DESTINATIONS as variables
106 eval "APPLICATIONS=\$$DESTDIR"
107 # Set destination directory accordingly
123 ECHO_VERBOSE "\nRemoving symlinks in $DIR"
124 # Walk through all applications from the current destination
125 for APP in $APPLICATIONS; do
126 # The following code is executed for every application in the current destination
127 if test -h $DIR/$APP; then
128 # Good, this app is still a symbolic link ..
129 if test -n "`ls -l $DIR/$APP | grep busybox`"; then
130 ECHO_VERBOSE "Removing link: $DIR/$APP"
138 # Action to be performed after restoring original busybox
140 OLDFILES="busybox-power.symlinks
142 busybox.original.md5"
144 for file in $OLDFILES; do
145 if test -e $INSTALLDIR/$file; then
152 ECHO_VERBOSE "busybox-power: verbose mode"
153 ECHO_VERBOSE " binary: $EXECPWR"
154 ECHO_VERBOSE " version string: `$EXECPWR | $EXECPWR head -n 1`"
155 CHECK_ENV && ECHO_VERBOSE " environment: $ENVIRONMENT"
159 if test "$ENVIRONMENT" != "SDK"; then
164 if test -e /tmp/busybox-power-error; then
165 # An error has occured during the checks