blob: 6ba1323d8d89b3b62e251deb3c86ea31e6e968aa [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
Ricardo Cerqueira6edfe232012-07-15 16:49:52 +01008export V=10
kmobse051cf32010-06-24 22:36:11 -05009
Warren Togamib1637c82012-03-03 22:37:42 -100010# Preserve /system/addon.d in /tmp/addon.d
11preserve_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
18restore_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
kmobse051cf32010-06-24 22:36:11 -050024check_prereq() {
Warren Togamib1637c82012-03-03 22:37:42 -100025if ( ! grep -q "^ro.cm.version=$V.*" /system/build.prop ); then
26 echo "Not backing up files from incompatible version."
Warren Togamib1637c82012-03-03 22:37:42 -100027 exit 127
28fi
kmobse051cf32010-06-24 22:36:11 -050029}
30
Warren Togamib1637c82012-03-03 22:37:42 -100031# Execute /system/addon.d/*.sh scripts with $1 parameter
32run_stage() {
33for script in $(find /tmp/addon.d/ -name '*.sh' |sort -n); do
34 $script $1
35done
kmobse051cf32010-06-24 22:36:11 -050036}
37
kmobse051cf32010-06-24 22:36:11 -050038case "$1" in
Warren Togamib1637c82012-03-03 22:37:42 -100039 backup)
40 mkdir -p $C
Warren Togamib1637c82012-03-03 22:37:42 -100041 check_prereq
42 preserve_addon_d
43 run_stage pre-backup
44 run_stage backup
45 run_stage post-backup
Warren Togamib1637c82012-03-03 22:37:42 -100046 ;;
47 restore)
Warren Togamib1637c82012-03-03 22:37:42 -100048 check_prereq
49 run_stage pre-restore
50 run_stage restore
51 run_stage post-restore
52 restore_addon_d
Warren Togamib1637c82012-03-03 22:37:42 -100053 rm -rf $C
54 sync
55 ;;
56 *)
57 echo "Usage: $0 {backup|restore}"
58 exit 1
kmobse051cf32010-06-24 22:36:11 -050059esac
60
61exit 0