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 | # Mount /system if it is not already mounted |
| 11 | mount_system() { |
eyeballer | 018b5b6 | 2012-04-10 15:45:29 -0400 | [diff] [blame] | 12 | if ! mount | grep -q " $S " ; then |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 13 | mount $S |
| 14 | fi |
| 15 | } |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 16 | |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 17 | # Unmount /system unless it is already unmounted |
| 18 | umount_system() { |
eyeballer | 018b5b6 | 2012-04-10 15:45:29 -0400 | [diff] [blame] | 19 | if mount | grep -q " $S " ; then |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 20 | umount $S |
| 21 | fi |
| 22 | } |
| 23 | |
| 24 | # Preserve /system/addon.d in /tmp/addon.d |
| 25 | preserve_addon_d() { |
| 26 | mkdir -p /tmp/addon.d/ |
| 27 | cp -a /system/addon.d/* /tmp/addon.d/ |
| 28 | chmod 755 /tmp/addon.d/*.sh |
| 29 | } |
| 30 | |
| 31 | # Restore /system/addon.d in /tmp/addon.d |
| 32 | restore_addon_d() { |
| 33 | cp -a /tmp/addon.d/* /system/addon.d/ |
| 34 | rm -rf /tmp/addon.d/ |
| 35 | } |
| 36 | |
| 37 | # Proceed only if /system is the expected major version |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 38 | check_prereq() { |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 39 | if ( ! grep -q "^ro.cm.version=$V.*" /system/build.prop ); then |
| 40 | echo "Not backing up files from incompatible version." |
| 41 | umount_system |
| 42 | exit 127 |
| 43 | fi |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 44 | } |
| 45 | |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 46 | # Execute /system/addon.d/*.sh scripts with $1 parameter |
| 47 | run_stage() { |
| 48 | for script in $(find /tmp/addon.d/ -name '*.sh' |sort -n); do |
| 49 | $script $1 |
| 50 | done |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 51 | } |
| 52 | |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 53 | case "$1" in |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 54 | backup) |
| 55 | mkdir -p $C |
| 56 | mount_system |
| 57 | check_prereq |
| 58 | preserve_addon_d |
| 59 | run_stage pre-backup |
| 60 | run_stage backup |
| 61 | run_stage post-backup |
| 62 | umount_system |
| 63 | ;; |
| 64 | restore) |
| 65 | mount_system |
| 66 | check_prereq |
| 67 | run_stage pre-restore |
| 68 | run_stage restore |
| 69 | run_stage post-restore |
| 70 | restore_addon_d |
| 71 | umount_system |
| 72 | rm -rf $C |
| 73 | sync |
| 74 | ;; |
| 75 | *) |
| 76 | echo "Usage: $0 {backup|restore}" |
| 77 | exit 1 |
kmobs | e051cf3 | 2010-06-24 22:36:11 -0500 | [diff] [blame] | 78 | esac |
| 79 | |
| 80 | exit 0 |