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 | #!/bin/bash
_TOOLS=/android-sdk-path/build-tools/34.0.0-rc2
_AAPT=${_TOOLS}/aapt
_PMLIST=packages_list.txt
_DIST_DIR="packages_"$(date "+%Y-%m-%d_%H%M%S")
adb shell pm list packages | sed -e 's|^package:||' | sort > ./${_PMLIST}
mkdir -p ${_DIST_DIR}
n=0
while read -u 9 _line; do
#if (( n > 0 )); then break; fi
_package=${_line##*:}
_apkpath=$(adb shell pm path ${_package} | sed -e 's|^package:||' | head -n 1)
_apkfilename=$(basename "${_apkpath}")
if [[ "${_apkpath}" = /data/app/* ]]
then
echo ""
echo "line: ${_line}"
echo "package: ${_package}"
echo "_apkpath: ${_apkpath}"
echo "_apkfilename: {$_apkfilename}"
adb pull ${_apkpath} ${_DIST_DIR}/
_name=$(${_AAPT} dump badging "${_DIST_DIR}/${_apkfilename}" | sed -n 's|^application-label:\(.\)\(.*\)\1$|\2|p' )
echo "APP NAME: ${_name}"
_version=$(${_AAPT} dump badging "${_DIST_DIR}/${_apkfilename}" | sed -n '/versionName=/p' | awk 'match($0, /versionName=\S+/) {print substr($0, RSTART+13, RLENGTH-14)}')
echo "APP VERSION: ${_version}"
mv "${_DIST_DIR}/${_apkfilename}" "${_DIST_DIR}/${_package}-${_version}-${_name}.apk"
echo ""
n=$((n+1))
fi
done 9< ${_PMLIST}
echo ""
echo "TOTAL $n apps are backed up."
|