blob: c0fbf5c85a12e8beefbb46dae60ce8128af85a3d [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
maxwen5b158882022-08-21 00:02:47 +02008export V=13
Dan Pasanen894b3522017-01-16 19:26:50 -06009export backuptool_ab=true
10
11copy_file() {
12 # toybox's cp doesn't do directories correctly for whatever reason
13 mkdir -p `dirname $2`
14
15 cp -dp "$1" "$2"
16 # symlinks don't have a context
17 if [ ! -L "$1" ]; then
18 # it is assumed that every label starts with 'u:object_r' and has no white-spaces
19 local context=`ls -Z "$1" | grep -o 'u:object_r:[^ ]*' | head -1`
20 chcon "$context" "$2"
21 fi
22}
23
24backup_file() {
25 if [ -e "$1" -o -L "$1" ]; then
26 local FILE=`basename "$1"`
27 local DIR=`dirname "$1"`
28 # dont backup any apps that have odex files, they are useless
29 if ( echo "$FILE" | grep -q "\.apk$" ) && [ -e `echo "$1" | sed -e 's/\.apk$/\.odex/'` ]; then
30 echo "Skipping odexed apk $1";
31 else
32 mkdir -p "$C/$DIR"
33 copy_file "$1" "$C/$DIR/$FILE"
34 fi
35 fi
36}
37
38restore_file() {
39 local FILE=`basename "$1"`
40 local DIR=`dirname "$1"`
41 if [ -e "$C/$DIR/$FILE" -o -L "$C/$DIR/$FILE" ]; then
42 if [ ! -d "/postinstall/$DIR" ]; then
43 mkdir -p "/postinstall/$DIR";
44 fi
45 copy_file "$C/$DIR/$FILE" "/postinstall/$1";
46 if [ -n "$2" ]; then
47 echo "Deleting obsolete file $2"
48 rm "$2";
49 fi
50 fi
51}