diff options
Diffstat (limited to 'prebuilt/common/bin/backuptool.sh')
-rwxr-xr-x | prebuilt/common/bin/backuptool.sh | 68 |
1 files changed, 54 insertions, 14 deletions
diff --git a/prebuilt/common/bin/backuptool.sh b/prebuilt/common/bin/backuptool.sh index c576be3..7ff0c88 100755 --- a/prebuilt/common/bin/backuptool.sh +++ b/prebuilt/common/bin/backuptool.sh @@ -5,27 +5,39 @@ export C=/tmp/backupdir export S=/system -export V=10.1 +export V=13.0 + +# Scripts in /system/addon.d expect to find backuptool.functions in /tmp +cp -f /tmp/install/bin/backuptool.functions /tmp # 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" - exit 127 + return 0 fi +return 1 } check_blacklist() { @@ -33,23 +45,47 @@ check_blacklist() { ## Discard any known bad backup scripts cd /$1/addon.d/ for f in *sh; do - s=$(md5sum $f | awk {'print $1'}) + s=$(md5sum $f | cut -c-32) grep -q $s /system/addon.d/blacklist && rm -f $f done fi } +check_whitelist() { + found=0 + if [ -f /system/addon.d/whitelist ];then + ## forcefully keep any version-independent stuff + cd /$1/addon.d/ + for f in *sh; do + s=$(md5sum $f | cut -c-32) + grep -q $s /system/addon.d/whitelist + if [ $? -eq 0 ]; then + found=1 + else + rm -f $f + fi + done + fi + return $found +} + # 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 backup) mkdir -p $C - check_prereq + if check_prereq; then + if check_whitelist system; then + exit 127 + fi + fi check_blacklist system preserve_addon_d run_stage pre-backup @@ -57,7 +93,11 @@ case "$1" in run_stage post-backup ;; restore) - check_prereq + if check_prereq; then + if check_whitelist tmp; then + exit 127 + fi + fi check_blacklist tmp run_stage pre-restore run_stage restore |