blob: e9111ade8fb3e5220ca7181c7d39d4e67faf7827 [file] [log] [blame]
Dan Pasanen894b3522017-01-16 19:26:50 -06001#!/system/bin/sh
2#
3# Functions for backuptool_ab.sh
4#
5
6export S=/system
7export C=/postinstall/tmp/backupdir
micky3872a465452023-11-06 21:43:44 +01008export V=14
Dan Pasanen894b3522017-01-16 19:26:50 -06009export backuptool_ab=true
10
11copy_file() {
Luca Stefani17a10552019-08-19 21:45:15 +020012 old=`umask`
13 umask 0322
14 mkdir -m755 -p `dirname $2`
15 umask "$old"
Dan Pasanen894b3522017-01-16 19:26:50 -060016
Luca Stefani17a10552019-08-19 21:45:15 +020017 cp -dp --preserve=a "$1" "$2"
Dan Pasanen894b3522017-01-16 19:26:50 -060018}
19
razorlovesb3190ba2020-09-04 23:29:34 -050020move_file() {
21 old=`umask`
22 umask 0322
23 mkdir -m755 -p `dirname $2`
24 umask "$old"
25
26 mv "$1" "$2"
27}
28
Dan Pasanen894b3522017-01-16 19:26:50 -060029backup_file() {
30 if [ -e "$1" -o -L "$1" ]; then
Dan Pasanen894b3522017-01-16 19:26:50 -060031 # dont backup any apps that have odex files, they are useless
Luca Stefani17a10552019-08-19 21:45:15 +020032 if ( echo "$1" | grep -q "\.apk$" ) && [ -e `echo "$1" | sed -e 's/\.apk$/\.odex/'` ]; then
Dan Pasanen894b3522017-01-16 19:26:50 -060033 echo "Skipping odexed apk $1";
34 else
Luca Stefani17a10552019-08-19 21:45:15 +020035 copy_file "$1" "$C/$1"
Dan Pasanen894b3522017-01-16 19:26:50 -060036 fi
37 fi
38}
39
40restore_file() {
Luca Stefani17a10552019-08-19 21:45:15 +020041 if [ -e "$C/$1" -o -L "$C/$1" ]; then
Alessandro Astone09bec2c2020-12-29 18:38:28 +010042 move_file "$C/$1" $(get_output_path "$1");
Dan Pasanen894b3522017-01-16 19:26:50 -060043 if [ -n "$2" ]; then
44 echo "Deleting obsolete file $2"
Alessandro Astone09bec2c2020-12-29 18:38:28 +010045 rm $(get_output_path "$2");
Dan Pasanen894b3522017-01-16 19:26:50 -060046 fi
47 fi
48}
Alessandro Astone09bec2c2020-12-29 18:38:28 +010049
50get_output_path() {
51 if [ $ADDOND_VERSION -lt 3 ]; then
52 echo "/postinstall/$1"
53 return
54 fi
55
56 file=$(echo "$1" | sed "s|^$S/||")
57 if __is_on_mounted_partition "$file"; then
58 echo "/postinstall/$file"
59 else
60 echo "/postinstall/$1"
61 fi
62}
63
64__is_on_mounted_partition() {
65 for p in $all_V3_partitions; do
66 mnt_point="/postinstall/$p"
67 if echo "$1" | grep -q "^$p/" && [ ! -L "$mnt_point" ] && mountpoint >/dev/null 2>&1 "$mnt_point"; then
68 return 0
69 fi
70 done
71
72 return 1
73}