kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 1 | #!/sbin/sh |
| 2 | # |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 3 | # Backup and restore addon /system files |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 4 | # |
| 5 | |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 6 | export C=/tmp/backupdir |
| 7 | export S=/system |
Ricardo Cerqueira | a690013 | 2013-07-27 01:54:17 +0100 | [diff] [blame] | 8 | export V=10.2 |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 9 | |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 10 | # Preserve /system/addon.d in /tmp/addon.d |
| 11 | preserve_addon_d() { |
| 12 | mkdir -p /tmp/addon.d/ |
| 13 | cp -a /system/addon.d/* /tmp/addon.d/ |
| 14 | chmod 755 /tmp/addon.d/*.sh |
| 15 | } |
| 16 | |
| 17 | # Restore /system/addon.d in /tmp/addon.d |
| 18 | restore_addon_d() { |
| 19 | cp -a /tmp/addon.d/* /system/addon.d/ |
| 20 | rm -rf /tmp/addon.d/ |
| 21 | } |
| 22 | |
Chirayu Desai | 700fc8f | 2012-12-13 19:36:37 +0530 | [diff] [blame] | 23 | # Proceed only if /system is the expected major and minor version |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 24 | check_prereq() { |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 25 | if ( ! grep -q "^ro.cm.version=$V.*" /system/build.prop ); then |
Chirayu Desai | 700fc8f | 2012-12-13 19:36:37 +0530 | [diff] [blame] | 26 | echo "Not backing up files from incompatible version: $V" |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 27 | exit 127 |
| 28 | fi |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 29 | } |
| 30 | |
Ricardo Cerqueira | 129989b | 2012-12-19 01:11:21 +0000 | [diff] [blame] | 31 | check_blacklist() { |
| 32 | if [ -f /system/addon.d/blacklist ];then |
| 33 | ## Discard any known bad backup scripts |
| 34 | cd /$1/addon.d/ |
| 35 | for f in *sh; do |
| 36 | s=$(md5sum $f | awk {'print $1'}) |
| 37 | grep -q $s /system/addon.d/blacklist && rm -f $f |
| 38 | done |
| 39 | fi |
| 40 | } |
| 41 | |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 42 | # Execute /system/addon.d/*.sh scripts with $1 parameter |
| 43 | run_stage() { |
| 44 | for script in $(find /tmp/addon.d/ -name '*.sh' |sort -n); do |
| 45 | $script $1 |
| 46 | done |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 47 | } |
| 48 | |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 49 | case "$1" in |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 50 | backup) |
| 51 | mkdir -p $C |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 52 | check_prereq |
Ricardo Cerqueira | 129989b | 2012-12-19 01:11:21 +0000 | [diff] [blame] | 53 | check_blacklist system |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 54 | preserve_addon_d |
| 55 | run_stage pre-backup |
| 56 | run_stage backup |
| 57 | run_stage post-backup |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 58 | ;; |
| 59 | restore) |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 60 | check_prereq |
Ricardo Cerqueira | 129989b | 2012-12-19 01:11:21 +0000 | [diff] [blame] | 61 | check_blacklist tmp |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 62 | run_stage pre-restore |
| 63 | run_stage restore |
| 64 | run_stage post-restore |
| 65 | restore_addon_d |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 66 | rm -rf $C |
| 67 | sync |
| 68 | ;; |
| 69 | *) |
| 70 | echo "Usage: $0 {backup|restore}" |
| 71 | exit 1 |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 72 | esac |
| 73 | |
| 74 | exit 0 |