-
Notifications
You must be signed in to change notification settings - Fork 7
/
restore.sh
85 lines (75 loc) · 2.09 KB
/
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
#!/bin/sh
set -e
. $(dirname $0)/config
uid=$1
shift
pkg=$1
if [ -z "$uid" -o -z "$pkg" ]; then
echo "Usage $0 <uid> <pkg>"
exit 0
fi
base="$devdatadir"
cd /data
pkgs="$*"
uids=$uid
# Backup all installed packages?
if [ "$pkg" = "all" ]; then
pkgfiles="$(cd $devdatadir/apks; ls *.apk)"
pkgs=""
for file in $pkgfiles; do
pkgs="$pkgs ${file%\.apk}"
done
fi
if [ "$uid" = "all" ]; then
uids="$(cd $devdatadir/data; ls | grep '^[0-9]*$')"
fi
for uid in $uids; do
echo "Restoring backup for uid $uid.."
for pkg in $pkgs; do
[ -z "$pkg" ] && ( echo "Missing pkg"; exit 1)
echo " Restoring pkg $pkg.."
if [ -f "$base/apks/$pkg.apk" ]; then
if [ -z "$(pm list package $pkg)" ]; then
echo " Installing pkg.."
pm install $base/apks/$pkg.apk >/dev/null
echo " done."
else
echo " pkg already installed.."
fi
if [ -f "$base/data/$uid/$pkg.disabled" ]; then
echo " Disabling pkg.."
pm disable --user $uid $pkg >/dev/null
echo " done."
else
echo " Enabling pkg.."
pm enable --user $uid $pkg >/dev/null
echo " done."
fi
fi
if [ -f "$base/data/$uid/$pkg-user.tar" ]; then
echo " Getting uid/gid and secontext.."
secontext=$(ls -dZ user/$uid/$pkg | cut -f1 -d' ')
user=$(ls -dl user/$uid/$pkg | cut -f3 -d' ')
group=$(ls -dl user/$uid/$pkg | cut -f4 -d' ')
echo " done."
echo " Restoring userdata.."
rm -rf user/$uid/$pkg
tar x -C user/$uid -f $base/data/$uid/$pkg-user.tar $pkg
echo " done."
echo " Restoring ownership.."
chown -R $user:$group user/$uid/$pkg
echo " done."
echo " Restoring secontext.."
find user/$uid/$pkg -exec chcon $secontext {} \;
echo " done."
fi
if [ -f "$base/data/$uid/$pkg-media.tar" ]; then
echo " Restoring media.."
rm -rf media/$uid/Android/data/$pkg
tar x -C media/$uid/Android/data -f $base/data/$uid/$pkg-media.tar $pkg
echo " done."
fi
echo " done."
done
echo "done."
done