@@ -5,13 +5,12 @@ TEMP_DIR="temp"
5
5
BIN_DIR=" bin"
6
6
BUILD_DIR=" build"
7
7
8
- if [ " ${GITHUB_TOKEN: - } " ]; then GH_HEADER=" Authorization: token ${GITHUB_TOKEN} " ; else GH_HEADER=; fi
8
+ if [ " ${GITHUB_TOKEN-} " ]; then GH_HEADER=" Authorization: token ${GITHUB_TOKEN} " ; else GH_HEADER=; fi
9
9
NEXT_VER_CODE=${NEXT_VER_CODE:- $(date +' %Y%m%d' )}
10
10
REBUILD=${REBUILD:- false}
11
11
OS=$( uname -o)
12
12
13
13
# -------------------- json/toml --------------------
14
- json_get () { grep -o " \" ${1} \" :[^\" ]*\" [^\" ]*\" " | sed -E ' s/".*".*"(.*)"/\1/' ; }
15
14
toml_prep () { __TOML__=$( tr -d ' \t\r' <<< " $1" | tr " '" ' "' | grep -o ' ^[^#]*' | grep -v ' ^$' | sed -r ' s/(\".*\")|\s*/\1/g; 1i []' ) ; }
16
15
toml_get_table_names () {
17
16
local tn
@@ -31,60 +30,55 @@ toml_get() {
31
30
pr () { echo -e " \033[0;32m[+] ${1} \033[0m" ; }
32
31
epr () {
33
32
echo >&2 -e " \033[0;31m[-] ${1} \033[0m"
34
- if [ " ${GITHUB_REPOSITORY: - } " ]; then echo -e " ::error::utils.sh [-] ${1} \n" ; fi
33
+ if [ " ${GITHUB_REPOSITORY-} " ]; then echo -e " ::error::utils.sh [-] ${1} \n" ; fi
35
34
}
36
35
abort () {
37
- epr " ABORT: ${1: - } "
36
+ epr " ABORT: ${1-} "
38
37
exit 1
39
38
}
40
39
41
40
get_rv_prebuilts () {
42
- local integrations_src=$1 patches_src=$2 integrations_ver=$3 patches_ver=$4 cli_src=$5 cli_ver=$6
43
- local patches_dir=${patches_src%/* }
44
- patches_dir=${TEMP_DIR} /${patches_dir,,} -rv
45
- local integrations_dir=${integrations_src%/* }
46
- integrations_dir=${TEMP_DIR} /${integrations_dir,,} -rv
47
- local cli_dir=${cli_src%/* }
48
- cli_dir=${TEMP_DIR} /${cli_dir,,} -rv
49
- mkdir -p " $patches_dir " " $integrations_dir " " $cli_dir "
50
-
41
+ local cli_src=$1 cli_ver=$2 integrations_src=$3 integrations_ver=$4 patches_src=$5 patches_ver=$6
51
42
pr " Getting prebuilts (${patches_src%/* } )" >&2
52
- local rv_cli_url rv_integrations_url rv_patches rv_patches_dl rv_patches_url rv_patches_json
53
-
54
- local rv_cli_rel=" https://api.github.com/repos/${cli_src} /releases/"
55
- if [ " $cli_ver " ]; then rv_cli_rel+=" tags/${cli_ver} " ; else rv_cli_rel+=" latest" ; fi
56
- local rv_integrations_rel=" https://api.github.com/repos/${integrations_src} /releases/"
57
- if [ " $integrations_ver " ]; then rv_integrations_rel+=" tags/${integrations_ver} " ; else rv_integrations_rel+=" latest" ; fi
58
- local rv_patches_rel=" https://api.github.com/repos/${patches_src} /releases/"
59
- if [ " $patches_ver " ]; then rv_patches_rel+=" tags/${patches_ver} " ; else rv_patches_rel+=" latest" ; fi
60
- rv_cli_url=$( gh_req " $rv_cli_rel " - | json_get ' browser_download_url' | grep -E ' \.jar$' ) || return 1
61
- local rv_cli_jar=" ${cli_dir} /${rv_cli_url##*/ } "
62
- echo " CLI: $( cut -d/ -f4 <<< " $rv_cli_url" ) /$( cut -d/ -f9 <<< " $rv_cli_url" ) " > " $patches_dir /changelog.md"
63
-
64
- rv_integrations_url=$( gh_req " $rv_integrations_rel " - | json_get ' browser_download_url' | grep -E ' \.apk$' ) || return 1
65
- local rv_integrations_apk=" ${integrations_dir} /${rv_integrations_url##*/ } "
66
- echo " Integrations: $( cut -d/ -f4 <<< " $rv_integrations_url" ) /$( cut -d/ -f9 <<< " $rv_integrations_url" ) " >> " $patches_dir /changelog.md"
67
-
68
- rv_patches=$( gh_req " $rv_patches_rel " -) || return 1
69
- # rv_patches_changelog=$(json_get 'body' <<<"$rv_patches" | sed 's/\(\\n\)\+/\\n/g')
70
- rv_patches_dl=$( json_get ' browser_download_url' <<< " $rv_patches" )
71
- rv_patches_json=" ${patches_dir} /patches-$( json_get ' tag_name' <<< " $rv_patches" ) .json"
72
- rv_patches_url=$( grep -E ' \.jar$' <<< " $rv_patches_dl" )
73
- local rv_patches_jar=" ${patches_dir} /${rv_patches_url##*/ } "
74
- [ -f " $rv_patches_jar " ] || REBUILD=true
75
- local nm
76
- nm=$( cut -d/ -f9 <<< " $rv_patches_url" )
77
- echo " Patches: $( cut -d/ -f4 <<< " $rv_patches_url" ) /$nm " >> " $patches_dir /changelog.md"
78
- # shellcheck disable=SC2001
79
- echo -e " [Changelog](https://github.com/${patches_src} /releases/tag/v$( sed ' s/.*-\(.*\)\..*/\1/' <<< " $nm" ) )\n" >> " $patches_dir /changelog.md"
80
- # echo -e "\n${rv_patches_changelog//# [/### [}\n---" >>"$patches_dir/changelog.md"
81
-
82
- dl_if_dne " $rv_cli_jar " " $rv_cli_url " >&2 || return 1
83
- dl_if_dne " $rv_integrations_apk " " $rv_integrations_url " >&2 || return 1
84
- dl_if_dne " $rv_patches_jar " " $rv_patches_url " >&2 || return 1
85
- dl_if_dne " $rv_patches_json " " $( grep ' json' <<< " $rv_patches_dl" ) " >&2 || return 1
86
-
87
- echo " $rv_cli_jar " " $rv_integrations_apk " " $rv_patches_jar " " $rv_patches_json "
43
+ for f in " ${TEMP_DIR} " /* -rv; do : > " ${f} /changelog.md" ; done
44
+ for src_ver in " $cli_src CLI $cli_ver " " $integrations_src Integrations $integrations_ver " " $patches_src Patches $patches_ver " ; do
45
+ set -- $src_ver
46
+ local src=$1 tag=$2 ver=${3-} ext
47
+ if [ " $tag " = " CLI" ] || [ " $tag " = " Patches" ]; then
48
+ ext=" jar"
49
+ elif [ " $tag " = " Integrations" ]; then
50
+ ext=" apk"
51
+ else abort unreachable; fi
52
+ local dir=${src%/* }
53
+ dir=${TEMP_DIR} /${dir,,} -rv
54
+ [ -d " $dir " ] || mkdir " $dir "
55
+
56
+ local rv_rel=" https://api.github.com/repos/${src} /releases/"
57
+ if [ " $ver " ]; then rv_rel+=" tags/${ver} " ; else rv_rel+=" latest" ; fi
58
+
59
+ local resp asset url name file
60
+ resp=$( gh_req " $rv_rel " -) || return 1
61
+ asset=$( jq -e -r " .assets[] | select(.name | endswith(\" $ext \" ))" <<< " $resp" ) || return 1
62
+ url=$( jq -r .url <<< " $asset" )
63
+ name=$( jq -r .name <<< " $asset" )
64
+ file=" ${dir} /${name} "
65
+ [ -f " $file " ] || REBUILD=true
66
+
67
+ echo " $tag : $( cut -d/ -f5 <<< " $url" ) /${name} " >> " $dir /changelog.md"
68
+ gh_dl " $file " " $url " >&2 || return 1
69
+ echo -n " $file "
70
+ if [ " $tag " = " Patches" ]; then
71
+ local tag_name
72
+ tag_name=$( jq -r ' .tag_name' <<< " $resp" )
73
+ name=" patches-${tag_name} .json"
74
+ file=" ${dir} /${name} "
75
+ url=$( jq -e -r ' .assets[] | select(.name | endswith("json")) | .url' <<< " $resp" ) || return 1
76
+ gh_dl " $file " " $url " >&2 || return 1
77
+ echo -n " $file "
78
+ echo -e " [Changelog](https://github.com/${src} /releases/tag/${tag_name} )\n" >> " $dir /changelog.md"
79
+ fi
80
+ done
81
+ echo
88
82
}
89
83
90
84
get_prebuilts () {
@@ -98,10 +92,10 @@ get_prebuilts() {
98
92
HTMLQ=" ${BIN_DIR} /htmlq/htmlq-x86_64"
99
93
fi
100
94
mkdir -p ${MODULE_TEMPLATE_DIR} /bin/arm64 ${MODULE_TEMPLATE_DIR} /bin/arm ${MODULE_TEMPLATE_DIR} /bin/x86 ${MODULE_TEMPLATE_DIR} /bin/x64
101
- dl_if_dne " ${MODULE_TEMPLATE_DIR} /bin/arm64/cmpr" " https://github.com/j-hc/cmpr/releases/latest/download/cmpr-arm64-v8a"
102
- dl_if_dne " ${MODULE_TEMPLATE_DIR} /bin/arm/cmpr" " https://github.com/j-hc/cmpr/releases/latest/download/cmpr-armeabi-v7a"
103
- dl_if_dne " ${MODULE_TEMPLATE_DIR} /bin/x86/cmpr" " https://github.com/j-hc/cmpr/releases/latest/download/cmpr-x86"
104
- dl_if_dne " ${MODULE_TEMPLATE_DIR} /bin/x64/cmpr" " https://github.com/j-hc/cmpr/releases/latest/download/cmpr-x86_64"
95
+ gh_dl " ${MODULE_TEMPLATE_DIR} /bin/arm64/cmpr" " https://github.com/j-hc/cmpr/releases/latest/download/cmpr-arm64-v8a"
96
+ gh_dl " ${MODULE_TEMPLATE_DIR} /bin/arm/cmpr" " https://github.com/j-hc/cmpr/releases/latest/download/cmpr-armeabi-v7a"
97
+ gh_dl " ${MODULE_TEMPLATE_DIR} /bin/x86/cmpr" " https://github.com/j-hc/cmpr/releases/latest/download/cmpr-x86"
98
+ gh_dl " ${MODULE_TEMPLATE_DIR} /bin/x64/cmpr" " https://github.com/j-hc/cmpr/releases/latest/download/cmpr-x86_64"
105
99
}
106
100
107
101
config_update () {
@@ -125,7 +119,8 @@ config_update() {
125
119
fi
126
120
else
127
121
sources[$PATCHES_SRC ]=0
128
- if ! last_patches_url=$( gh_req " https://api.github.com/repos/${PATCHES_SRC} /releases/latest" - 2>&1 | json_get ' browser_download_url' | grep -E ' \.jar$' ) ; then
122
+ if ! last_patches_url=$( gh_req " https://api.github.com/repos/${PATCHES_SRC} /releases/latest" - \
123
+ | jq -e -r ' .assets[] | select(.name | endswith("jar")) | .name' ) ; then
129
124
abort oops
130
125
fi
131
126
last_patches=${last_patches_url##*/ }
@@ -146,21 +141,29 @@ config_update() {
146
141
}
147
142
148
143
_req () {
149
- if [ " $2 " = - ]; then
150
- wget -nv -O " $2 " --header=" $3 " " $1 "
144
+ local ip=" $1 " op=" $2 "
145
+ shift 2
146
+ if [ " $op " = - ]; then
147
+ wget -nv -O " $op " " $@ " " $ip "
151
148
else
152
149
local dlp
153
- dlp=" $( dirname " $2 " ) /tmp.$( basename " $2 " ) "
150
+ dlp=" $( dirname " $op " ) /tmp.$( basename " $op " ) "
154
151
if [ -f " $dlp " ]; then
155
152
while [ -f " $dlp " ]; do sleep 1; done
156
153
return
157
154
fi
158
- wget -nv -O " $dlp " --header=" $3 " " $1 " || return 1
159
- mv -f " $dlp " " $2 "
155
+ wget -nv -O " $dlp " " $@ " " $ip " || return 1
156
+ mv -f " $dlp " " $op "
157
+ fi
158
+ }
159
+ req () { _req " $1 " " $2 " --header=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0" ; }
160
+ gh_req () { _req " $1 " " $2 " --header=" $GH_HEADER " ; }
161
+ gh_dl () {
162
+ if [ ! -f " $1 " ]; then
163
+ pr " Getting '$1 ' from '$2 '"
164
+ _req " $2 " " $1 " --header=" $GH_HEADER " --header=" Accept: application/octet-stream"
160
165
fi
161
166
}
162
- req () { _req " $1 " " $2 " " User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0" ; }
163
- gh_req () { _req " $1 " " $2 " " $GH_HEADER " ; }
164
167
165
168
log () { echo -e " $1 " >> " build.md" ; }
166
169
get_largest_ver () {
@@ -180,7 +183,7 @@ get_patch_last_supported_ver() {
180
183
exc_sel=$( list_args " $3 " | sed ' s/.*/\.name != &/' | paste -sd ' ~' | sed ' s/~/ and /g' || :)
181
184
inc_sel=${inc_sel:- false}
182
185
if [ " $4 " = false ]; then inc_sel=" ${inc_sel} or .use==true" ; fi
183
- if ! vs=$( jq -r " .[]
186
+ if ! vs=$( jq -e - r " .[]
184
187
| select(.compatiblePackages // [] | .[] | .name==\" ${1} \" )
185
188
| select(${inc_sel} )
186
189
| select(${exc_sel:- true} )
@@ -190,17 +193,6 @@ get_patch_last_supported_ver() {
190
193
tr -d ' ,\t[]"' <<< " $vs" | sort -u | grep -v ' ^$' | get_largest_ver || :
191
194
}
192
195
193
- dl_if_dne () {
194
- [ " ${DRYRUN:- } " ] && {
195
- : > " $1 "
196
- return 0
197
- }
198
- if [ ! -f " $1 " ]; then
199
- pr " Getting '$1 ' from '$2 '"
200
- req " $2 " " $1 "
201
- fi
202
- }
203
-
204
196
isoneof () {
205
197
local i=$1 v
206
198
shift
@@ -212,30 +204,30 @@ isoneof() {
212
204
dl_apkmirror () {
213
205
local url=$1 version=${2// / -} output=$3 arch=$4 dpi=$5 apkorbundle=APK
214
206
if [ " $arch " = " arm-v7a" ]; then arch=" armeabi-v7a" ; fi
215
- [ " ${DRYRUN:- } " ] && {
216
- : > " $output "
217
- return 0
218
- }
219
207
local apparch resp node app_table dlurl=" "
220
208
if [ " $arch " = all ]; then
221
209
apparch=(universal noarch ' arm64-v8a + armeabi-v7a' )
222
210
else apparch=(" $arch " universal noarch ' arm64-v8a + armeabi-v7a' ); fi
223
211
url=" ${url} /${url##*/ } -${version// ./ -} -release/"
224
212
resp=$( req " $url " -) || return 1
225
- for (( n = 1 ; n < 40 ; n++ )) ; do
226
- node=$( $HTMLQ " div.table-row.headerFont:nth-last-child($n )" -r " span:nth-child(n+3)" <<< " $resp" )
227
- if [ -z " $node " ]; then break ; fi
228
- app_table=$( $HTMLQ --text --ignore-whitespace <<< " $node" )
229
- if [ " $( sed -n 3p <<< " $app_table" ) " = " $apkorbundle " ] && { [ " $apkorbundle " = BUNDLE ] ||
230
- { [ " $apkorbundle " = APK ] && [ " $( sed -n 6p <<< " $app_table" ) " = " $dpi " ] &&
231
- isoneof " $( sed -n 4p <<< " $app_table" ) " " ${apparch[@]} " ; }; }; then
232
- dlurl=$( $HTMLQ --base https://www.apkmirror.com --attribute href " div:nth-child(1) > a:nth-child(1)" <<< " $node" )
233
- break
234
- fi
235
- done
236
- [ -z " $dlurl " ] && return 1
237
- url=$( req " $dlurl " - | $HTMLQ --base https://www.apkmirror.com --attribute href " a.btn" ) || return 1
238
- if [ " $apkorbundle " = BUNDLE ] && [[ " $url " != * " &forcebaseapk=true" ]]; then url=" ${url} &forcebaseapk=true" ; fi
213
+ node=$( $HTMLQ " div.table-row.headerFont:nth-last-child(1)" -r " span:nth-child(n+3)" <<< " $resp" )
214
+ if [ " $node " ]; then
215
+ for (( n = 1 ; n < 40 ; n++ )) ; do
216
+ node=$( $HTMLQ " div.table-row.headerFont:nth-last-child($n )" -r " span:nth-child(n+3)" <<< " $resp" )
217
+ if [ -z " $node " ]; then break ; fi
218
+ app_table=$( $HTMLQ --text --ignore-whitespace <<< " $node" )
219
+ if [ " $( sed -n 3p <<< " $app_table" ) " = " $apkorbundle " ] && { [ " $apkorbundle " = BUNDLE ] \
220
+ || { [ " $apkorbundle " = APK ] && [ " $( sed -n 6p <<< " $app_table" ) " = " $dpi " ] \
221
+ && isoneof " $( sed -n 4p <<< " $app_table" ) " " ${apparch[@]} " ; }; }; then
222
+ dlurl=$( $HTMLQ --base https://www.apkmirror.com --attribute href " div:nth-child(1) > a:nth-child(1)" <<< " $node" )
223
+ break
224
+ fi
225
+ done
226
+ [ -z " $dlurl " ] && return 1
227
+ resp=$( req " $dlurl " -)
228
+ fi
229
+ url=$( echo " $resp " | $HTMLQ --base https://www.apkmirror.com --attribute href " a.btn" ) || return 1
230
+ if [ " $apkorbundle " = BUNDLE ] && [[ $url != * " &forcebaseapk=true" ]]; then url=" ${url} &forcebaseapk=true" ; fi
239
231
url=$( req " $url " - | $HTMLQ --base https://www.apkmirror.com --attribute href " span > a[rel = nofollow]" ) || return 1
240
232
req " $url " " $output "
241
233
}
@@ -310,15 +302,11 @@ get_archive_pkg_name() { echo "$__ARCHIVE_PKG_NAME__"; }
310
302
311
303
patch_apk () {
312
304
local stock_input=$1 patched_apk=$2 patcher_args=$3 rv_cli_jar=$4 rv_patches_jar=$5
313
- local cmd=" java -jar $rv_cli_jar patch $stock_input -p -o $patched_apk -b $rv_patches_jar \
314
- --keystore=ks.keystore --keystore- entry-password=123456789 --keystore-password=123456789 --signer=jhc --alias=jhc $patcher_args --options=options.json"
305
+ local cmd=" java -jar $rv_cli_jar patch $stock_input -p -o $patched_apk -b $rv_patches_jar $patcher_args --keystore=ks.keystore \
306
+ --keystore- entry-password=123456789 --keystore-password=123456789 --signer=jhc --keystore-entry- alias=jhc --options=options.json"
315
307
if [ " $OS " = Android ]; then cmd+=" --custom-aapt2-binary=${AAPT2} " ; fi
316
308
pr " $cmd "
317
- if [ " ${DRYRUN:- } " = true ]; then
318
- cp -f " $stock_input " " $patched_apk "
319
- else
320
- eval " $cmd "
321
- fi
309
+ eval " $cmd "
322
310
[ -f " $patched_apk " ]
323
311
}
324
312
@@ -471,7 +459,7 @@ build_rv() {
471
459
" ${app_name} ${args[rv_brand]} " \
472
460
" $version " \
473
461
" ${app_name} ${args[rv_brand]} Magisk module" \
474
- " https://raw.githubusercontent.com/${GITHUB_REPOSITORY: - } /update/${upj} " \
462
+ " https://raw.githubusercontent.com/${GITHUB_REPOSITORY-} /update/${upj} " \
475
463
" $base_template "
476
464
477
465
local module_output=" ${app_name_l} -${rv_brand_f} -magisk-v${version_f} -${arch_f} .zip"
0 commit comments