forked from cluk1/android-multiuser-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adb-restore.sh
executable file
·127 lines (115 loc) · 3.85 KB
/
adb-restore.sh
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash +x
. $(dirname $0)/config
function usage {
echo "usage: $0 DEVICE USER_ID|all PACKAGES...|all"
echo "exam1: $0 XXXXXX all all"
echo "exam2: $0 XXXXXX 0 com.google.android.youtube"
}
if [ ! "$1" ]; then
usage
$A0 devices
exit 1
fi
set -e
DEVICE=$1
shift
AUID=$1
START_AUID=$AUID
shift
PKG=$1
START_PKG=$PKG
if [ -z "$AUID" -o -z "$PKG" ]; then
usage
exit 0
fi
A="$A0 -s $DEVICE"
AS="$A shell"
PKGS="$*"
UPKGS=$PKGS
AUIDS="$AUID"
ALL_PKGS=0
# Backup all installed packages?
if [ "$PKGS" = "all" ]; then
PKGS="`cat $LBASE/pall.txt`"
ALL_PKGS=1
fi
if [ "$AUID" = "all" ]; then
#PRE-REQUISITE BEFORE ENTER RECOVERY:
# adb shell "pm list users | grep 'UserInfo' | cut -f1 -d':' | cut -f2 -d'{' > $LBASE/alluser.txt"
AUIDS="`cat $LBASE/alluser.txt`"
fi
for AUID in $AUIDS; do
printf "Restoring backup for uid $AUID.."
if [ $ALL_PKGS -eq 1 ]; then
UPKGS="`cat $LBASE/puser_$AUID.txt`"
fi
for PKG in $UPKGS; do
#[ -z "$pkg" ] && ( echo "Missing pkg"; exit 1)
[ -z "$PKG" ] && ( echo "Missing pkg"; exit 1)
printf " Restoring pkg $PKG.."
if [ -d "$LBASE/apks/$PKG" ] || [ -f "$LBASE/apks/$PKG.apk" ]; then
#FIX MULTIPLE APKS
if [ "$($AS pm list package $PKG)" ]; then
echo " pkg already installed.."
else
printf " Installing pkg.."
if [ -d "$LBASE/apks/$PKG" ]; then #MULTIPLE APKS
$A install-multiple $LBASE/apks/$PKG/*apk >/dev/null
else #SINGLE APK
$A install $LBASE/apks/$PKG.apk >/dev/null
fi
echo " done."
fi
if [ -f "$LBASE/data/$AUID/$PKG.disabled" ]; then
printf " Disabling pkg.."
$AS pm disable --user $AUID $PKG >/dev/null
echo " done."
else
printf " Enabling pkg.."
$AS pm enable --user $AUID $PKG >/dev/null
echo " done."
fi
fi
############### IN RECOVERY #######################
# #if [ -f "$base/data/$uid/$pkg-user.tar" ]; then
# if [ -f "$LBASE/data/$AUID/$PKG-user.tar" ]; then
# echo " Getting uid/gid and secontext.."
# #secontext=$(ls -dZ user/$uid/$pkg | cut -f1 -d' ')
# SECONTEXT=$(ls -dZ /data/user/$AUID/$PKG | cut -f1 -d' ')
# #user=$(ls -dl user/$uid/$pkg | cut -f3 -d' ')
# AUSERr=$(ls -dl /data/user/$AUID/$PKG | cut -f3 -d' ')
# #group=$(ls -dl user/$uid/$pkg | cut -f4 -d' ')
# AGROUP=$(ls -dl /data/user/$AUID/$PKG | cut -f4 -d' ')
# echo " done."
# echo " Restoring userdata.."
# #rm -rf user/$uid/$pkg
# rm -rf /data/user/$UID/$PKG
# #tar x -C user/$uid -f $base/data/$uid/$pkg-user.tar $pkg
# cat $LBASE/data/$AUID/$PKG-user.tar | $AS "tar x -C user/$AUID $PKG"
# echo " done."
# echo " Restoring ownership.."
# #chown -R $user:$group user/$uid/$pkg
# $AS "chown -R $AUSER:$AGROUP user/$AUID/$PKG"
# echo " done."
# echo " Restoring secontext.."
# #find user/$uid/$pkg -exec chcon $secontext {} \;
# $AS "find user/$AUID/$PKG -exec chcon $SECONTEXT {} \;"
# echo " done."
# fi
# #if [ -f "$base/data/$uid/$pkg-media.tar" ]; then
# if [ -f "$LBASE/data/$AUID/$PKG-media.tar" ]; then
# echo " Restoring media.."
# #rm -rf media/$uid/Android/data/$pkg
# $AS "rm -rf /datamedia/$AUID/Android/data/$PKG"
# #tar x -C media/$uid/Android/data -f $base/data/$uid/$pkg-media.tar $pkg
# cat $LBASE/data/$AUID/$PKG-media.tar | $AS "tar x -C media/$AUID/Android/data $PKG"
# echo " done."
# fi
############### END IN RECOVERY #######################
echo " done."
done
echo "done."
done
echo "Next, reboot to recovery to restore userdata (adb -s $DEVICE reboot recovery, adb -s $DEVICE reboot bootloader && fastboot boot twrp-xxxx)"
echo "Require mounted /data: mount /dev/block/by-name/userdata /data"
echo "Then run: $(dirname $0)/restore.sh $DEVICE $START_AUID $START_PKG"