-
Notifications
You must be signed in to change notification settings - Fork 0
/
abtool
executable file
·167 lines (136 loc) · 2.67 KB
/
abtool
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#! /bin/bash
#
# abtool
# Copyright (C) 2013 Adrian Perez <aperez@igalia.com>
#
# Distributed under terms of the MIT license.
#
set -e
#
# cmd_help topic
#
cmd_help ()
{
case ${1:-commands} in
commands)
cat <<-EOF
Usage: $0 command [command arguments]
Available commands:
unpack Unpack an ADB backup to a directory.
pack Pack a directory to an ADB backup.
list Lists contents of an ADB backup.
help Display usage information for commands.
EOF
;;
unpack)
cat <<-EOF
Usage: $0 unpack file [path]
Unpacks an ADB backup file to a directory tree.
Arguments:
file ADB backup file, obtained with 'adb backup'
path Directory where to extract the backup contents. It will be
automatically created if it does not exist. If not given,
the current directory will be used for output.
EOF
;;
pack)
cat <<-EOF
Usage: $0 pack file [path]
Packs a directory tree to an ADB backup file.
Arguments:
file ADB backup file resulting from the packing.
path Directory containing the input files. If not given, the
current directory will be used as input.
EOF
;;
list)
cat <<-EOF
Usage: $0 list file
Lists the contents of an ADB backup file.
Arguments:
file ADB backup file resulting from the packing.
EOF
;;
help)
cat <<-EOF
Usage: $0 help [topic]
Options:
topic Command name or topic (use 'help topics' for a list)
EOF
;;
*)
cat 1>&2 <<-EOF
$0: help: No such topic '$1'
EOF
exit 1
;;
esac
}
#
# cmd_unpack backup.ab [dest_path]
#
cmd_unpack ()
{
if [[ $# -lt 1 ]] ; then
echo "$0: unpack: Invalid command line." 1>&2
exit 1
fi
local tar_opts=( )
if [[ $# -gt 1 ]] ; then
mkdir -p "$2"
tar_opts=( -C "$2" )
fi
tail -n +5 "$1" | openssl zlib -d | tar -xf - "${tar_opts[@]}"
}
#
# cmd_list backup.ab
#
cmd_list ()
{
if [[ $# -lt 1 ]] ; then
echo "$0: list: Invalid command line." 1>&2
exit 1
fi
tail -n +5 "$1" | openssl zlib -d | tar -tf -
}
declare -r HEADER=$'ANDROID BACKUP\n1\n1\nnone\n'
#
# cmd_pack
#
cmd_pack ()
{
if [[ $# -lt 1 ]] ; then
echo "$0: pack: Invalid command line." 1>&2
exit 1
fi
local dir='.'
if [[ $# -gt 1 ]] ; then
if [[ ! -d $2 ]] ; then
echo "$0: pack: Directory '$2' does not exist." 1>&2
exit 1
fi
dir=$2
fi
( cd "${dir}"
echo "$HEADER"
tar -cf - . | openssl zlib -e
) > "$1"
}
if [[ $# -eq 0 ]] ; then
cmd=help
else
cmd=$1
shift
fi
case ${cmd} in
pack | unpack | list | help)
cmd_${cmd} "$@"
;;
*)
cat 1>&2 <<-EOF
$0: No such command '${cmd}'
Use '$0 help' to get a list of available commands
EOF
exit 1
;;
esac