blob: c576be38897b33362d88da864d14d3ed0a86cd6e [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
Chirayu Desai700fc8f2012-12-13 19:36:37 +05308export V=10.1
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
Chirayu Desai700fc8f2012-12-13 19:36:37 +053023# Proceed only if /system is the expected major and minor 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
Chirayu Desai700fc8f2012-12-13 19:36:37 +053026 echo "Not backing up files from incompatible version: $V"
Warren Togamib1637c82012-03-03 22:37:42 -100027 exit 127
28fi
kmobse051cf32010-06-24 22:36:11 -050029}
30
Ricardo Cerqueira129989b2012-12-19 01:11:21 +000031check_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 Togamib1637c82012-03-03 22:37:42 -100042# Execute /system/addon.d/*.sh scripts with $1 parameter
43run_stage() {
44for script in $(find /tmp/addon.d/ -name '*.sh' |sort -n); do
45 $script $1
46done
kmobse051cf32010-06-24 22:36:11 -050047}
48
kmobse051cf32010-06-24 22:36:11 -050049case "$1" in
Warren Togamib1637c82012-03-03 22:37:42 -100050 backup)
51 mkdir -p $C
Warren Togamib1637c82012-03-03 22:37:42 -100052 check_prereq
Ricardo Cerqueira129989b2012-12-19 01:11:21 +000053 check_blacklist system
Warren Togamib1637c82012-03-03 22:37:42 -100054 preserve_addon_d
55 run_stage pre-backup
56 run_stage backup
57 run_stage post-backup
Warren Togamib1637c82012-03-03 22:37:42 -100058 ;;
59 restore)
Warren Togamib1637c82012-03-03 22:37:42 -100060 check_prereq
Ricardo Cerqueira129989b2012-12-19 01:11:21 +000061 check_blacklist tmp
Warren Togamib1637c82012-03-03 22:37:42 -100062 run_stage pre-restore
63 run_stage restore
64 run_stage post-restore
65 restore_addon_d
Warren Togamib1637c82012-03-03 22:37:42 -100066 rm -rf $C
67 sync
68 ;;
69 *)
70 echo "Usage: $0 {backup|restore}"
71 exit 1
kmobse051cf32010-06-24 22:36:11 -050072esac
73
74exit 0