blob: 7a915072fdbd27dc76cccdb737944c278aba71ca [file] [log] [blame]
Warren Togamib1637c82012-03-03 22:37:42 -10001#!/sbin/sh
2#
3# Functions for backuptool.sh
4#
5
Gabriele M0e2d72e2017-02-27 15:44:17 +01006copy_file() {
7 cp -dp "$1" "$2"
8 # symlinks don't have a context
9 if [ ! -L "$1" ]; then
10 # it is assumed that every label starts with 'u:object_r' and has no white-spaces
11 local context=`ls -Z "$1" | grep -o 'u:object_r:[^ ]*' | head -1`
12 chcon "$context" "$2"
13 fi
14}
15
Warren Togamib1637c82012-03-03 22:37:42 -100016backup_file() {
Gabriele M556246b2017-02-26 21:01:38 +010017 if [ -e "$1" -o -L "$1" ]; then
Warren Togamib1637c82012-03-03 22:37:42 -100018 local F=`basename "$1"`
19 local D=`dirname "$1"`
20 # dont backup any apps that have odex files, they are useless
21 if ( echo "$F" | grep -q "\.apk$" ) && [ -e `echo "$1" | sed -e 's/\.apk$/\.odex/'` ]; then
22 echo "Skipping odexed apk $1";
23 else
24 mkdir -p "$C/$D"
Gabriele M0e2d72e2017-02-27 15:44:17 +010025 copy_file "$1" "$C/$D/$F"
Warren Togamib1637c82012-03-03 22:37:42 -100026 fi
27 fi
28}
29
30restore_file() {
31 local FILE=`basename "$1"`
32 local DIR=`dirname "$1"`
Gabriele M556246b2017-02-26 21:01:38 +010033 if [ -e "$C/$DIR/$FILE" -o -L "$C/$DIR/$FILE" ]; then
Warren Togamib1637c82012-03-03 22:37:42 -100034 if [ ! -d "$DIR" ]; then
35 mkdir -p "$DIR";
36 fi
Alessandro Astone42aa1fa2020-12-29 18:38:28 +010037 copy_file "$C/$DIR/$FILE" $(get_output_path "$1");
Warren Togamib1637c82012-03-03 22:37:42 -100038 if [ -n "$2" ]; then
39 echo "Deleting obsolete file $2"
Alessandro Astone42aa1fa2020-12-29 18:38:28 +010040 rm $(get_output_path "$2");
Warren Togamib1637c82012-03-03 22:37:42 -100041 fi
42 fi
43}
Alessandro Astone42aa1fa2020-12-29 18:38:28 +010044
45get_output_path() {
46 # In recovery we mounted all partitions in the right place, so we can rely on symlinks
47 echo "$1"
48}