blob: dd867c0b15d1726d532c37abd96b22f4162e6ef6 [file] [log] [blame]
Warren Togamib1637c82012-03-03 22:37:42 -10001#!/sbin/sh
2#
3# Functions for backuptool.sh
4#
5
6export C=/tmp/backupdir
7export S=/system
Luca Stefani5c60e4f2017-08-17 19:28:48 +02008export V=15.0
Warren Togamib1637c82012-03-03 22:37:42 -10009
Gabriele M0e2d72e2017-02-27 15:44:17 +010010copy_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 Togamib1637c82012-03-03 22:37:42 -100020backup_file() {
Gabriele M556246b2017-02-26 21:01:38 +010021 if [ -e "$1" -o -L "$1" ]; then
Warren Togamib1637c82012-03-03 22:37:42 -100022 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 M0e2d72e2017-02-27 15:44:17 +010029 copy_file "$1" "$C/$D/$F"
Warren Togamib1637c82012-03-03 22:37:42 -100030 fi
31 fi
32}
33
34restore_file() {
35 local FILE=`basename "$1"`
36 local DIR=`dirname "$1"`
Gabriele M556246b2017-02-26 21:01:38 +010037 if [ -e "$C/$DIR/$FILE" -o -L "$C/$DIR/$FILE" ]; then
Warren Togamib1637c82012-03-03 22:37:42 -100038 if [ ! -d "$DIR" ]; then
39 mkdir -p "$DIR";
40 fi
Gabriele M0e2d72e2017-02-27 15:44:17 +010041 copy_file "$C/$DIR/$FILE" "$1";
Warren Togamib1637c82012-03-03 22:37:42 -100042 if [ -n "$2" ]; then
43 echo "Deleting obsolete file $2"
44 rm "$2";
45 fi
46 fi
47}