For scripts declaring ADDOND_VERSION=3 automatically mount vendor, product, system_ext and others (when they're dedicated partitions). Also expose the get_output_path() function to get the path to where a file is mounted in case it lives in a dedicated partition. ab exapmles: get_output_path "system/product/priv-app/MyApp.apk" = "/postinstall/product/priv-app/MyApk.apk" get_output_path "system/app/MySystemApp.apk" = "/postinstall/system/app/MySystemApp.apk" a-only examples: get_output_path "/mnt/system/system/product/priv-app/MyApp.apk" = "/mnt/system/system/product/priv-app/MyApp.apk" ****************************************************************** Instead of cycling all scripts for each stage, run pre-backup -> backup -> post-backup in quick succession (and likewise for restore), to ensure backwards compatibility with scripts that wrongly assumed their environment not to change between steps. This is needed because we want to undo any mounting done for V3 scripts when executing V2 scripts. If a V2 script did mounting in pre-restore and expected things to still be mounted in restore, we would break their (yes incorrect) assumption. Change-Id: I73fbad6f45824fed99e4482128769435348588f5
74 lines
1.4 KiB
Bash
74 lines
1.4 KiB
Bash
#!/system/bin/sh
|
|
#
|
|
# Functions for backuptool_ab.sh
|
|
#
|
|
|
|
export S=/system
|
|
export C=/postinstall/tmp/backupdir
|
|
export V=18.1
|
|
export backuptool_ab=true
|
|
|
|
copy_file() {
|
|
old=`umask`
|
|
umask 0322
|
|
mkdir -m755 -p `dirname $2`
|
|
umask "$old"
|
|
|
|
cp -dp --preserve=a "$1" "$2"
|
|
}
|
|
|
|
move_file() {
|
|
old=`umask`
|
|
umask 0322
|
|
mkdir -m755 -p `dirname $2`
|
|
umask "$old"
|
|
|
|
mv "$1" "$2"
|
|
}
|
|
|
|
backup_file() {
|
|
if [ -e "$1" -o -L "$1" ]; then
|
|
# dont backup any apps that have odex files, they are useless
|
|
if ( echo "$1" | grep -q "\.apk$" ) && [ -e `echo "$1" | sed -e 's/\.apk$/\.odex/'` ]; then
|
|
echo "Skipping odexed apk $1";
|
|
else
|
|
copy_file "$1" "$C/$1"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
restore_file() {
|
|
if [ -e "$C/$1" -o -L "$C/$1" ]; then
|
|
move_file "$C/$1" $(get_output_path "$1");
|
|
if [ -n "$2" ]; then
|
|
echo "Deleting obsolete file $2"
|
|
rm $(get_output_path "$2");
|
|
fi
|
|
fi
|
|
}
|
|
|
|
get_output_path() {
|
|
if [ $ADDOND_VERSION -lt 3 ]; then
|
|
echo "/postinstall/$1"
|
|
return
|
|
fi
|
|
|
|
file=$(echo "$1" | sed "s|^$S/||")
|
|
if __is_on_mounted_partition "$file"; then
|
|
echo "/postinstall/$file"
|
|
else
|
|
echo "/postinstall/$1"
|
|
fi
|
|
}
|
|
|
|
__is_on_mounted_partition() {
|
|
for p in $all_V3_partitions; do
|
|
mnt_point="/postinstall/$p"
|
|
if echo "$1" | grep -q "^$p/" && [ ! -L "$mnt_point" ] && mountpoint >/dev/null 2>&1 "$mnt_point"; then
|
|
return 0
|
|
fi
|
|
done
|
|
|
|
return 1
|
|
}
|