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 | 6edfe23 | 2012-07-15 16:49:52 +0100 | [diff] [blame] | 8 | export V=10 |
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 | |
| 23 | # Proceed only if /system is the expected major 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 |
| 26 | echo "Not backing up files from incompatible version." |
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 | |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 31 | # Execute /system/addon.d/*.sh scripts with $1 parameter |
| 32 | run_stage() { |
| 33 | for script in $(find /tmp/addon.d/ -name '*.sh' |sort -n); do |
| 34 | $script $1 |
| 35 | done |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 36 | } |
| 37 | |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 38 | case "$1" in |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 39 | backup) |
| 40 | mkdir -p $C |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 41 | check_prereq |
| 42 | preserve_addon_d |
| 43 | run_stage pre-backup |
| 44 | run_stage backup |
| 45 | run_stage post-backup |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 46 | ;; |
| 47 | restore) |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 48 | check_prereq |
| 49 | run_stage pre-restore |
| 50 | run_stage restore |
| 51 | run_stage post-restore |
| 52 | restore_addon_d |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 53 | rm -rf $C |
| 54 | sync |
| 55 | ;; |
| 56 | *) |
| 57 | echo "Usage: $0 {backup|restore}" |
| 58 | exit 1 |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 59 | esac |
| 60 | |
| 61 | exit 0 |