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 d925eb5..97ef414 100755
--- a/prebuilt/common/bin/backuptool.sh
+++ b/prebuilt/common/bin/backuptool.sh
@@ -33,12 +33,13 @@
check_prereq() {
# If there is no build.prop file the partition is probably empty.
if [ ! -r $S/build.prop ]; then
- exit 127
+ return 0
fi
if ! grep -q "^ro.lineage.version=$V.*" $S/build.prop; then
echo "Not backing up files from incompatible version: $V"
- exit 127
+ return 0
fi
+return 1
}
# Execute /system/addon.d/*.sh scripts with $1 parameter
@@ -80,7 +81,10 @@
backup)
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
@@ -89,7 +93,10 @@
;;
restore)
mount_system
- check_prereq
+ if ! check_prereq; then
+ unmount_system
+ exit 127
+ end
run_stage pre-restore
run_stage restore
run_stage post-restore
diff --git a/prebuilt/common/bin/backuptool_ab.sh b/prebuilt/common/bin/backuptool_ab.sh
index 86bf67a..079d69d 100755
--- a/prebuilt/common/bin/backuptool_ab.sh
+++ b/prebuilt/common/bin/backuptool_ab.sh
@@ -47,13 +47,13 @@
check_prereq() {
# If there is no build.prop file the partition is probably empty.
if [ ! -r /system/build.prop ]; then
- exit 127
+ return 0
fi
-
-grep -q "^ro.lineage.version=$V.*" /system/build.prop && return 1
-
-echo "Not backing up files from incompatible version: $V"
-exit 127
+if ! grep -q "^ro.lineage.version=$V.*" /system/build.prop; then
+ echo "Not backing up files from incompatible version: $V"
+ return 0
+fi
+return 1
}
# Execute /system/addon.d/*.sh scripts with $1 parameter
@@ -74,14 +74,18 @@
case "$1" in
backup)
mkdir -p $C
- check_prereq
+ if ! check_prereq; then
+ exit 127
+ fi
preserve_addon_d
run_stage pre-backup
run_stage backup
run_stage post-backup
;;
restore)
- check_prereq
+ if ! check_prereq; then
+ exit 127
+ fi
run_stage pre-restore
run_stage restore
run_stage post-restore