Andrew Dodd | 0c20901 | 2013-09-28 15:34:25 -0400 | [diff] [blame] | 1 | #!/sbin/sh |
| 2 | # |
| 3 | # Backup and restore addon /system files |
| 4 | # |
| 5 | |
| 6 | export C=/tmp/backupdir |
| 7 | export S=/system |
maxwen | 6156096 | 2017-08-23 20:41:54 +0200 | [diff] [blame] | 8 | export V=8.0 |
Andrew Dodd | 0c20901 | 2013-09-28 15:34:25 -0400 | [diff] [blame] | 9 | |
Marko Man | 2d21873 | 2017-09-12 02:24:39 +0200 | [diff] [blame^] | 10 | DEBUG=0 |
| 11 | |
Andrew Dodd | 0c20901 | 2013-09-28 15:34:25 -0400 | [diff] [blame] | 12 | # Preserve /system/addon.d in /tmp/addon.d |
| 13 | preserve_addon_d() { |
| 14 | mkdir -p /tmp/addon.d/ |
| 15 | cp -a /system/addon.d/* /tmp/addon.d/ |
| 16 | chmod 755 /tmp/addon.d/*.sh |
| 17 | } |
| 18 | |
| 19 | # Restore /system/addon.d in /tmp/addon.d |
| 20 | restore_addon_d() { |
| 21 | cp -a /tmp/addon.d/* /system/addon.d/ |
| 22 | rm -rf /tmp/addon.d/ |
| 23 | } |
| 24 | |
| 25 | # Proceed only if /system is the expected major and minor version |
| 26 | check_prereq() { |
| 27 | if ( ! grep -q "^ro.build.version.release=$V.*" /system/build.prop ); then |
| 28 | echo "Not backing up files from incompatible version: $V" |
| 29 | exit 127 |
| 30 | fi |
| 31 | } |
| 32 | |
| 33 | check_blacklist() { |
| 34 | if [ -f /system/addon.d/blacklist ];then |
| 35 | ## Discard any known bad backup scripts |
| 36 | cd /$1/addon.d/ |
| 37 | for f in *sh; do |
| 38 | s=$(md5sum $f | awk {'print $1'}) |
| 39 | grep -q $s /system/addon.d/blacklist && rm -f $f |
| 40 | done |
| 41 | fi |
| 42 | } |
| 43 | |
| 44 | # Execute /system/addon.d/*.sh scripts with $1 parameter |
| 45 | run_stage() { |
| 46 | for script in $(find /tmp/addon.d/ -name '*.sh' |sort -n); do |
Marko Man | 2d21873 | 2017-09-12 02:24:39 +0200 | [diff] [blame^] | 47 | if [ $DEBUG -eq 1 ]; then |
| 48 | echo run_stage $script $1 |
| 49 | fi |
Andrew Dodd | 0c20901 | 2013-09-28 15:34:25 -0400 | [diff] [blame] | 50 | $script $1 |
| 51 | done |
| 52 | } |
| 53 | |
| 54 | case "$1" in |
| 55 | backup) |
Marko Man | 2d21873 | 2017-09-12 02:24:39 +0200 | [diff] [blame^] | 56 | cp /system/bin/backuptool.functions /tmp |
Andrew Dodd | 0c20901 | 2013-09-28 15:34:25 -0400 | [diff] [blame] | 57 | mkdir -p $C |
| 58 | check_prereq |
| 59 | check_blacklist system |
| 60 | preserve_addon_d |
| 61 | run_stage pre-backup |
| 62 | run_stage backup |
| 63 | run_stage post-backup |
| 64 | ;; |
| 65 | restore) |
Marko Man | 2d21873 | 2017-09-12 02:24:39 +0200 | [diff] [blame^] | 66 | cp /system/bin/backuptool.functions /tmp |
Andrew Dodd | 0c20901 | 2013-09-28 15:34:25 -0400 | [diff] [blame] | 67 | check_prereq |
| 68 | check_blacklist tmp |
| 69 | run_stage pre-restore |
| 70 | run_stage restore |
| 71 | run_stage post-restore |
| 72 | restore_addon_d |
| 73 | rm -rf $C |
| 74 | sync |
| 75 | ;; |
| 76 | *) |
| 77 | echo "Usage: $0 {backup|restore}" |
| 78 | exit 1 |
| 79 | esac |
| 80 | |
| 81 | exit 0 |