Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 1 | #!/sbin/sh |
| 2 | # |
| 3 | # Functions for backuptool.sh |
| 4 | # |
| 5 | |
| 6 | export C=/tmp/backupdir |
| 7 | export S=/system |
Rashed Abdel-Tawab | 6326caa | 2018-08-07 10:49:49 -0700 | [diff] [blame] | 8 | export V=16.0 |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 9 | |
Gabriele M | 0e2d72e | 2017-02-27 15:44:17 +0100 | [diff] [blame] | 10 | copy_file() { |
| 11 | cp -dp "$1" "$2" |
| 12 | # symlinks don't have a context |
| 13 | if [ ! -L "$1" ]; then |
| 14 | # it is assumed that every label starts with 'u:object_r' and has no white-spaces |
| 15 | local context=`ls -Z "$1" | grep -o 'u:object_r:[^ ]*' | head -1` |
| 16 | chcon "$context" "$2" |
| 17 | fi |
| 18 | } |
| 19 | |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 20 | backup_file() { |
Gabriele M | 556246b | 2017-02-26 21:01:38 +0100 | [diff] [blame] | 21 | if [ -e "$1" -o -L "$1" ]; then |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 22 | local F=`basename "$1"` |
| 23 | local D=`dirname "$1"` |
| 24 | # dont backup any apps that have odex files, they are useless |
| 25 | if ( echo "$F" | grep -q "\.apk$" ) && [ -e `echo "$1" | sed -e 's/\.apk$/\.odex/'` ]; then |
| 26 | echo "Skipping odexed apk $1"; |
| 27 | else |
| 28 | mkdir -p "$C/$D" |
Gabriele M | 0e2d72e | 2017-02-27 15:44:17 +0100 | [diff] [blame] | 29 | copy_file "$1" "$C/$D/$F" |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 30 | fi |
| 31 | fi |
| 32 | } |
| 33 | |
| 34 | restore_file() { |
| 35 | local FILE=`basename "$1"` |
| 36 | local DIR=`dirname "$1"` |
Gabriele M | 556246b | 2017-02-26 21:01:38 +0100 | [diff] [blame] | 37 | if [ -e "$C/$DIR/$FILE" -o -L "$C/$DIR/$FILE" ]; then |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 38 | if [ ! -d "$DIR" ]; then |
| 39 | mkdir -p "$DIR"; |
| 40 | fi |
Gabriele M | 0e2d72e | 2017-02-27 15:44:17 +0100 | [diff] [blame] | 41 | copy_file "$C/$DIR/$FILE" "$1"; |
Warren Togami | b1637c8 | 2012-03-03 22:37:42 -1000 | [diff] [blame] | 42 | if [ -n "$2" ]; then |
| 43 | echo "Deleting obsolete file $2" |
| 44 | rm "$2"; |
| 45 | fi |
| 46 | fi |
| 47 | } |