Dan Pasanen | 894b352 | 2017-01-16 19:26:50 -0600 | [diff] [blame] | 1 | #!/system/bin/sh |
| 2 | # |
| 3 | # Functions for backuptool_ab.sh |
| 4 | # |
| 5 | |
| 6 | export S=/system |
| 7 | export C=/postinstall/tmp/backupdir |
maxwen | 5b15888 | 2022-08-21 00:02:47 +0200 | [diff] [blame^] | 8 | export V=13 |
Dan Pasanen | 894b352 | 2017-01-16 19:26:50 -0600 | [diff] [blame] | 9 | export backuptool_ab=true |
| 10 | |
| 11 | copy_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 | |
| 24 | backup_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 | |
| 38 | restore_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 | } |