blob: fd62159f1a1fbc4ec1a8cf2f3ae7c3c9839a3001 [file] [log] [blame]
kmobse051cf32010-06-24 22:36:11 -05001#!/sbin/sh
2#
Warren Togamib1637c82012-03-03 22:37:42 -10003# Backup and restore addon /system files
kmobse051cf32010-06-24 22:36:11 -05004#
5
Warren Togamib1637c82012-03-03 22:37:42 -10006export C=/tmp/backupdir
7export S=/system
8export V=9
kmobse051cf32010-06-24 22:36:11 -05009
Warren Togamib1637c82012-03-03 22:37:42 -100010# Mount /system if it is not already mounted
11mount_system() {
12if [ ! -f "$S/build.prop" ]; then
13 mount $S
14fi
15}
kmobse051cf32010-06-24 22:36:11 -050016
Warren Togamib1637c82012-03-03 22:37:42 -100017# Unmount /system unless it is already unmounted
18umount_system() {
19if [ -f "$S/build.prop" ]; then
20 umount $S
21fi
22}
23
24# Preserve /system/addon.d in /tmp/addon.d
25preserve_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
32restore_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
kmobse051cf32010-06-24 22:36:11 -050038check_prereq() {
Warren Togamib1637c82012-03-03 22:37:42 -100039if ( ! 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
43fi
kmobse051cf32010-06-24 22:36:11 -050044}
45
Warren Togamib1637c82012-03-03 22:37:42 -100046# Execute /system/addon.d/*.sh scripts with $1 parameter
47run_stage() {
48for script in $(find /tmp/addon.d/ -name '*.sh' |sort -n); do
49 $script $1
50done
kmobse051cf32010-06-24 22:36:11 -050051}
52
kmobse051cf32010-06-24 22:36:11 -050053case "$1" in
Warren Togamib1637c82012-03-03 22:37:42 -100054 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
kmobse051cf32010-06-24 22:36:11 -050078esac
79
80exit 0