backuptool: Fix backup/restore functionality

Backup/restore functionality was broken in the
Ia1f4ae95c9e4dae4df844853e81c264bc838f177 change
because of incorrect check of the function's result.

check_prereq() function refactored to return 0 if
backuping/restoration is possible. Any work should be
performed only if check_prereq() succeeds.

Change-Id: Ic977dba675df58a228ef4b882b25beb66cc9d2c6
diff --git a/prebuilt/common/bin/backuptool_ab.sh b/prebuilt/common/bin/backuptool_ab.sh
index d542700..0dbbb9a 100755
--- a/prebuilt/common/bin/backuptool_ab.sh
+++ b/prebuilt/common/bin/backuptool_ab.sh
@@ -47,14 +47,15 @@
 check_prereq() {
 # If there is no build.prop file the partition is probably empty.
 if [ ! -r /system/build.prop ]; then
-    return 0
+  echo "Backup/restore is not possible. Partition is probably empty"
+  return 1
 fi
 
 if ! grep -q "^ro.omni.version=$V.*" /product/build.prop; then
-    echo "Not backing up files from incompatible version: $V"
-    return 0
+  echo "Backup/restore is not possible. Incompatible ROM version: $V"
+  return 2
 fi
-return 1
+return 0
 }
 
 # Execute /system/addon.d/*.sh scripts with $1 parameter
@@ -78,30 +79,25 @@
 
 case "$1" in
   backup)
-    mkdir -p $C
-    if ! check_prereq; then
-      exit 127
+    if check_prereq; then
+      mkdir -p $C
+      preserve_addon_d
+      run_stage pre-backup
+      run_stage backup
+      run_stage post-backup
     fi
     log -t "update_engine" "backuptool_ab.sh backup"
-
-    preserve_addon_d
-    run_stage pre-backup
-    run_stage backup
-    run_stage post-backup
   ;;
   restore)
-    if ! check_prereq; then
-      exit 127
-    fi
+    if check_prereq; then
+      run_stage pre-restore
+      run_stage restore
+      run_stage post-restore
+      restore_addon_d
+      rm -rf $C
+      rm -rf /postinstall/tmp
+      sync
     log -t "update_engine" "backuptool_ab.sh restore"
-
-    run_stage pre-restore
-    run_stage restore
-    run_stage post-restore
-    restore_addon_d
-    rm -rf $C
-    rm -rf /postinstall/tmp
-    sync
   ;;
   *)
     echo "Usage: $0 {backup|restore}"