forked from opengapps/opengapps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport_sources.sh
executable file
·111 lines (102 loc) · 4.53 KB
/
report_sources.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
#!/bin/sh
#This file is part of The Open GApps script of @mfonville.
#
# The Open GApps scripts are free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# These scripts are distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
TOP="$(realpath .)"
SOURCES="$TOP/sources"
command -v aapt >/dev/null 2>&1 || { echo "aapt is required but it's not installed. Aborting." >&2; exit 1; }
command -v md5sum >/dev/null 2>&1 || { echo "md5sum is required but it's not installed. Aborting." >&2; exit 1; }
argument(){
case $1 in
hash) hash="hash";;
nohelp) nohelp="nohelp";;
all) filterapparchs="${filterapparchs} all";;
arm) filterapparchs="${filterapparchs} arm";;
arm64) filterapparchs="${filterapparchs} arm64";;
x86) filterapparchs="${filterapparchs} x86";;
x86_64) filterapparchs="${filterapparchs} x86_64";;
*-*) buildarch="$(echo "$1" | cut -f 1 -d '-')"
maxsdk="$(echo "$1" | cut -f 2 -d '-')";;
*) maxsdk="$1";;
esac
}
hash=""
nohelp=""
filterapparchs=""
buildarch=""
fallbackarch=""
maxsdk="99"
for arg in "$@";do
argument "$arg"
done
if [ -z "$hash" ] && [ -z "$nohelp" ]; then
echo "=== Simple How To ===:
* No arguments: Show all packages of all architectures and SDK-levels
=== OR ===
* SDK-level as a argument: Show packages that are eligable to be picked when building for specified SDK-level
* all|arm|arm64|x86|x86_64: Show only packages of given architecture
* These arguments can be combined in any order and multiple architectures can be supplied
* Example command: './report_sources.sh 22 all arm arm64'
=== OR ===
* (all|arm|arm64|x86|x86_64)-(SDK-level): Show packages that will be selected when building for specified architecture and SDK-level
* Example command: './report_sources.sh arm-22'
=== AND ===
* hash: If you add hash as an extra argument, the result will not be returned as human readable, but with a unique hash for the resultset
* nohelp: If you add nohelp as an extra argument, the result will not include this helptext (not necessary if hash is used)
* Example command: './report_sources.sh arm-22 hash'
--------------------------------------------------------------------------------------------------------------"
fi
if [ "$buildarch" = arm64 ]; then
fallbackarch="arm"
elif [ "$buildarch" = x86_64 ]; then
fallbackarch="x86"
fi
result="$(printf "%45s|%7s|%3s|%16s|%23s|%11s" "Application Name" "Arch." "SDK" "DPI" "Version Name" "Version")
--------------------------------------------------------------------------------------------------------------"
allapps="$(find "$SOURCES/" -iname "*.apk" | awk -F '/' '{print $(NF-3)}' | sort | uniq)"
for appname in $allapps;do
appnamefiles="$(find "$SOURCES/" -iname "*.apk" -ipath "*/$appname/*")"
if [ -n "$buildarch" ]; then
apparchs="$buildarch $fallbackarch all"
elif [ -n "$filterapparchs" ];then
apparchs="$filterapparchs"
else
apparchs="$(printf "%s" "$appnamefiles" | awk -F '/' '{print $(NF-5)}' | sort | uniq)"
fi
for arch in $apparchs;do
appsdkfiles="$(find "$SOURCES/$arch/" -iname "*.apk" -ipath "*/$appname/*")"
appsdks="$(printf "%s" "$appsdkfiles" | awk -F '/' '{print $(NF-2)}' | sort -r -g | uniq)"
for sdk in $appsdks;do
if [ "$sdk" -le "$maxsdk" ];then
appdpifiles="$(find "$SOURCES/$arch/" -iname "*.apk" -ipath "*/$appname/$sdk/*")"
appdpis="$(printf "%s" "$appdpifiles" | awk -F '/' '{print $(NF-1)}' | sort | uniq)"
for dpi in $appdpis;do
appversionfile="$(find "$SOURCES/$arch/" -iname "*.apk" -ipath "*/$appname/$sdk/$dpi/*" | head -n 1)"
appversion="$(basename -s ".apk" "$appversionfile")"
appversionname="$(aapt dump badging "$appversionfile" 2>/dev/null | grep "versionName" | awk '{print $4}' | sed s/versionName=// | sed "s/'//g")"
result="$result
$(printf "%45s| %6s| %2s| %15s| %22s| %10s" "$appname" "$arch" "$sdk" "$dpi" "$appversionname" "$appversion")"
done
if [ -n "$buildarch" ]; then
break 2 #when selecting for the build of a specified architeture and sdk, only one architecture result is enough
elif [ "$maxsdk" != "99" ];then
break #if a specific sdk level is supplied, we only show 1 relevant version
fi
fi
done
done
done
if [ -z "$hash" ]; then
echo "$result"
else
printf "%s" "$result" | md5sum | cut -f1 -d' '
fi