blob: dd71112f23433f6c26afb68c96a7e2f2fc9d2f22 [file] [log] [blame]
Andrew Dodd0c209012013-09-28 15:34:25 -04001#!/sbin/sh
2#
3# Backup and restore addon /system files
4#
5
6export C=/tmp/backupdir
7export S=/system
maxwen61560962017-08-23 20:41:54 +02008export V=8.0
Andrew Dodd0c209012013-09-28 15:34:25 -04009
Marko Man2d218732017-09-12 02:24:39 +020010DEBUG=0
11
Andrew Dodd0c209012013-09-28 15:34:25 -040012# Preserve /system/addon.d in /tmp/addon.d
13preserve_addon_d() {
14 mkdir -p /tmp/addon.d/
15 cp -a /system/addon.d/* /tmp/addon.d/
16 chmod 755 /tmp/addon.d/*.sh
17}
18
19# Restore /system/addon.d in /tmp/addon.d
20restore_addon_d() {
21 cp -a /tmp/addon.d/* /system/addon.d/
22 rm -rf /tmp/addon.d/
23}
24
25# Proceed only if /system is the expected major and minor version
26check_prereq() {
27if ( ! grep -q "^ro.build.version.release=$V.*" /system/build.prop ); then
28 echo "Not backing up files from incompatible version: $V"
29 exit 127
30fi
31}
32
33check_blacklist() {
34 if [ -f /system/addon.d/blacklist ];then
35 ## Discard any known bad backup scripts
36 cd /$1/addon.d/
37 for f in *sh; do
38 s=$(md5sum $f | awk {'print $1'})
39 grep -q $s /system/addon.d/blacklist && rm -f $f
40 done
41 fi
42}
43
44# Execute /system/addon.d/*.sh scripts with $1 parameter
45run_stage() {
46for script in $(find /tmp/addon.d/ -name '*.sh' |sort -n); do
Marko Man2d218732017-09-12 02:24:39 +020047 if [ $DEBUG -eq 1 ]; then
48 echo run_stage $script $1
49 fi
Andrew Dodd0c209012013-09-28 15:34:25 -040050 $script $1
51done
52}
53
54case "$1" in
55 backup)
Marko Man2d218732017-09-12 02:24:39 +020056 cp /system/bin/backuptool.functions /tmp
Andrew Dodd0c209012013-09-28 15:34:25 -040057 mkdir -p $C
58 check_prereq
59 check_blacklist system
60 preserve_addon_d
61 run_stage pre-backup
62 run_stage backup
63 run_stage post-backup
64 ;;
65 restore)
Marko Man2d218732017-09-12 02:24:39 +020066 cp /system/bin/backuptool.functions /tmp
Andrew Dodd0c209012013-09-28 15:34:25 -040067 check_prereq
68 check_blacklist tmp
69 run_stage pre-restore
70 run_stage restore
71 run_stage post-restore
72 restore_addon_d
73 rm -rf $C
74 sync
75 ;;
76 *)
77 echo "Usage: $0 {backup|restore}"
78 exit 1
79esac
80
81exit 0