Recovery BackupTool: add system mount check to prevent (u)mount if already mounted
diff --git a/prebuilt/common/bin/backuptool.sh b/prebuilt/common/bin/backuptool.sh
index 39666ce..85f800e 100755
--- a/prebuilt/common/bin/backuptool.sh
+++ b/prebuilt/common/bin/backuptool.sh
@@ -140,9 +140,15 @@
    fi
 }
 
+# don't (u)mount system if already done
+UMOUNT=0
+
 case "$1" in
    backup)
-      mount $S
+      if [ ! -f "$S/build.prop" ]; then
+         mount $S
+         UMOUNT=1
+      fi
       check_prereq;
       check_installscript;
       if [ $PROCEED -ne 0 ];
@@ -155,9 +161,15 @@
            done
          done
       fi
-      umount $S
+      if [ $UMOUNT -ne 0 ]; then
+         umount $S
+      fi
    ;;
    restore)
+      if [ ! -f "$S/build.prop" ]; then
+         mount $S
+         UMOUNT=1
+      fi
       check_prereq;
       check_installscript;
       if [ $PROCEED -ne 0 ];
@@ -171,6 +183,10 @@
          done
          rm -rf $C
       fi
+      if [ $UMOUNT -ne 0 ]; then
+         umount $S
+      fi
+      sync
    ;;
    *)
       echo "Usage: $0 {backup|restore}"