2010-06-25 03:36:11 +00:00
|
|
|
#!/sbin/sh
|
|
|
|
#
|
2012-03-04 08:37:42 +00:00
|
|
|
# Backup and restore addon /system files
|
2010-06-25 03:36:11 +00:00
|
|
|
#
|
|
|
|
|
2012-03-04 08:37:42 +00:00
|
|
|
export C=/tmp/backupdir
|
|
|
|
export S=/system
|
2014-11-05 18:22:50 +00:00
|
|
|
export V=12
|
2010-06-25 03:36:11 +00:00
|
|
|
|
2014-12-12 19:56:04 +00:00
|
|
|
# Scripts in /system/addon.d expect to find backuptool.functions in /tmp
|
|
|
|
cp -f /tmp/install/bin/backuptool.functions /tmp
|
|
|
|
|
2012-03-04 08:37:42 +00:00
|
|
|
# Preserve /system/addon.d in /tmp/addon.d
|
|
|
|
preserve_addon_d() {
|
|
|
|
mkdir -p /tmp/addon.d/
|
|
|
|
cp -a /system/addon.d/* /tmp/addon.d/
|
|
|
|
chmod 755 /tmp/addon.d/*.sh
|
2010-06-25 03:36:11 +00:00
|
|
|
}
|
|
|
|
|
2012-03-04 08:37:42 +00:00
|
|
|
# Restore /system/addon.d in /tmp/addon.d
|
|
|
|
restore_addon_d() {
|
|
|
|
cp -a /tmp/addon.d/* /system/addon.d/
|
|
|
|
rm -rf /tmp/addon.d/
|
2010-08-14 21:46:34 +00:00
|
|
|
}
|
|
|
|
|
2012-12-13 14:06:37 +00:00
|
|
|
# Proceed only if /system is the expected major and minor version
|
2012-03-04 08:37:42 +00:00
|
|
|
check_prereq() {
|
|
|
|
if ( ! grep -q "^ro.cm.version=$V.*" /system/build.prop ); then
|
2012-12-13 14:06:37 +00:00
|
|
|
echo "Not backing up files from incompatible version: $V"
|
2013-08-19 03:00:05 +00:00
|
|
|
return 0
|
2012-03-04 08:37:42 +00:00
|
|
|
fi
|
2013-08-19 03:00:05 +00:00
|
|
|
return 1
|
2010-06-25 03:36:11 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 01:11:21 +00:00
|
|
|
check_blacklist() {
|
|
|
|
if [ -f /system/addon.d/blacklist ];then
|
|
|
|
## Discard any known bad backup scripts
|
|
|
|
cd /$1/addon.d/
|
|
|
|
for f in *sh; do
|
|
|
|
s=$(md5sum $f | awk {'print $1'})
|
|
|
|
grep -q $s /system/addon.d/blacklist && rm -f $f
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-08-19 03:00:05 +00:00
|
|
|
check_whitelist() {
|
|
|
|
found=0
|
|
|
|
if [ -f /system/addon.d/whitelist ];then
|
|
|
|
## forcefully keep any version-independent stuff
|
|
|
|
cd /$1/addon.d/
|
|
|
|
for f in *sh; do
|
|
|
|
s=$(md5sum $f | awk {'print $1'})
|
|
|
|
grep -q $s /system/addon.d/whitelist
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
found=1
|
|
|
|
else
|
|
|
|
rm -f $f
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
return $found
|
|
|
|
}
|
|
|
|
|
2012-03-04 08:37:42 +00:00
|
|
|
# Execute /system/addon.d/*.sh scripts with $1 parameter
|
|
|
|
run_stage() {
|
|
|
|
for script in $(find /tmp/addon.d/ -name '*.sh' |sort -n); do
|
|
|
|
$script $1
|
|
|
|
done
|
2010-06-25 03:36:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
2012-03-04 08:37:42 +00:00
|
|
|
backup)
|
|
|
|
mkdir -p $C
|
2013-08-19 03:00:05 +00:00
|
|
|
if check_prereq; then
|
|
|
|
if check_whitelist system; then
|
|
|
|
exit 127
|
|
|
|
fi
|
|
|
|
fi
|
2012-12-19 01:11:21 +00:00
|
|
|
check_blacklist system
|
2012-03-04 08:37:42 +00:00
|
|
|
preserve_addon_d
|
|
|
|
run_stage pre-backup
|
|
|
|
run_stage backup
|
|
|
|
run_stage post-backup
|
|
|
|
;;
|
|
|
|
restore)
|
2013-08-19 03:00:05 +00:00
|
|
|
if check_prereq; then
|
|
|
|
if check_whitelist tmp; then
|
|
|
|
exit 127
|
|
|
|
fi
|
|
|
|
fi
|
2012-12-19 01:11:21 +00:00
|
|
|
check_blacklist tmp
|
2012-03-04 08:37:42 +00:00
|
|
|
run_stage pre-restore
|
|
|
|
run_stage restore
|
|
|
|
run_stage post-restore
|
|
|
|
restore_addon_d
|
|
|
|
rm -rf $C
|
|
|
|
sync
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage: $0 {backup|restore}"
|
|
|
|
exit 1
|
2010-06-25 03:36:11 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|