clean up scripts
authorDennis Groenen <tj.groenen@gmail.com>
Sun, 11 Mar 2012 16:29:44 +0000 (17:29 +0100)
committerDennis Groenen <tj.groenen@gmail.com>
Sun, 11 Mar 2012 16:29:44 +0000 (17:29 +0100)
debian/busybox-power.preinst
debian/rules
debian/scripts/applets [new file with mode: 0644]
debian/scripts/functions [deleted file]
debian/scripts/install-binary.sh
debian/scripts/uninstall-binary.sh

index e8f4bab..52b7684 100644 (file)
@@ -4,30 +4,29 @@ test "$1" = install || exit 0 # upgrades are fine
 
 # Detect environment
 #if test ! -e /proc/component_version
 
 # Detect environment
 #if test ! -e /proc/component_version
-if test -d /scratchbox
-  then
-    echo "busybox-power: Scratchbox environment detected"
-    ENVIRONMENT="SDK"
-  else
-    PROD=$(cat /proc/component_version | grep product | cut -d" " -f 6)
-    case $PROD in
-      RX-51)
-        echo "busybox-power: Maemo (N900) environment detected"
-        ENVIRONMENT="N900"
-        ;;
-      *)
-        # Unsupported, use the least strict environment (SDK)
-        echo "busybox-power: unsupported environment, using SDK codepath.."
-        ENVIRONMENT="SDK"
+if test -d /scratchbox; then
+  echo "busybox-power: Scratchbox environment detected"
+  ENVIRONMENT="SDK"
+else
+  PROD=$(cat /proc/component_version | grep product | cut -d" " -f 6)
+  case $PROD in
+    RX-51)
+      echo "busybox-power: Maemo (N900) environment detected"
+      ENVIRONMENT="N900"
       ;;
       ;;
-    esac
+    *)
+      # Unsupported, use the least strict environment (SDK)
+      echo "busybox-power: unsupported environment, using SDK codepath.."
+      ENVIRONMENT="SDK"
+      ;;
+  esac
 fi
 
 case $ENVIRONMENT in
   SDK)
     # Extra warning doesn't apply to SDK, just exit
     exit 0
 fi
 
 case $ENVIRONMENT in
   SDK)
     # Extra warning doesn't apply to SDK, just exit
     exit 0
-  ;;
+    ;;
   N900)
     f=/tmp/busybox-power-msg
     cat > $f <<EOF
   N900)
     f=/tmp/busybox-power-msg
     cat > $f <<EOF
@@ -37,10 +36,11 @@ Even though installation should be safe, a reflash might be required if somethin
 Files overwritten by this package:
 bin/busybox
 EOF
 Files overwritten by this package:
 bin/busybox
 EOF
+    echo "Please confirm the text on the screen of your device"
     maemo-confirm-text "Installation notes" $f
     res=$?
     rm -f $f
     exit $res
     maemo-confirm-text "Installation notes" $f
     res=$?
     rm -f $f
     exit $res
-  ;;
+    ;;
 esac
 
 esac
 
index e0a7f6a..476ccf7 100755 (executable)
@@ -82,7 +82,7 @@ binary-arch_busybox: $(STAMPS_DIR)/build_busybox
        dh_testdir
        dh_testroot
        dh_clean -k -d
        dh_testdir
        dh_testroot
        dh_clean -k -d
-       install -D -m644 debian/scripts/functions debian/busybox-power/opt/busybox-power/functions
+       install -D -m644 debian/scripts/applets debian/busybox-power/opt/busybox-power/applets
        install -D -m755 debian/scripts/install-binary.sh debian/busybox-power/opt/busybox-power/install-binary.sh
        install -D -m755 debian/scripts/uninstall-binary.sh debian/busybox-power/opt/busybox-power/uninstall-binary.sh
        install -D -m755 $(DIR)/busybox_unstripped debian/busybox-power/opt/busybox-power/busybox.power
        install -D -m755 debian/scripts/install-binary.sh debian/busybox-power/opt/busybox-power/install-binary.sh
        install -D -m755 debian/scripts/uninstall-binary.sh debian/busybox-power/opt/busybox-power/uninstall-binary.sh
        install -D -m755 $(DIR)/busybox_unstripped debian/busybox-power/opt/busybox-power/busybox.power
diff --git a/debian/scripts/applets b/debian/scripts/applets
new file mode 100644 (file)
index 0000000..970d38e
--- /dev/null
@@ -0,0 +1,20 @@
+#
+# This file contains (ideally) all applets supported by BusyBox sorted by
+# their respective location in a standard Debian installation.
+#
+# Please send in enhancements/corrections to my e-mail adress.
+#
+# By Dennis Groenen <tj.groenen@gmail.com>
+# Last updated: 11-22-2011 (MM-DD-YYYY)
+#
+
+# Define all possible destinations for the provided utilities
+DESTINATIONS="DEST_BIN DEST_SBIN DEST_USRBIN DEST_USRSBIN"
+
+# Define all utilities per destination
+# These will be symlinked to /bin/busybox
+DEST_BIN="bunzip2 bzcat bzip2 cpio cttyhack dnsdomainname dumpkmap ed fbset fdflush hush ip ipaddr iplink iproute iprule mountpoint mt nc pipe_progress popmaildir pscan usleep ash cat chgrp chmod chown cp date dd df dmesg echo false hostname ln ls mkdir mknod mktemp more mount mv pidof pwd readlink rm rmdir sed sleep stty sync tar touch true umount uname which grep egrep fgrep run-parts zcat gunzip gzip uncompress sh fsync kill ps fuser netstat groups users setserial su ping ping6 login"
+DEST_SBIN="blkid blockdev bootchartd crond fdisk ifenslave ip iptunnel klogd loadkmap logread makedevs mdev mkdosfs mke2fs mkfs.ext2 mkfs.vfat nbd-client raidautorun runlevel setconsole start-stop-daemon sulogin sysctl syslogd vconfig getty hwclock killall5 losetup mkswap swapoff swapon pivot_root halt reboot poweroff ifconfig nameif route slattach ifdown ifup zcip nameif findfs"
+DEST_USRBIN="adjtimex arping base64 beep brctl cal catv chattr chpst chrt chvt cryptpw dc deallocvt devmem diff dos2unix dumpleases eject envdir envuidgid ether-wake fdformat fgconsole flock freeramdisk ftpget ftpput hexdump ionice iostat ipcalc kbd_mode last length less linux32 linux64 loadfont lpd lpq lpr lsattr lsusb lzcat lzma lzop lzopcat makemime man microcom mkpasswd mpstat nmeter openvt patch pmap readahead reformime resize rev rpm rpm2cpio rtcwake runsv runsvdir rx script scriptreplay setarch setfont setkeycodes setlogcons setuidgid showkey smemcap softlimit strings sv svlogd tcpsvd telnet tftp timeout ttysize udhcpc udpsvd unix2dos unlzma unlzop unxz unzip uudecode uuencode vi volname wall wget xz xzcat zcipice [ [[ awk basename cksum clear cmp comm cut dirname du env expand expr find fold getopt head hostid id install logger logname md5sum mesg mkfifo nice nohup od printenv printf renice reset seq setsid sha1sum sort split stat sum tac tail tee test tr tty unexpand uniq wc which who whoami xargs yes ar time nslookup free pgrep pkill top uptime watch realpath killall chvt deallocvt openvt setkeycodes setlogcons kbd_mode whois pstree pwdx crontab ipcrm ipcs passwd traceroute traceroute6 vlock"
+DEST_USRSBIN="acpid add-shell addgroup adduser arp chat chpasswd delgroup deluser dhcprelay fakeidentd ftpd hdparm httpd ifplugd inetd lspci ntpd rdate rdev readprofile remove-shell sendmail sha256sum sha512sum telnetd tftpd tunctl udhcpd watchdog chroot ubirsvol dnsd"
+
diff --git a/debian/scripts/functions b/debian/scripts/functions
deleted file mode 100644 (file)
index c870852..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# This file contains (ideally) all utilities supported by BusyBox sorted by
-# their respective location in a standard Debian installation.
-#
-# Please send in enhancements/corrections to my e-mail adress.
-#
-# By Dennis Groenen <tj.groenen@gmail.com>
-# Last updated: 11-22-2011 (MM-DD-YYYY)
-#
-
-# Define all possible destinations for the provided utilities
-DESTINATIONS="DEST_BIN DEST_SBIN DEST_USRBIN DEST_USRSBIN"
-
-# Define all utilities per destination
-# These will be symlinked to /bin/busybox
-DEST_BIN="bunzip2 bzcat bzip2 cpio cttyhack dnsdomainname dumpkmap ed fbset fdflush hush ip ipaddr iplink iproute iprule mountpoint mt nc pipe_progress popmaildir pscan usleep ash cat chgrp chmod chown cp date dd df dmesg echo false hostname ln ls mkdir mknod mktemp more mount mv pidof pwd readlink rm rmdir sed sleep stty sync tar touch true umount uname which grep egrep fgrep run-parts zcat gunzip gzip uncompress sh fsync kill ps fuser netstat groups users setserial su ping ping6 login"
-DEST_SBIN="blkid blockdev bootchartd crond fdisk ifenslave ip iptunnel klogd loadkmap logread makedevs mdev mkdosfs mke2fs mkfs.ext2 mkfs.vfat nbd-client raidautorun runlevel setconsole start-stop-daemon sulogin sysctl syslogd vconfig getty hwclock killall5 losetup mkswap swapoff swapon pivot_root halt reboot poweroff ifconfig nameif route slattach ifdown ifup zcip nameif findfs"
-DEST_USRBIN="adjtimex arping base64 beep brctl cal catv chattr chpst chrt chvt cryptpw dc deallocvt devmem diff dos2unix dumpleases eject envdir envuidgid ether-wake fdformat fgconsole flock freeramdisk ftpget ftpput hexdump ionice iostat ipcalc kbd_mode last length less linux32 linux64 loadfont lpd lpq lpr lsattr lsusb lzcat lzma lzop lzopcat makemime man microcom mkpasswd mpstat nmeter openvt patch pmap readahead reformime resize rev rpm rpm2cpio rtcwake runsv runsvdir rx script scriptreplay setarch setfont setkeycodes setlogcons setuidgid showkey smemcap softlimit strings sv svlogd tcpsvd telnet tftp timeout ttysize udhcpc udpsvd unix2dos unlzma unlzop unxz unzip uudecode uuencode vi volname wall wget xz xzcat zcipice [ [[ awk basename cksum clear cmp comm cut dirname du env expand expr find fold getopt head hostid id install logger logname md5sum mesg mkfifo nice nohup od printenv printf renice reset seq setsid sha1sum sort split stat sum tac tail tee test tr tty unexpand uniq wc which who whoami xargs yes ar time nslookup free pgrep pkill top uptime watch realpath killall chvt deallocvt openvt setkeycodes setlogcons kbd_mode whois pstree pwdx crontab ipcrm ipcs passwd traceroute traceroute6 vlock"
-DEST_USRSBIN="acpid add-shell addgroup adduser arp chat chpasswd delgroup deluser dhcprelay fakeidentd ftpd hdparm httpd ifplugd inetd lspci ntpd rdate rdev readprofile remove-shell sendmail sha256sum sha512sum telnetd tftpd tunctl udhcpd watchdog chroot ubirsvol dnsd"
-
index bb828df..d45caae 100755 (executable)
@@ -1,50 +1,45 @@
 #!/bin/sh
 #!/bin/sh
-# A script to replace /bin/busybox and creates symlinks to new functions.
-# The default locations of busybox' functions (applets) are defined in the file $INSTALLDIR/functions
-# It keeps track of the installed symlinks by writing them to $INSTALLDIR/installed-symlinks in
-# a similiar fashion as locations are defined in the "functions" file.
+# A script to replace /bin/busybox and create missing symlinks to its applets.
 #
 #
-# The scripts check whether symlinks/binaries of the utilities already exist, and if not,
-# it checks whether the new busybox binary supports it. If so, it creates a symlink to /bin/busybox.
+# The target directories for BusyBox' applets are defined in the "applets" file.
+# This script will only create symbolic links when 1) they do not already exist 
+# in the filesystem, and 2) the BusyBox binary supports the applet. A list of 
+# all made symbolic links is written out to the file "busybox-power.symlinks", 
+# which will be used during uninstallation of busybox-power.
 #
 #
-# NB The busybox binary needs to support the install applet
+# NB The BusyBox binary needs to support the install applet.
 #
 # By Dennis Groenen <tj.groenen@gmail.com>
 # GPLv3 licensed
 #
 #
 # By Dennis Groenen <tj.groenen@gmail.com>
 # GPLv3 licensed
 #
-# Last updated: 11-22-2011 (MM-DD-YYYY)
+# Last updated: 03-11-2012 (MM-DD-YYYY)
 # 
 
 INSTALLDIR="/opt/busybox-power"
 EXECPWR="$INSTALLDIR/busybox.power"
 VERBOSE="0"
 
 # 
 
 INSTALLDIR="/opt/busybox-power"
 EXECPWR="$INSTALLDIR/busybox.power"
 VERBOSE="0"
 
-# Print extra information in verbose mode
-if test $VERBOSE == 1; then 
-  echo "busybox-power: verbose mode" \ 
-  echo "  binary: $EXECPWR" \ 
-  echo "  version string: `$EXECPWR | $EXECPWR head -n 1`"
-fi
+ECHO_VERBOSE() {
+       if test $VERBOSE == 1; then 
+               echo -e "$1"; fi
+}
 
 # Detect environment
 CHECK_ENV() {
 
 # Detect environment
 CHECK_ENV() {
-    if test -d /scratchbox
-      then
-        ENVIRONMENT="SDK"
-      else
-        PROD=$($EXECPWR cat /proc/component_version | $EXECPWR grep product | $EXECPWR cut -d" " -f 6)
-        case $PROD in
-          RX-51)
-            ENVIRONMENT="N900"
+    if test -d /scratchbox; then
+      ENVIRONMENT="SDK"
+    else
+      PROD=$($EXECPWR cat /proc/component_version | $EXECPWR grep product | $EXECPWR cut -d" " -f 6)
+      case $PROD in
+        RX-51)
+          ENVIRONMENT="N900"
           ;;
           ;;
-          *)
-            # Unsupported, use the least strict environment (SDK)
-            ENVIRONMENT="SDK"
+        *)
+          # Unsupported, use the least strict environment (SDK)
+          ENVIRONMENT="SDK"
           ;;
           ;;
-        esac
+      esac
     fi
     fi
-
-    if test $VERBOSE == 1; then echo "  environment: $ENVIRONMENT"; fi
 }
 
 # Environment-independent checks before continuing
 }
 
 # Environment-independent checks before continuing
@@ -57,8 +52,8 @@ GENERIC_CHECKS() {
       exit 1
     fi
 
       exit 1
     fi
 
-    if test ! -e $INSTALLDIR/functions; then
-      echo "error: cannot find list of defined functions"
+    if test ! -e $INSTALLDIR/applets; then
+      echo "error: cannot find list of defined applets"
       exit 1
     fi
 
       exit 1
     fi
 
@@ -82,113 +77,112 @@ E_N900_CHECKS() {
 
 # N900-specific code executed prior to installing the enhanced binary
 E_N900_PREINST() {
 
 # N900-specific code executed prior to installing the enhanced binary
 E_N900_PREINST() {
-    md5sum $INSTALLDIR/busybox.power | $EXECPWR awk '{ print $1 }' > $INSTALLDIR/busybox.power.md5
-    md5sum /bin/busybox | $EXECPWR awk '{ print $1 }' > $INSTALLDIR/busybox.original.md5
+    $EXECPWR md5sum $INSTALLDIR/busybox.power | $EXECPWR awk '{ print $1 }' \
+      > $INSTALLDIR/busybox.power.md5
+    $EXECPWR md5sum /bin/busybox | $EXECPWR awk '{ print $1 }' \
+      > $INSTALLDIR/busybox.original.md5
 
     # Check whether busybox-power isn't installed already
     INSTBINARY_MD5=`$EXECPWR cat $INSTALLDIR/busybox.power.md5`
     ORIGBINARY_MD5=`$EXECPWR cat $INSTALLDIR/busybox.original.md5`
 
     # Check whether busybox-power isn't installed already
     INSTBINARY_MD5=`$EXECPWR cat $INSTALLDIR/busybox.power.md5`
     ORIGBINARY_MD5=`$EXECPWR cat $INSTALLDIR/busybox.original.md5`
-    if test "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"
-      then
-        echo "warning: installed busybox binary matches the binary"
-        echo "  that is to be installed"
-        if ! test -e $INSTALLDIR/busybox.original; then 
-          $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original; fi
-      else
-        $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original
+    if test "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"; then
+      echo "warning: installed busybox binary matches the binary"
+      echo "  that is to be installed"
+      if ! test -e $INSTALLDIR/busybox.original; then 
+        $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original; fi
+    else
+      $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original
     fi
 }
 
 # SDK-specific code executed prior to installing the enhanced binary
 E_SDK_PREINST() {
     fi
 }
 
 # SDK-specific code executed prior to installing the enhanced binary
 E_SDK_PREINST() {
-    if test -e /bin/busybox
-      then
-        $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original
-    fi
+    if test -e /bin/busybox; then
+      $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original; fi
 }
 
 }
 
-# Overwrite old busybox binary with bbpower's one
+# Overwrite the installed binary with the enhanced binary
 INSTALL() {
     $EXECPWR cp -f $INSTALLDIR/busybox.power /bin/busybox
 }
 
 INSTALL() {
     $EXECPWR cp -f $INSTALLDIR/busybox.power /bin/busybox
 }
 
-# Creates missing symlinks to busybox' binary
+# Creates missing symlinks to the enhanced binary
 SYMLINK() {
 SYMLINK() {
-    # Load defined BusyBox functions
-    source $INSTALLDIR/functions
+    # Load defined BusyBox applets
+    source $INSTALLDIR/applets
 
 
-    # Get a list of supported functions by busybox-power
-    if test -d /tmp/busybox-power; then $EXECPWR rm -Rf /tmp/busybox-power; fi
+    # Get a list of supported applets by busybox-power
+    if test -d /tmp/busybox-power; then 
+      $EXECPWR rm -Rf /tmp/busybox-power; fi
     $EXECPWR mkdir -p /tmp/busybox-power
     $EXECPWR mkdir -p /tmp/busybox-power
-    $INSTALLDIR/busybox.power --install -s /tmp/busybox-power
-    $EXECPWR ls /tmp/busybox-power/ > $INSTALLDIR/functions_supported
+    $EXECPWR --install -s /tmp/busybox-power
+    $EXECPWR ls /tmp/busybox-power/ > $INSTALLDIR/applets_supported
     $EXECPWR rm -Rf /tmp/busybox-power
 
     $EXECPWR rm -Rf /tmp/busybox-power
 
-    # Prepare file which keeps track of installed symlinks by busybox-power
+    # Prepare file that will keep track of installed symlinks by busybox-power
     echo "# Automatically generated by busybox-power. DO NOT EDIT" > $INSTALLDIR/busybox-power.symlinks
     echo -e "\nDESTINATIONS=\"$DESTINATIONS\"" >> $INSTALLDIR/busybox-power.symlinks
     echo -e "\n# Installed symlinks" >> $INSTALLDIR/busybox-power.symlinks
 
     # Walk through all possible destinations
     echo "# Automatically generated by busybox-power. DO NOT EDIT" > $INSTALLDIR/busybox-power.symlinks
     echo -e "\nDESTINATIONS=\"$DESTINATIONS\"" >> $INSTALLDIR/busybox-power.symlinks
     echo -e "\n# Installed symlinks" >> $INSTALLDIR/busybox-power.symlinks
 
     # Walk through all possible destinations
-    for DESTDIR in $DESTINATIONS
-      do 
-        # Enable us to see all entries in $DESTINATION as variables
-        eval "APPLICATIONS=\$$DESTDIR"
-
-        # Set destination directory accordingly
-        case $DESTDIR in
-          DEST_BIN)
-            DIR="/bin"
+    for DESTDIR in $DESTINATIONS; do 
+      # Enable us to see all entries in $DESTINATION as variables
+      eval "APPLICATIONS=\$$DESTDIR"
+
+      # Set destination directory accordingly
+      case $DESTDIR in
+        DEST_BIN)
+          DIR="/bin"
           ;;
           ;;
-          DEST_SBIN)
-            DIR="/sbin"
+        DEST_SBIN)
+          DIR="/sbin"
           ;;
           ;;
-          DEST_USRBIN)
-            DIR="/usr/bin"
+        DEST_USRBIN)
+          DIR="/usr/bin"
           ;;
           ;;
-          DEST_USRSBIN)
-            DIR="/usr/sbin"
+        DEST_USRSBIN)
+          DIR="/usr/sbin"
           ;;
           ;;
-        esac
+      esac
 
       # Keep track of installed symlinks per destination
       SYMLINKS="$DESTDIR=\""
 
 
       # Keep track of installed symlinks per destination
       SYMLINKS="$DESTDIR=\""
 
-      if test $VERBOSE == 1; then echo -e "\nSymlinking functions in $DIR"; fi
+      ECHO_VERBOSE "\nSymlinking applets in $DIR"
       # Walk through all applications from the current destination
       # Walk through all applications from the current destination
-      for APP in $APPLICATIONS
-        do
-          # The following code is executed for every application in the current destination
-          if test ! -e $DIR/$APP
-            then
-              # Check whether the function is supported by the busybox binary
-              if `$EXECPWR grep -Fq "$APP" $INSTALLDIR/functions_supported` 
-                then
-                  if test $VERBOSE == 1; then echo "Symlinking: /bin/busybox -> $DIR/$APP"; fi
-                  $EXECPWR ln -s /bin/busybox $DIR/$APP
-                  SYMLINKS="$SYMLINKS $APP" 
-              fi
+      for APP in $APPLICATIONS; do
+        # The following code is executed for all applets in the current destination
+        if test ! -e $DIR/$APP; then
+          # Check whether the applet is supported by the busybox binary
+          if `$EXECPWR grep -Fq "$APP" $INSTALLDIR/applets_supported`; then
+            ECHO_VERBOSE "Symlinking: /bin/busybox -> $DIR/$APP"
+            $EXECPWR ln -s /bin/busybox $DIR/$APP
+            SYMLINKS="$SYMLINKS $APP" 
           fi
           fi
+        fi
       done
 
       # Write out installed symlinks
       echo "$SYMLINKS\"" >> $INSTALLDIR/busybox-power.symlinks
     done
 
       done
 
       # Write out installed symlinks
       echo "$SYMLINKS\"" >> $INSTALLDIR/busybox-power.symlinks
     done
 
-    $EXECPWR rm $INSTALLDIR/functions_supported
+    $EXECPWR rm $INSTALLDIR/applets_supported
 }
 
 ### Codepath ###
 }
 
 ### Codepath ###
-CHECK_ENV
+ECHO_VERBOSE "busybox-power: verbose mode"
+ECHO_VERBOSE "  binary: $EXECPWR"
+ECHO_VERBOSE "  version string: `$EXECPWR | $EXECPWR head -n 1`"
+CHECK_ENV && ECHO_VERBOSE "  environment: $ENVIRONMENT"
 GENERIC_CHECKS
 case $ENVIRONMENT in
   SDK)
     E_SDK_PREINST
 GENERIC_CHECKS
 case $ENVIRONMENT in
   SDK)
     E_SDK_PREINST
-  ;;
+    ;;
   N900)
     E_N900_CHECKS
     E_N900_PREINST
   N900)
     E_N900_CHECKS
     E_N900_PREINST
-  ;;
+    ;;
 esac
 INSTALL
 SYMLINK
 esac
 INSTALL
 SYMLINK
index fff462a..c0eecc5 100755 (executable)
@@ -1,47 +1,43 @@
 #!/bin/sh
 #!/bin/sh
-# A script to restore /bin/busybox and delete created symlinks as defined in $INSTALLDIR/installed-symlinks
+# A script to restore /bin/busybox and delete the symlinks made during 
+# installation.
 #
 #
-# Symbolic links are only removed if they are
-# a) created by the installer script ("install-binary.sh")
-# b) not replaced by a binary (i.e. they are still a symbolic link)
-# c) pointing to a busybox binary
+# Symbolic links to applets are only removed if they are
+# 1) created by the installer script ("install-binary.sh")
+# 2) not replaced by a binary (i.e. they are still a symbolic link)
+# 3) pointing to a busybox binary
 #
 # By Dennis Groenen <tj.groenen@gmail.com>
 # GPLv3 licensed
 #
 #
 # By Dennis Groenen <tj.groenen@gmail.com>
 # GPLv3 licensed
 #
-# Last updated: 11-22-2011 (MM-DD-YYYY)
+# Last updated: 03-11-2012 (MM-DD-YYYY)
 # 
 
 INSTALLDIR="/opt/busybox-power"
 EXECPWR="$INSTALLDIR/busybox.power"
 VERBOSE="0"
 
 # 
 
 INSTALLDIR="/opt/busybox-power"
 EXECPWR="$INSTALLDIR/busybox.power"
 VERBOSE="0"
 
-# Print extra information in verbose mode
-if test $VERBOSE == 1; then 
-  echo "busybox-power: verbose mode" \ 
-  echo "  binary: $EXECPWR" \ 
-  echo "  version string: `$EXECPWR | $EXECPWR head -n 1`"
-fi
+ECHO_VERBOSE() {
+  if test $VERBOSE == 1; then 
+    echo -e "$1"; fi
+}
 
 # Detect environment
 CHECK_ENV() {
 
 # Detect environment
 CHECK_ENV() {
-    if test -d /scratchbox
-      then
-        ENVIRONMENT="SDK"
-      else
-        PROD=$(cat /proc/component_version | grep product | cut -d" " -f 6)
-        case $PROD in
-          RX-51)
-            ENVIRONMENT="N900"
+    if test -d /scratchbox; then
+      ENVIRONMENT="SDK"
+    else
+      PROD=$(cat /proc/component_version | grep product | cut -d" " -f 6)
+      case $PROD in
+        RX-51)
+          ENVIRONMENT="N900"
           ;;
           ;;
-          *)
-            # Unsupported, use the least strict environment (SDK)
-            ENVIRONMENT="SDK"
+        *)
+          # Unsupported, use the least strict environment (SDK)
+          ENVIRONMENT="SDK"
           ;;
           ;;
-        esac
+      esac
     fi
     fi
-
-    if test $VERBOSE == 1; then echo "  environment: $ENVIRONMENT"; fi
 }
 
 # Environment-independent checks before continuing
 }
 
 # Environment-independent checks before continuing
@@ -76,145 +72,132 @@ E_N900_CHECKS() {
 
 # N900-specific code executed prior to uninstalling the enhanced binary
 E_N900_PRERM() {
 
 # N900-specific code executed prior to uninstalling the enhanced binary
 E_N900_PRERM() {
-    if test -e $INSTALLDIR/busybox.power.md5
-      then
-        INSTBINARY_MD5=`md5sum /bin/busybox | awk '{ print $1 }'`
-        ORIGBINARY_MD5=`cat $INSTALLDIR/busybox.power.md5`
-        if test ! "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"; then
-          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
-        fi
+    if test -e $INSTALLDIR/busybox.power.md5; then
+      INSTBINARY_MD5=`md5sum /bin/busybox | awk '{ print $1 }'`
+      ORIGBINARY_MD5=`cat $INSTALLDIR/busybox.power.md5`
+      if test ! "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"; then
+        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
+      fi
     fi
 
     fi
 
-    if test -e $INSTALLDIR/busybox.original.md5
-      then
-        INSTBINARY_MD5=`cat $INSTALLDIR/busybox.original.md5`
-        ORIGBINARY_MD5=`md5sum $INSTALLDIR/busybox.original | awk '{ print $1 }'`
-        if test ! "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"; then
-          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
-        fi
-      else
-        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
+    if test -e $INSTALLDIR/busybox.original.md5; then
+      INSTBINARY_MD5=`cat $INSTALLDIR/busybox.original.md5`
+      ORIGBINARY_MD5=`md5sum $INSTALLDIR/busybox.original | awk '{ print $1 }'`
+      if test ! "$INSTBINARY_MD5" == "$ORIGBINARY_MD5"; then
+        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
+      fi
+    else
+      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
     fi
 }
 
 # Display encountered errors
 DISPLAY_ERRORS() {
     fi
 }
 
 # Display encountered errors
 DISPLAY_ERRORS() {
-      case $ENVIRONMENT in
-        SDK)
-          echo -e "\n\n-----------Attention!-----------"
-          cat /tmp/busybox-power-error
-          rm /tmp/busybox-power-error
-          echo "-> Please press [enter] to ignore the above errors/warnings. Hit [ctrl-c] to break"
-          read 
+    case $ENVIRONMENT in
+      SDK)
+        echo -e "\n\n-----------Attention!-----------"
+        cat /tmp/busybox-power-error
+        rm /tmp/busybox-power-error
+        echo "-> Please press [enter] to ignore the above errors/warnings."
+        echo "   Hit [ctrl-c] to break"
+        read 
         ;;
         ;;
-        N900)
-          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
-          maemo-confirm-text "Attention!" /tmp/busybox-power-error
-          res=$?
-          rm /tmp/busybox-power-error
-          if test ! $res == 0; then exit 1; fi
+      N900)
+        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
+        echo "Please confirm the text on the screen of your device"
+        maemo-confirm-text "Attention!" /tmp/busybox-power-error
+        res=$?
+        rm /tmp/busybox-power-error
+        if test ! $res == 0; then exit 1; fi
         ;;
       esac
         ;;
       esac
-
-      touch $INSTALLDIR/busybox-power.symlinks
 }
 
 }
 
-# Uninstallation of the enhanced binary on the N900
-E_N900_UNINST() {
-    if test -e $INSTALLDIR/busybox.original 
-      then
-        cp -f $INSTALLDIR/busybox.original /bin/busybox
-        if test -e /bin/busybox; then rm $INSTALLDIR/busybox.original; fi
-    fi 
-}
-
-# Uninstallation of the enhanced binary in Maemo's SDK
-E_SDK_UNINST() {
-    if test -e $INSTALLDIR/busybox.original
-      then
-       cp -f $INSTALLDIR/busybox.original /bin/busybox
-       if test -e /bin/busybox; then rm $INSTALLDIR/busybox.original; fi
-      else
-       rm /bin/busybox
+# Uninstallation of the enhanced binary
+UNINSTALL() {
+    if test -e $INSTALLDIR/busybox.original; then
+      cp -f $INSTALLDIR/busybox.original /bin/busybox
+      if test -e /bin/busybox; then
+        rm $INSTALLDIR/busybox.original; fi
+    else
+      if test "$ENVIRONMENT" == "SDK"; then
+        # There was no /bin/busybox to begin with..
+        rm /bin/busybox
+      fi
     fi
 }
 
     fi
 }
 
-# Remove all symlinks that busybox-power has made
+# Remove all symlinks that the installation script has made
 UNSYMLINK() {
     # Load list of installed symlinks
 UNSYMLINK() {
     # Load list of installed symlinks
+    touch $INSTALLDIR/busybox-power.symlinks
     source $INSTALLDIR/busybox-power.symlinks
 
     # Walk through all possible destinations
     source $INSTALLDIR/busybox-power.symlinks
 
     # Walk through all possible destinations
-    for DESTDIR in $DESTINATIONS
-      do 
-        # Enable us to see all entries in $DESTIONATION as variables
-        eval "APPLICATIONS=\$$DESTDIR"
-        # Set destination dirrectory accordingly
-        case $DESTDIR in
-          DEST_BIN)
-           DIR="/bin"
+    for DESTDIR in $DESTINATIONS; do 
+      # Enable us to see all entries in $DESTINATIONS as variables
+      eval "APPLICATIONS=\$$DESTDIR"
+      # Set destination directory accordingly
+      case $DESTDIR in
+        DEST_BIN)
+          DIR="/bin"
           ;;
           ;;
-          DEST_SBIN)
-           DIR="/sbin"
+        DEST_SBIN)
+          DIR="/sbin"
           ;;
           ;;
-          DEST_USRBIN)
-           DIR="/usr/bin"
+        DEST_USRBIN)
+          DIR="/usr/bin"
           ;;
           ;;
-          DEST_USRSBIN)
-           DIR="/usr/sbin"
+        DEST_USRSBIN)
+          DIR="/usr/sbin"
           ;;
           ;;
-        esac
+      esac
 
 
-      if test $VERBOSE == 1; then echo -e "\nRemoving symlinks in $DIR"; fi
+      ECHO_VERBOSE "\nRemoving symlinks in $DIR"
       # Walk through all applications from the current destination
       # Walk through all applications from the current destination
-      for APP in $APPLICATIONS
-        do
-          # The following code is executed for every application in the current destination
-          if test -h $DIR/$APP # Check if the app is a symbolic link
-           then
-             if test -n "`ls -l $DIR/$APP | grep busybox`" # Check if the symbolic link points to busybox
-               then
-                  if test $VERBOSE == 1; then echo "Removing link: $DIR/$APP"; fi
-                  rm $DIR/$APP
-             fi
+      for APP in $APPLICATIONS; do
+        # The following code is executed for every application in the current destination
+        if test -h $DIR/$APP; then 
+          # Good, this app is still a symbolic link ..
+          if test -n "`ls -l $DIR/$APP | grep busybox`"; then
+            ECHO_VERBOSE "Removing link: $DIR/$APP"
+            rm $DIR/$APP
           fi
           fi
+        fi
       done
     done
 }
 
 # Action to be performed after restoring original busybox
       done
     done
 }
 
 # Action to be performed after restoring original busybox
-POST_UNINST() {
+CLEANUP() {
     OLDFILES="busybox-power.symlinks
       busybox.power.md5
       busybox.original.md5"
 
     OLDFILES="busybox-power.symlinks
       busybox.power.md5
       busybox.original.md5"
 
-    for file in $OLDFILES
-      do
-       if test -e $INSTALLDIR/$file; then
-         rm $INSTALLDIR/$file
-       fi
-      done
+    for file in $OLDFILES; do
+      if test -e $INSTALLDIR/$file; then
+        rm $INSTALLDIR/$file
+      fi
+    done
 }
 
 ### Codepath ###
 }
 
 ### Codepath ###
-CHECK_ENV
+ECHO_VERBOSE "busybox-power: verbose mode"
+ECHO_VERBOSE "  binary: $EXECPWR"
+ECHO_VERBOSE "  version string: `$EXECPWR | $EXECPWR head -n 1`"
+CHECK_ENV && ECHO_VERBOSE "  environment: $ENVIRONMENT"
 GENERIC_CHECKS
 case $ENVIRONMENT in
 GENERIC_CHECKS
 case $ENVIRONMENT in
-  SDK)
-    # Check for errors before restoring BusyBox
-    if test -e /tmp/busybox-power-error
-      then DISPLAY_ERRORS; fi
-    E_SDK_UNINST
-  ;;
   N900)
     E_N900_CHECKS
     E_N900_PRERM
   N900)
     E_N900_CHECKS
     E_N900_PRERM
-    # Check for errors before restoring BusyBox
-    if test -e /tmp/busybox-power-error
-      then DISPLAY_ERRORS; fi
-    E_N900_UNINST
-  ;;
+    ;;
 esac
 esac
+if test -e /tmp/busybox-power-error; then
+  # An error has occured during the checks
+  DISPLAY_ERRORS
+fi
 UNSYMLINK
 UNSYMLINK
-POST_UNINST
+UNINSTALL
+CLEANUP