Introduce caching of APKsignature results for 'ok'
[opengapps/opengapps.git] / report_sources.sh
blob01de1ff4f1915c7c05664953f36a85393c4c1b64
1 #!/bin/bash
2 #This file is part of The Open GApps script of @mfonville.
4 # The Open GApps scripts are free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # These scripts are distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
15 command -v realpath >/dev/null 2>&1 || { echo "realpath is required but it's not installed, aborting." >&2; exit 1; }
16 TOP="$(realpath .)"
17 CACHE="$TOP/cache"
18 SOURCES="$TOP/sources"
19 SCRIPTS="$TOP/scripts"
20 CERTIFICATES="$SCRIPTS/certificates"
21 # shellcheck source=scripts/inc.tools.sh
22 . "$SCRIPTS/inc.tools.sh"
23 # shellcheck source=scripts/inc.compatibility.sh
24 . "$SCRIPTS/inc.compatibility.sh"
25 # shellcheck source=scripts/inc.sourceshelper.sh
26 . "$SCRIPTS/inc.sourceshelper.sh"
28 # Check tools
29 checktools aapt bc coreutils jarsigner
31 argument(){
32 case $1 in
33 hash) hash="hash";;
34 nobeta) nobeta="! -ipath '*.beta*'";;
35 nohelp) nohelp="nohelp";;
36 noleanback) noleanback="! -ipath '*.leanback*'";;
37 nosig) nosig="nosig";;
38 nostub) nostub="! -ipath '*.stub*'";;
39 all) filterapparchs="${filterapparchs} all";;
40 arm) filterapparchs="${filterapparchs} arm";;
41 arm64) filterapparchs="${filterapparchs} arm64";;
42 x86) filterapparchs="${filterapparchs} x86";;
43 x86_64) filterapparchs="${filterapparchs} x86_64";;
44 max*mb) filtermaxsize="${1:3:-2}"
45 [ ! -z "${filtermaxsize##*[!0-9]*}" ] || { echo "ERROR: invalid argument" && exit 1; };;
46 min*mb) filterminsize="${1:3:-2}"
47 [ ! -z "${filterminsize##*[!0-9]*}" ] || { echo "ERROR: invalid argument" && exit 1; };;
48 *-*) buildarch="$(echo "$1" | cut -f 1 -d '-')"
49 maxsdk="$(echo "$1" | cut -f 2 -d '-')"
50 [ ! -z "${maxsdk##*[!0-9]*}" ] || { echo "ERROR: invalid argument" && exit 1; };;
51 *) [ ! -z "${1##*[!0-9]*}" ] && maxsdk="$1" || { echo "ERROR: invalid argument" && exit 1; };;
52 esac
55 hash=""
56 nobeta=""
57 nohelp=""
58 noleanback=""
59 nosig=""
60 nostub=""
61 filterapparchs=""
62 filtermaxsize=""
63 filterminsize=""
64 buildarch=""
65 maxsdk="99"
67 for arg in "$@"; do
68 argument "$arg"
69 done
71 if [ -z "$hash" ] && [ -z "$nohelp" ]; then
72 echo "=== Simple How To ===:
73 * No arguments: Show all packages of all architectures and SDK-levels
74 === OR ===
75 * SDK-level as a argument: Show packages that are eligable to be picked when building for specified SDK-level
76 * all|arm|arm64|x86|x86_64: Show only packages of given architecture
77 * These arguments can be combined in any order and multiple architectures can be supplied
78 * Example command: './report_sources.sh 22 all arm arm64'
79 === OR ===
80 * (all|arm|arm64|x86|x86_64)-(SDK-level): Show packages that will be selected when building for specified architecture and SDK-level
81 * Example command: './report_sources.sh arm-22'
82 === AND ===
83 * 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
84 * max*mb: If you specify a number for *, the result will only include APKs that are at most that size (or equal) in (rounded) MiBs
85 * min*mb: If you specify a number for *, the result will only include APKs that are at least that size (or equal) in (rounded) MiBs
86 * nobeta: If you add nobeta as an extra argument, the result will not include the apps that are marked as beta (=ending on .beta)
87 * nohelp: If you add nohelp as an extra argument, the result will not include this helptext (not necessary if hash is used)
88 * noleanback: If you add noleanback as an extra argument, the result will not include the apps that are marked as leanback (=ending on .leanback)
89 * nosig: Skips signature checking (which takes a lot of CPU power); NB: this does change the hash result!
90 * nostub: If you add nostub as an extra argument, the result will not include the apps that are marked as stub (=ending on .stub)
91 * Example command: './report_sources.sh arm-22 hash'
92 --------------------------------------------------------------------------------------------------------------------------"
95 case "$buildarch" in
96 arm64|x86) fallbackarchs="arm";;
97 x86_64) fallbackarchs="x86 arm";;
98 *) fallbackarchs="";;
99 esac
101 result="$(printf "%61s|%6s|%3s|%15s|%35s|%10s|%3s|%4s" "Application Name" "Arch." "SDK" "DPI" "Version Name" "Version" "MiB" "Sig.")
102 ------------------------------------------------------------------------------------------------------------------------------------------------"
103 searchstring="find '$SOURCES/' -iname '*.apk' $nobeta $noleanback | awk -F '/' '{print \$(NF-3)}' | sort | uniq"
104 allapps="$(eval "$searchstring")"
105 for appname in $allapps; do
106 appnamefiles="$(find "$SOURCES/" -iname "*.apk" -ipath "*/$appname/*")"
107 if [ -n "$buildarch" ]; then
108 apparchs="$buildarch $fallbackarchs all"
109 elif [ -n "$filterapparchs" ];then
110 apparchs="$filterapparchs"
111 else
112 apparchs="$(printf "%s" "$appnamefiles" | awk -F '/' '{print $(NF-5)}' | sort | uniq)"
115 for arch in $apparchs; do
116 appsdkfiles="$(find "$SOURCES/$arch/" -iname "*.apk" -ipath "*/$appname/*")"
117 appsdks="$(printf "%s" "$appsdkfiles" | awk -F '/' '{print $(NF-2)}' | sort -r -g | uniq)"
119 for sdk in $appsdks; do
120 if [ "$sdk" -le "$maxsdk" ]; then
121 appdpifiles="$(find "$SOURCES/$arch/" -iname "*.apk" -ipath "*/$appname/$sdk/*")"
122 appdpis="$(printf "%s" "$appdpifiles" | awk -F '/' '{print $(NF-1)}' | sort | uniq)"
123 for dpi in $appdpis; do
124 appversionfile="$(find "$SOURCES/$arch/" -iname "*.apk" -ipath "*/$appname/$sdk/$dpi/*" | head -n 1)"
125 apksize="$(du --apparent-size -m "$appversionfile" | cut -f 1)"
126 if { [ -z "$filtermaxsize" ] || [ "$apksize" -le "$filtermaxsize" ];} && { [ -z "$filterminsize" ] || [ "$apksize" -ge "$filterminsize" ];} then
127 getapkproperties "$appversionfile" #set versionname and versioncode
128 if [ -z "$nosig" ]; then
129 if verifyapk "$appversionfile" "silent"; then
130 signed="ok"
131 else
132 signed="fail"
134 else
135 signed="skip"
137 result="$result
138 $(printf "%61s|%6s|%3s|%15s|%35s|%10s|%3s|%4s" "$appname" "$arch" "$sdk" "$dpi" "$versionname" "$versioncode" "$apksize" "$signed")"
140 done
141 if [ -n "$buildarch" ]; then
142 break 2 #when selecting for the build of a specified architeture and sdk, only one architecture result is enough
143 elif [ "$maxsdk" != "99" ];then
144 break #if a specific sdk level is supplied, we only show 1 relevant version
147 done
148 done
149 done
150 if [ -z "$hash" ]; then
151 echo "$result"
152 else
153 printf "%s" "$result" | md5sum | cut -f1 -d' '