replicant-vendor_replicant/prebuilt/common/bin/backuptool.sh
Warren Togami b1637c8e2b 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-08 20:40:36 -10:00

81 lines
1.4 KiB
Bash
Executable File

#!/sbin/sh
#
# Backup and restore addon /system files
#
export C=/tmp/backupdir
export S=/system
export V=9
# Mount /system if it is not already mounted
mount_system() {
if [ ! -f "$S/build.prop" ]; then
mount $S
fi
}
# Unmount /system unless it is already unmounted
umount_system() {
if [ -f "$S/build.prop" ]; then
umount $S
fi
}
# 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
}
# Restore /system/addon.d in /tmp/addon.d
restore_addon_d() {
cp -a /tmp/addon.d/* /system/addon.d/
rm -rf /tmp/addon.d/
}
# Proceed only if /system is the expected major version
check_prereq() {
if ( ! grep -q "^ro.cm.version=$V.*" /system/build.prop ); then
echo "Not backing up files from incompatible version."
umount_system
exit 127
fi
}
# 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
}
case "$1" in
backup)
mkdir -p $C
mount_system
check_prereq
preserve_addon_d
run_stage pre-backup
run_stage backup
run_stage post-backup
umount_system
;;
restore)
mount_system
check_prereq
run_stage pre-restore
run_stage restore
run_stage post-restore
restore_addon_d
umount_system
rm -rf $C
sync
;;
*)
echo "Usage: $0 {backup|restore}"
exit 1
esac
exit 0