2012-03-04 08:37:42 +00:00
|
|
|
#!/sbin/sh
|
|
|
|
#
|
|
|
|
# Functions for backuptool.sh
|
|
|
|
#
|
|
|
|
|
|
|
|
export C=/tmp/backupdir
|
|
|
|
export S=/system
|
2015-10-07 15:38:03 +00:00
|
|
|
export V=13.0
|
2012-03-04 08:37:42 +00:00
|
|
|
|
2017-02-27 14:44:17 +00:00
|
|
|
copy_file() {
|
|
|
|
cp -dp "$1" "$2"
|
|
|
|
# symlinks don't have a context
|
|
|
|
if [ ! -L "$1" ]; then
|
|
|
|
# it is assumed that every label starts with 'u:object_r' and has no white-spaces
|
|
|
|
local context=`ls -Z "$1" | grep -o 'u:object_r:[^ ]*' | head -1`
|
|
|
|
chcon "$context" "$2"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2012-03-04 08:37:42 +00:00
|
|
|
backup_file() {
|
2017-02-26 20:01:38 +00:00
|
|
|
if [ -e "$1" -o -L "$1" ]; then
|
2012-03-04 08:37:42 +00:00
|
|
|
local F=`basename "$1"`
|
|
|
|
local D=`dirname "$1"`
|
|
|
|
# dont backup any apps that have odex files, they are useless
|
|
|
|
if ( echo "$F" | grep -q "\.apk$" ) && [ -e `echo "$1" | sed -e 's/\.apk$/\.odex/'` ]; then
|
|
|
|
echo "Skipping odexed apk $1";
|
|
|
|
else
|
|
|
|
mkdir -p "$C/$D"
|
2017-02-27 14:44:17 +00:00
|
|
|
copy_file "$1" "$C/$D/$F"
|
2012-03-04 08:37:42 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
restore_file() {
|
|
|
|
local FILE=`basename "$1"`
|
|
|
|
local DIR=`dirname "$1"`
|
2017-02-26 20:01:38 +00:00
|
|
|
if [ -e "$C/$DIR/$FILE" -o -L "$C/$DIR/$FILE" ]; then
|
2012-03-04 08:37:42 +00:00
|
|
|
if [ ! -d "$DIR" ]; then
|
|
|
|
mkdir -p "$DIR";
|
|
|
|
fi
|
2017-02-27 14:44:17 +00:00
|
|
|
copy_file "$C/$DIR/$FILE" "$1";
|
2012-03-04 08:37:42 +00:00
|
|
|
if [ -n "$2" ]; then
|
|
|
|
echo "Deleting obsolete file $2"
|
|
|
|
rm "$2";
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|