replicant-vendor_replicant/prebuilt/common/bin/backuptool.sh

115 lines
2.4 KiB
Bash
Raw Normal View History

2010-06-25 03:36:11 +00:00
#!/sbin/sh
#
Modular backuptool.sh. Executes backup and restore methods defined in arbitrary /system/addon.d/*.sh scripts. Tips & Tricks ============= * 50-cm.sh contains only a reference implementation. You may customize the methods however you wish. For example, 20-foobar.sh pre-backup can use a loop with conditionals to generate a dynamic backup list in /tmp/foobar_file_list which is later printed by list_files() so the backup method will act on those files. * Optional methods pre-backup, post-backup, pre-restore, or post-restore may be defined for special purposes. * Inject new files into /tmp/addon.d/ prior to backuptool.sh backup if you want to act during the current CM upgrade. * Delete files from /tmp/addon.d/ during post-restore if you want to permanently remove files from /system/addon.d/ Addons may use this approach to run a script only once. * Scripts run in sort -n order. Prefix with numbers 00 through 99 if want to run in a particular order. * You can have two separate scripts, implementing only backup in one, and only restore in the other with a different number prefix of each. This allows even greater control the backup/restore order even further. * You could use pre-backup to generate a one-time use backup script in /tmp/addon.d/ that deletes itself in post-restore. Patch Series ============ http://review.cyanogenmod.com/#change,13265 CyanogenMod/android_build * edify generator http://review.cyanogenmod.com/#change,13266 CyanogenMod/android_system_core * permissions on /system/addon.d http://review.cyanogenmod.com/#change,13267 CyanogenMod/android_vendor_cm * 50-cm.sh reference backup script * modular backuptool.sh * support backuptool.functions used by /system/addon.d/*.sh scripts Change-Id: Ifd5eaf9dcfd68d92e5043c21d1bae1dc0ad54860
2012-03-04 08:37:42 +00:00
# Backup and restore addon /system files
2010-06-25 03:36:11 +00:00
#
Modular backuptool.sh. Executes backup and restore methods defined in arbitrary /system/addon.d/*.sh scripts. Tips & Tricks ============= * 50-cm.sh contains only a reference implementation. You may customize the methods however you wish. For example, 20-foobar.sh pre-backup can use a loop with conditionals to generate a dynamic backup list in /tmp/foobar_file_list which is later printed by list_files() so the backup method will act on those files. * Optional methods pre-backup, post-backup, pre-restore, or post-restore may be defined for special purposes. * Inject new files into /tmp/addon.d/ prior to backuptool.sh backup if you want to act during the current CM upgrade. * Delete files from /tmp/addon.d/ during post-restore if you want to permanently remove files from /system/addon.d/ Addons may use this approach to run a script only once. * Scripts run in sort -n order. Prefix with numbers 00 through 99 if want to run in a particular order. * You can have two separate scripts, implementing only backup in one, and only restore in the other with a different number prefix of each. This allows even greater control the backup/restore order even further. * You could use pre-backup to generate a one-time use backup script in /tmp/addon.d/ that deletes itself in post-restore. Patch Series ============ http://review.cyanogenmod.com/#change,13265 CyanogenMod/android_build * edify generator http://review.cyanogenmod.com/#change,13266 CyanogenMod/android_system_core * permissions on /system/addon.d http://review.cyanogenmod.com/#change,13267 CyanogenMod/android_vendor_cm * 50-cm.sh reference backup script * modular backuptool.sh * support backuptool.functions used by /system/addon.d/*.sh scripts Change-Id: Ifd5eaf9dcfd68d92e5043c21d1bae1dc0ad54860
2012-03-04 08:37:42 +00:00
export C=/tmp/backupdir
export S=/system
export V=13.0
2010-06-25 03:36:11 +00:00
# Scripts in /system/addon.d expect to find backuptool.functions in /tmp
cp -f /tmp/install/bin/backuptool.functions /tmp
Modular backuptool.sh. Executes backup and restore methods defined in arbitrary /system/addon.d/*.sh scripts. Tips & Tricks ============= * 50-cm.sh contains only a reference implementation. You may customize the methods however you wish. For example, 20-foobar.sh pre-backup can use a loop with conditionals to generate a dynamic backup list in /tmp/foobar_file_list which is later printed by list_files() so the backup method will act on those files. * Optional methods pre-backup, post-backup, pre-restore, or post-restore may be defined for special purposes. * Inject new files into /tmp/addon.d/ prior to backuptool.sh backup if you want to act during the current CM upgrade. * Delete files from /tmp/addon.d/ during post-restore if you want to permanently remove files from /system/addon.d/ Addons may use this approach to run a script only once. * Scripts run in sort -n order. Prefix with numbers 00 through 99 if want to run in a particular order. * You can have two separate scripts, implementing only backup in one, and only restore in the other with a different number prefix of each. This allows even greater control the backup/restore order even further. * You could use pre-backup to generate a one-time use backup script in /tmp/addon.d/ that deletes itself in post-restore. Patch Series ============ http://review.cyanogenmod.com/#change,13265 CyanogenMod/android_build * edify generator http://review.cyanogenmod.com/#change,13266 CyanogenMod/android_system_core * permissions on /system/addon.d http://review.cyanogenmod.com/#change,13267 CyanogenMod/android_vendor_cm * 50-cm.sh reference backup script * modular backuptool.sh * support backuptool.functions used by /system/addon.d/*.sh scripts Change-Id: Ifd5eaf9dcfd68d92e5043c21d1bae1dc0ad54860
2012-03-04 08:37:42 +00:00
# Preserve /system/addon.d in /tmp/addon.d
preserve_addon_d() {
if [ -d /system/addon.d/ ]; then
mkdir -p /tmp/addon.d/
cp -a /system/addon.d/* /tmp/addon.d/
chmod 755 /tmp/addon.d/*.sh
fi
2010-06-25 03:36:11 +00:00
}
# Restore /system/addon.d from /tmp/addon.d
Modular backuptool.sh. Executes backup and restore methods defined in arbitrary /system/addon.d/*.sh scripts. Tips & Tricks ============= * 50-cm.sh contains only a reference implementation. You may customize the methods however you wish. For example, 20-foobar.sh pre-backup can use a loop with conditionals to generate a dynamic backup list in /tmp/foobar_file_list which is later printed by list_files() so the backup method will act on those files. * Optional methods pre-backup, post-backup, pre-restore, or post-restore may be defined for special purposes. * Inject new files into /tmp/addon.d/ prior to backuptool.sh backup if you want to act during the current CM upgrade. * Delete files from /tmp/addon.d/ during post-restore if you want to permanently remove files from /system/addon.d/ Addons may use this approach to run a script only once. * Scripts run in sort -n order. Prefix with numbers 00 through 99 if want to run in a particular order. * You can have two separate scripts, implementing only backup in one, and only restore in the other with a different number prefix of each. This allows even greater control the backup/restore order even further. * You could use pre-backup to generate a one-time use backup script in /tmp/addon.d/ that deletes itself in post-restore. Patch Series ============ http://review.cyanogenmod.com/#change,13265 CyanogenMod/android_build * edify generator http://review.cyanogenmod.com/#change,13266 CyanogenMod/android_system_core * permissions on /system/addon.d http://review.cyanogenmod.com/#change,13267 CyanogenMod/android_vendor_cm * 50-cm.sh reference backup script * modular backuptool.sh * support backuptool.functions used by /system/addon.d/*.sh scripts Change-Id: Ifd5eaf9dcfd68d92e5043c21d1bae1dc0ad54860
2012-03-04 08:37:42 +00:00
restore_addon_d() {
if [ -d /tmp/addon.d/ ]; then
cp -a /tmp/addon.d/* /system/addon.d/
rm -rf /tmp/addon.d/
fi
2010-08-14 21:46:34 +00:00
}
# Proceed only if /system is the expected major and minor version
Modular backuptool.sh. Executes backup and restore methods defined in arbitrary /system/addon.d/*.sh scripts. Tips & Tricks ============= * 50-cm.sh contains only a reference implementation. You may customize the methods however you wish. For example, 20-foobar.sh pre-backup can use a loop with conditionals to generate a dynamic backup list in /tmp/foobar_file_list which is later printed by list_files() so the backup method will act on those files. * Optional methods pre-backup, post-backup, pre-restore, or post-restore may be defined for special purposes. * Inject new files into /tmp/addon.d/ prior to backuptool.sh backup if you want to act during the current CM upgrade. * Delete files from /tmp/addon.d/ during post-restore if you want to permanently remove files from /system/addon.d/ Addons may use this approach to run a script only once. * Scripts run in sort -n order. Prefix with numbers 00 through 99 if want to run in a particular order. * You can have two separate scripts, implementing only backup in one, and only restore in the other with a different number prefix of each. This allows even greater control the backup/restore order even further. * You could use pre-backup to generate a one-time use backup script in /tmp/addon.d/ that deletes itself in post-restore. Patch Series ============ http://review.cyanogenmod.com/#change,13265 CyanogenMod/android_build * edify generator http://review.cyanogenmod.com/#change,13266 CyanogenMod/android_system_core * permissions on /system/addon.d http://review.cyanogenmod.com/#change,13267 CyanogenMod/android_vendor_cm * 50-cm.sh reference backup script * modular backuptool.sh * support backuptool.functions used by /system/addon.d/*.sh scripts Change-Id: Ifd5eaf9dcfd68d92e5043c21d1bae1dc0ad54860
2012-03-04 08:37:42 +00:00
check_prereq() {
# If there is no build.prop file the partition is probably empty.
if [ ! -r /system/build.prop ]; then
return 0
fi
Modular backuptool.sh. Executes backup and restore methods defined in arbitrary /system/addon.d/*.sh scripts. Tips & Tricks ============= * 50-cm.sh contains only a reference implementation. You may customize the methods however you wish. For example, 20-foobar.sh pre-backup can use a loop with conditionals to generate a dynamic backup list in /tmp/foobar_file_list which is later printed by list_files() so the backup method will act on those files. * Optional methods pre-backup, post-backup, pre-restore, or post-restore may be defined for special purposes. * Inject new files into /tmp/addon.d/ prior to backuptool.sh backup if you want to act during the current CM upgrade. * Delete files from /tmp/addon.d/ during post-restore if you want to permanently remove files from /system/addon.d/ Addons may use this approach to run a script only once. * Scripts run in sort -n order. Prefix with numbers 00 through 99 if want to run in a particular order. * You can have two separate scripts, implementing only backup in one, and only restore in the other with a different number prefix of each. This allows even greater control the backup/restore order even further. * You could use pre-backup to generate a one-time use backup script in /tmp/addon.d/ that deletes itself in post-restore. Patch Series ============ http://review.cyanogenmod.com/#change,13265 CyanogenMod/android_build * edify generator http://review.cyanogenmod.com/#change,13266 CyanogenMod/android_system_core * permissions on /system/addon.d http://review.cyanogenmod.com/#change,13267 CyanogenMod/android_vendor_cm * 50-cm.sh reference backup script * modular backuptool.sh * support backuptool.functions used by /system/addon.d/*.sh scripts Change-Id: Ifd5eaf9dcfd68d92e5043c21d1bae1dc0ad54860
2012-03-04 08:37:42 +00:00
if ( ! grep -q "^ro.cm.version=$V.*" /system/build.prop ); then
echo "Not backing up files from incompatible version: $V"
return 0
Modular backuptool.sh. Executes backup and restore methods defined in arbitrary /system/addon.d/*.sh scripts. Tips & Tricks ============= * 50-cm.sh contains only a reference implementation. You may customize the methods however you wish. For example, 20-foobar.sh pre-backup can use a loop with conditionals to generate a dynamic backup list in /tmp/foobar_file_list which is later printed by list_files() so the backup method will act on those files. * Optional methods pre-backup, post-backup, pre-restore, or post-restore may be defined for special purposes. * Inject new files into /tmp/addon.d/ prior to backuptool.sh backup if you want to act during the current CM upgrade. * Delete files from /tmp/addon.d/ during post-restore if you want to permanently remove files from /system/addon.d/ Addons may use this approach to run a script only once. * Scripts run in sort -n order. Prefix with numbers 00 through 99 if want to run in a particular order. * You can have two separate scripts, implementing only backup in one, and only restore in the other with a different number prefix of each. This allows even greater control the backup/restore order even further. * You could use pre-backup to generate a one-time use backup script in /tmp/addon.d/ that deletes itself in post-restore. Patch Series ============ http://review.cyanogenmod.com/#change,13265 CyanogenMod/android_build * edify generator http://review.cyanogenmod.com/#change,13266 CyanogenMod/android_system_core * permissions on /system/addon.d http://review.cyanogenmod.com/#change,13267 CyanogenMod/android_vendor_cm * 50-cm.sh reference backup script * modular backuptool.sh * support backuptool.functions used by /system/addon.d/*.sh scripts Change-Id: Ifd5eaf9dcfd68d92e5043c21d1bae1dc0ad54860
2012-03-04 08:37:42 +00:00
fi
return 1
2010-06-25 03:36:11 +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 | cut -c-32)
grep -q $s /system/addon.d/blacklist && rm -f $f
done
fi
}
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 | cut -c-32)
grep -q $s /system/addon.d/whitelist
if [ $? -eq 0 ]; then
found=1
else
rm -f $f
fi
done
fi
return $found
}
Modular backuptool.sh. Executes backup and restore methods defined in arbitrary /system/addon.d/*.sh scripts. Tips & Tricks ============= * 50-cm.sh contains only a reference implementation. You may customize the methods however you wish. For example, 20-foobar.sh pre-backup can use a loop with conditionals to generate a dynamic backup list in /tmp/foobar_file_list which is later printed by list_files() so the backup method will act on those files. * Optional methods pre-backup, post-backup, pre-restore, or post-restore may be defined for special purposes. * Inject new files into /tmp/addon.d/ prior to backuptool.sh backup if you want to act during the current CM upgrade. * Delete files from /tmp/addon.d/ during post-restore if you want to permanently remove files from /system/addon.d/ Addons may use this approach to run a script only once. * Scripts run in sort -n order. Prefix with numbers 00 through 99 if want to run in a particular order. * You can have two separate scripts, implementing only backup in one, and only restore in the other with a different number prefix of each. This allows even greater control the backup/restore order even further. * You could use pre-backup to generate a one-time use backup script in /tmp/addon.d/ that deletes itself in post-restore. Patch Series ============ http://review.cyanogenmod.com/#change,13265 CyanogenMod/android_build * edify generator http://review.cyanogenmod.com/#change,13266 CyanogenMod/android_system_core * permissions on /system/addon.d http://review.cyanogenmod.com/#change,13267 CyanogenMod/android_vendor_cm * 50-cm.sh reference backup script * modular backuptool.sh * support backuptool.functions used by /system/addon.d/*.sh scripts Change-Id: Ifd5eaf9dcfd68d92e5043c21d1bae1dc0ad54860
2012-03-04 08:37:42 +00:00
# Execute /system/addon.d/*.sh scripts with $1 parameter
run_stage() {
if [ -d /tmp/addon.d/ ]; then
for script in $(find /tmp/addon.d/ -name '*.sh' |sort -n); do
$script $1
done
fi
2010-06-25 03:36:11 +00:00
}
case "$1" in
Modular backuptool.sh. Executes backup and restore methods defined in arbitrary /system/addon.d/*.sh scripts. Tips & Tricks ============= * 50-cm.sh contains only a reference implementation. You may customize the methods however you wish. For example, 20-foobar.sh pre-backup can use a loop with conditionals to generate a dynamic backup list in /tmp/foobar_file_list which is later printed by list_files() so the backup method will act on those files. * Optional methods pre-backup, post-backup, pre-restore, or post-restore may be defined for special purposes. * Inject new files into /tmp/addon.d/ prior to backuptool.sh backup if you want to act during the current CM upgrade. * Delete files from /tmp/addon.d/ during post-restore if you want to permanently remove files from /system/addon.d/ Addons may use this approach to run a script only once. * Scripts run in sort -n order. Prefix with numbers 00 through 99 if want to run in a particular order. * You can have two separate scripts, implementing only backup in one, and only restore in the other with a different number prefix of each. This allows even greater control the backup/restore order even further. * You could use pre-backup to generate a one-time use backup script in /tmp/addon.d/ that deletes itself in post-restore. Patch Series ============ http://review.cyanogenmod.com/#change,13265 CyanogenMod/android_build * edify generator http://review.cyanogenmod.com/#change,13266 CyanogenMod/android_system_core * permissions on /system/addon.d http://review.cyanogenmod.com/#change,13267 CyanogenMod/android_vendor_cm * 50-cm.sh reference backup script * modular backuptool.sh * support backuptool.functions used by /system/addon.d/*.sh scripts Change-Id: Ifd5eaf9dcfd68d92e5043c21d1bae1dc0ad54860
2012-03-04 08:37:42 +00:00
backup)
mkdir -p $C
if check_prereq; then
if check_whitelist system; then
exit 127
fi
fi
check_blacklist system
Modular backuptool.sh. Executes backup and restore methods defined in arbitrary /system/addon.d/*.sh scripts. Tips & Tricks ============= * 50-cm.sh contains only a reference implementation. You may customize the methods however you wish. For example, 20-foobar.sh pre-backup can use a loop with conditionals to generate a dynamic backup list in /tmp/foobar_file_list which is later printed by list_files() so the backup method will act on those files. * Optional methods pre-backup, post-backup, pre-restore, or post-restore may be defined for special purposes. * Inject new files into /tmp/addon.d/ prior to backuptool.sh backup if you want to act during the current CM upgrade. * Delete files from /tmp/addon.d/ during post-restore if you want to permanently remove files from /system/addon.d/ Addons may use this approach to run a script only once. * Scripts run in sort -n order. Prefix with numbers 00 through 99 if want to run in a particular order. * You can have two separate scripts, implementing only backup in one, and only restore in the other with a different number prefix of each. This allows even greater control the backup/restore order even further. * You could use pre-backup to generate a one-time use backup script in /tmp/addon.d/ that deletes itself in post-restore. Patch Series ============ http://review.cyanogenmod.com/#change,13265 CyanogenMod/android_build * edify generator http://review.cyanogenmod.com/#change,13266 CyanogenMod/android_system_core * permissions on /system/addon.d http://review.cyanogenmod.com/#change,13267 CyanogenMod/android_vendor_cm * 50-cm.sh reference backup script * modular backuptool.sh * support backuptool.functions used by /system/addon.d/*.sh scripts Change-Id: Ifd5eaf9dcfd68d92e5043c21d1bae1dc0ad54860
2012-03-04 08:37:42 +00:00
preserve_addon_d
run_stage pre-backup
run_stage backup
run_stage post-backup
;;
restore)
if check_prereq; then
if check_whitelist tmp; then
exit 127
fi
fi
check_blacklist tmp
Modular backuptool.sh. Executes backup and restore methods defined in arbitrary /system/addon.d/*.sh scripts. Tips & Tricks ============= * 50-cm.sh contains only a reference implementation. You may customize the methods however you wish. For example, 20-foobar.sh pre-backup can use a loop with conditionals to generate a dynamic backup list in /tmp/foobar_file_list which is later printed by list_files() so the backup method will act on those files. * Optional methods pre-backup, post-backup, pre-restore, or post-restore may be defined for special purposes. * Inject new files into /tmp/addon.d/ prior to backuptool.sh backup if you want to act during the current CM upgrade. * Delete files from /tmp/addon.d/ during post-restore if you want to permanently remove files from /system/addon.d/ Addons may use this approach to run a script only once. * Scripts run in sort -n order. Prefix with numbers 00 through 99 if want to run in a particular order. * You can have two separate scripts, implementing only backup in one, and only restore in the other with a different number prefix of each. This allows even greater control the backup/restore order even further. * You could use pre-backup to generate a one-time use backup script in /tmp/addon.d/ that deletes itself in post-restore. Patch Series ============ http://review.cyanogenmod.com/#change,13265 CyanogenMod/android_build * edify generator http://review.cyanogenmod.com/#change,13266 CyanogenMod/android_system_core * permissions on /system/addon.d http://review.cyanogenmod.com/#change,13267 CyanogenMod/android_vendor_cm * 50-cm.sh reference backup script * modular backuptool.sh * support backuptool.functions used by /system/addon.d/*.sh scripts Change-Id: Ifd5eaf9dcfd68d92e5043c21d1bae1dc0ad54860
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