backuptool: Add checks if it makes sense to execute commands
Change-Id: Ic83fc1168ac459b1bba5cef97d184ce2a9db4c68
diff --git a/prebuilt/common/bin/backuptool.sh b/prebuilt/common/bin/backuptool.sh
index fa29ad2..e2759ed 100755
--- a/prebuilt/common/bin/backuptool.sh
+++ b/prebuilt/common/bin/backuptool.sh
@@ -12,19 +12,27 @@
# Preserve /system/addon.d in /tmp/addon.d
preserve_addon_d() {
- mkdir -p /tmp/addon.d/
- cp -a /system/addon.d/* /tmp/addon.d/
- chmod 755 /tmp/addon.d/*.sh
+ if [ -d /system/addon.d/ ]; then
+ mkdir -p /tmp/addon.d/
+ cp -a /system/addon.d/* /tmp/addon.d/
+ chmod 755 /tmp/addon.d/*.sh
+ fi
}
-# Restore /system/addon.d in /tmp/addon.d
+# Restore /system/addon.d from /tmp/addon.d
restore_addon_d() {
- cp -a /tmp/addon.d/* /system/addon.d/
- rm -rf /tmp/addon.d/
+ if [ -d /tmp/addon.d/ ]; then
+ cp -a /tmp/addon.d/* /system/addon.d/
+ rm -rf /tmp/addon.d/
+ fi
}
# Proceed only if /system is the expected major and minor version
check_prereq() {
+# If there is no build.prop file the partition is probably empty.
+if [ ! -r /system/build.prop ]; then
+ return 0
+fi
if ( ! grep -q "^ro.cm.version=$V.*" /system/build.prop ); then
echo "Not backing up files from incompatible version: $V"
return 0
@@ -63,9 +71,11 @@
# Execute /system/addon.d/*.sh scripts with $1 parameter
run_stage() {
-for script in $(find /tmp/addon.d/ -name '*.sh' |sort -n); do
- $script $1
-done
+if [ -d /tmp/addon.d/ ]; then
+ for script in $(find /tmp/addon.d/ -name '*.sh' |sort -n); do
+ $script $1
+ done
+fi
}
case "$1" in