backuptool: Properly unmount system partition

For non AB devices system partition should be unmounted
if check_prereq function fails.

This patch also refactors backuptool a bit for AB devices
in order to look same as backuptool for non AB devices.

Change-Id: Ia1f4ae95c9e4dae4df844853e81c264bc838f177
diff --git a/prebuilt/common/bin/backuptool.sh b/prebuilt/common/bin/backuptool.sh
index 9853eed..2f14522 100755
--- a/prebuilt/common/bin/backuptool.sh
+++ b/prebuilt/common/bin/backuptool.sh
@@ -29,12 +29,13 @@
   if [ ! -f /tmp/build.prop ]; then
     # this will block any backups made before 8 cause file was not copied before
     echo "Not restoring files from incompatible version: $V"
-    exit 127
+    return 0
   fi
   if ( ! grep -q "^ro.build.version.release=$V.*" /tmp/build.prop ); then
     echo "Not restoring files from incompatible version: $V"
-    exit 127
+    return 0
   fi
+  return 1
 }
 
 # Execute /system/addon.d/*.sh scripts with $1 parameter
@@ -81,7 +82,10 @@
     cp $S/build.prop /tmp
     mount_system
     mkdir -p $C
-    #check_prereq
+    if ! check_prereq; then
+      unmount_system
+      exit 127
+    end
     preserve_addon_d
     run_stage pre-backup
     run_stage backup
@@ -91,7 +95,10 @@
   restore)
     cp $S/bin/backuptool.functions /tmp
     mount_system
-    check_prereq
+    if ! check_prereq; then
+      unmount_system
+      exit 127
+    end
     run_stage pre-restore
     run_stage restore
     run_stage post-restore