You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.2 KiB

#!/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
12 years ago
# Backup and restore addon /system files
#
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
12 years ago
export C=/tmp/backupdir
export SYSDEV="$(readlink -nf "$2")"
export SYSFS="$3"
export V=18.0
# 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
12 years ago
# Preserve /system/addon.d in /tmp/addon.d
preserve_addon_d() {
if [ -d $S/addon.d/ ]; then
mkdir -p /tmp/addon.d/
cp -a $S/addon.d/* /tmp/addon.d/
chmod 755 /tmp/addon.d/*.sh
fi
}
# 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
12 years ago
restore_addon_d() {
if [ -d /tmp/addon.d/ ]; then
mkdir -p $S/addon.d/
cp -a /tmp/addon.d/* $S/addon.d/
rm -rf /tmp/addon.d/
fi
}
# 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
12 years ago
check_prereq() {
# If there is no build.prop file the partition is probably empty.
if [ ! -r $S/build.prop ]; then
echo "Backup/restore is not possible. Partition is probably empty"
return 1
fi
if ! grep -q "^ro.lineage.version=$V.*" $S/build.prop; then
echo "Backup/restore is not possible. Incompatible ROM version: $V"
return 2
fi
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
12 years ago
# 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
}
determine_system_mount() {
if grep -q -e"^$SYSDEV" /proc/mounts; then
umount $(grep -e"^$SYSDEV" /proc/mounts | cut -d" " -f2)
fi
if [ -d /mnt/system ]; then
SYSMOUNT="/mnt/system"
elif [ -d /system_root ]; then
SYSMOUNT="/system_root"
else
SYSMOUNT="/system"
fi
export S=$SYSMOUNT/system
}
mount_system() {
mount -t $SYSFS $SYSDEV $SYSMOUNT -o rw,discard
}
unmount_system() {
umount $SYSMOUNT
}
determine_system_mount
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
12 years ago
backup)
mount_system
if check_prereq; then
mkdir -p $C
preserve_addon_d
run_stage pre-backup
run_stage backup
run_stage post-backup
fi
unmount_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
12 years ago
;;
restore)
mount_system
if check_prereq; then
run_stage pre-restore
run_stage restore
run_stage post-restore
restore_addon_d
rm -rf $C
sync
fi
unmount_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
12 years ago
;;
*)
echo "Usage: $0 {backup|restore}"
exit 1
esac
exit 0