aboutsummaryrefslogtreecommitdiffstats
path: root/prebuilt/common/bin/backuptool.functions
blob: 8a372a3eef83ff391aa88ad1af4556a4c2c470c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/sbin/sh
#
# Functions for backuptool.sh
#

export C=/tmp/backupdir
export S=/system
export V=13.0

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
}

backup_file() {
  if [ -e "$1" -o -L "$1" ]; then
    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"
      copy_file "$1" "$C/$D/$F"
    fi
  fi
}

restore_file() {
  local FILE=`basename "$1"`
  local DIR=`dirname "$1"`
  if [ -e "$C/$DIR/$FILE" -o -L "$C/$DIR/$FILE" ]; then
    if [ ! -d "$DIR" ]; then
      mkdir -p "$DIR";
    fi
    copy_file "$C/$DIR/$FILE" "$1";
    if [ -n "$2" ]; then
      echo "Deleting obsolete file $2"
      rm "$2";
    fi
  fi
}