Files
vendor_strix/prebuilt/common/bin/backuptool.sh
Adrian DC 9dde3d63e8 backuptool: Temporarily render version check permissive
* Due to both following commits, backuptool went permissive
    and lineage properties got lost from the system on devices
    that do not have BOARD_PROPERTY_OVERRIDES_SPLIT_ENABLED

    "backuptool: Take into account new location for system default props"
    Change-Id: I62046447876c2198a0c4f88a4f36f4723d417617

    "lineage: Move to Google's method of defining system default props"
    Change-Id: I6cb0e28a7599b010b389cc541015a37010a00f4b

 * Once the properties issue is properly resolved in the sources,
    a period of time is required for "most" of the users to upgrade
    their system with fixed lineage properties before we break addons
    by repairing the backuptool script globally

Change-Id: Iea8865ea9bb05eed56a8a0a7b95e3f04b01c4bae
2018-05-18 22:04:29 +02:00

117 lines
2.5 KiB
Bash
Executable File

#!/sbin/sh
#
# Backup and restore addon /system files
#
export C=/tmp/backupdir
export S=/system
export V=15.1
# Scripts in /system/addon.d expect to find backuptool.functions in /tmp
cp -f /tmp/install/bin/backuptool.functions /tmp
# 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
}
# Restore /system/addon.d from /tmp/addon.d
restore_addon_d() {
if [ -d /tmp/addon.d/ ]; then
mkdir -p /system/addon.d/
cp -a /tmp/addon.d/* /system/addon.d/
rm -rf /tmp/addon.d/
fi
}
# Proceed only if /system is the expected major and minor version
check_prereq() {
# If there is no build.prop file the partition is probably empty.
if [ ! -r /system/build.prop ]; then
return 0
fi
# if [ ! grep -q "^ro.lineage.version=$V.*" /system/etc/prop.default /system/build.prop ]; then
# echo "Not backing up files from incompatible version: $V"
# return 0
# fi
return 1
}
check_blacklist() {
if [ -f /system/addon.d/blacklist -a -d /$1/addon.d/ ]; then
## Discard any known bad backup scripts
cd /$1/addon.d/
for f in *sh; do
[ -f $f ] || continue
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
}
# 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
}
case "$1" in
backup)
mkdir -p $C
if check_prereq; then
if check_whitelist system; then
exit 127
fi
fi
check_blacklist system
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
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
esac
exit 0