use the diversion target for backing up the original binary
[busybox-power] / debian / scripts / install-binary.sh
index 2a9de6f..55ef026 100755 (executable)
 
 INSTALLDIR="/opt/busybox-power"
 EXECPWR="$INSTALLDIR/busybox.power"
+DISTBIN="/bin/busybox.distrib"
 VERBOSE="0"
 
+INSTBINARY_SHA1=`$EXECPWR sha1sum $EXECPWR | $EXECPWR awk '{ print $1 }'`
+ORIGBINARY_SHA1=`$EXECPWR sha1sum /bin/busybox | $EXECPWR awk '{ print $1 }'`
+
 # Load shared functions
 source $INSTALLDIR/functions
 
@@ -37,41 +41,24 @@ CHECK_SYMLINKSFILE() {
     fi
 }
 
-# Create MD5 hashes of relevant binaries
-HASH_BINARIES() {
-    $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
-}
-
 # Backup the original BusyBox binary
 BACKUP() {
-    case $ENVIRONMENT in
-      SDK)
-        # Scratchbox does not ship with BusyBox by default
-        if test -e /bin/busybox; then
-          $EXECPWR cp /bin/busybox $INSTALLDIR/busybox.original; fi
-        ;;
-      FREMANTLE)
-        # Check whether busybox-power isn't somehow 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
-        fi
-        ;;
-    esac
+    if test ! -e /bin/busybox; then
+      # Scratchbox does not ship with BusyBox by default
+      return
+    fi
+
+    if ! test "$INSTBINARY_SHA1" == "$ORIGBINARY_SHA1"; then
+      $EXECPWR cp -a /bin/busybox $DISTBIN
+      $EXECPWR sha1sum $DISTBIN | $EXECPWR awk '{ print $1 }' \
+        > $INSTALLDIR/busybox.distrib.sha1
+    fi
 }
 
 # Overwrite the installed binary with the enhanced binary
 INSTALL() {
-    $EXECPWR cp -f $INSTALLDIR/busybox.power /bin/busybox
+    /usr/sbin/dpkg-divert --local --divert $DISTBIN /bin/busybox
+    $EXECPWR cp -f $EXECPWR /bin/busybox
 }
 
 # Create missing symlinks to the enhanced binary
@@ -147,9 +134,7 @@ CHECK_STANDALONE
 CHECK_APPLETSFILE
 CHECK_SYMLINKSFILE
 if test "$ENVIRONMENT" != "SDK"; then
-  CHECK_ROOT
-  HASH_BINARIES
-fi
+  CHECK_ROOT; fi
 BACKUP
 INSTALL
 SYMLINK