-
Notifications
You must be signed in to change notification settings - Fork 1
/
update-local-repo
executable file
·466 lines (327 loc) · 9.67 KB
/
update-local-repo
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
#!/bin/bash
set -e
base_dir="$(dirname "$(readlink -f "$0")")"
source "$base_dir/global"
error() {
>&2 echo "Error:" "$@"
exit 1
}
### Releases
curl_gh() {
local token_file="$base_dir/github-oauth-token"
if [[ -f "$token_file" ]]; then
curl -H "Authorization: token $( cat "$token_file" )" "$@"
else
curl "$@"
fi
}
query_releases_once() {
local user="$1"
local repo="$2"
#>&2 echo -n "Querying releases... "
local releases=""
local page
for (( page = 1; ; page++ )); do
local release_page="$( curl_gh -sfL "https://api.github.com/repos/$user/$repo/releases?page=$page" )"
release_page="$( jq '.[]' <<< "$release_page" )"
[[ "$release_page" == "" ]] && break
releases="$releases$release_page"
done
>&2 echo "$(( page - 1 )) page(s)"
#>&2 echo
printf '%s' "$releases"
}
query_releases() {
local user="$1"
local repo="$2"
local verify_releases=true
>&2 echo -n "Querying releases... "
local releases="$( query_releases_once "$user" "$repo" )"
while $verify_releases; do
>&2 echo -n "Verifying releases... "
local releases2="$( query_releases_once "$user" "$repo" )"
[[ "$releases" == "$releases2" ]] && break
releases="$releases2"
done
>&2 echo
printf '%s' "$releases"
}
process_releases() {
local releases="$1"
local release_processor="$2"
local ids=( $( jq '.id' <<< "$releases" ) )
for id in ${ids[@]}; do
local release="$( jq "select((.id == $id) and (.assets | length > 0))" <<< "$releases" )"
if [[ "$release" != "" ]]; then
local tag="$( jq -r '.tag_name' <<< "$release" )"
local prerelease="$( jq -r '.prerelease' <<< "$release" )"
"$release_processor" "$release" "$tag" "$prerelease"
fi
done
}
process_repo() {
local user="$1"
local repo="$2"
local release_processor="$3"
local releases="$( query_releases "$user" "$repo" )"
process_releases "$releases" "$release_processor"
}
### Maven
add_checksums() {
local file="$1"
local md5=( $( md5sum -b "$file" ) )
printf '%s' "$md5" >"$file.md5"
local sha1=( $( sha1sum -b "$file" ) )
printf '%s' "$sha1" >"$file.sha1"
}
download_asset() {
if [[ -f "$file" ]]; then
local size="$( jq '.size' <<< "$asset" )"
if (( size != $( stat --printf '%s' "$file" ) )); then
error "Remote and local asset size mismatch"
fi
echo "Asset '$( basename "$file" )' already downloaded"
else
local url="$( jq -r '.browser_download_url' <<< "$asset" )"
mkdir -p "$(dirname "$file")"
curl_gh -#fL --output "$file" "$url"
fi
add_checksums "$file"
}
process_asset() {
local asset_count="$( jq -s 'length' <<< "$asset" )"
if (( $asset_count == 0 )); then error "No asset found"; fi
if (( $asset_count > 1 )); then error "Multiple assets found"; fi
download_asset
}
html_escape () {
local s="$1"
s="${s//&/&}"
s="${s//</<}"
s="${s//>/>}"
s="${s//'"'/"}"
printf '%s' "$s"
}
create_pom() {
local file="$group_dir/$artifact/$version/$artifact-$version.pom"
local uploader="$( jq -r '.uploader.login' <<< "$asset" )"
cat >"$file" <<__EOF__
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>$group</groupId>
<artifactId>$artifact</artifactId>
<version>$version</version>
<url>https://github.com/$user/$repo</url>
<organization>
<name>DexPatcher</name>
<url>https://dexpatcher.github.io/</url>
</organization>
<developers>
<developer>
<id>$uploader</id>
<url>https://github.com/$uploader</url>
</developer>
</developers>
<scm>
<url>https://github.com/$user/$repo</url>
</scm>
</project>
__EOF__
add_checksums "$file"
}
create_metadata() {
local file="$group_dir/$artifact/maven-metadata.xml"
cat >"$file" <<__EOF__
<?xml version="1.0" encoding="UTF-8"?>
<metadata
xmlns="http://maven.apache.org/METADATA/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/METADATA/1.1.0 http://maven.apache.org/xsd/repository-metadata-1.1.0.xsd"
modelVersion="1.1.0">
<groupId>$group</groupId>
<artifactId>$artifact</artifactId>
<versioning>
<latest>${versions[-1]}</latest>
<release>${release_versions[-1]}</release>
<versions>
__EOF__
local version
for version in "${versions[@]}"; do
cat >>"$file" <<__EOF__
<version>$version</version>
__EOF__
done
cat >>"$file" <<__EOF__
</versions>
__EOF__
#<lastUpdated>20190613143244</lastUpdated>
cat >>"$file" <<__EOF__
</versioning>
</metadata>
__EOF__
add_checksums "$file"
}
setup_repo() {
echo
echo "### $user/$repo ###"
echo
group_dir="$repo_dir/${group//.//}"
versions=()
release_versions=()
}
setup_version() {
versions=( "$version" "${versions[@]}" )
if [[ "$prerelease" == 'false' ]]; then
release_versions=( "$version" "${release_versions[@]}" )
echo "Version: $version"
else
echo "Version: $version (pre-release)"
fi
}
finish_repo() {
create_metadata
echo
}
### Apktool
process_apktool_release() {
release="$1"
tag="$2"
prerelease="$3"
version="${tag#v}"
setup_version
asset="$( jq ".assets[] | select(.name == \"apktool_$version.jar\")" <<< "$release" )"
file="$group_dir/$artifact/$version/$artifact-$version.jar"
process_asset
create_pom
# apktool-aapt(2)
aapt="$base_dir/build/apktool-aapt.jar"
aapt2="$base_dir/build/apktool-aapt2.jar"
mkdir -p "$base_dir/build"
rm -f "$aapt" "$aapt2"
"$base_dir/pack_aapt_and_aapt2" "$file" "$version" "$aapt" "$aapt2"
main_artifact="$artifact"
if [[ -f "$aapt" ]]; then
aapt_versions=( "$version" "${aapt_versions[@]}" )
if [[ "$prerelease" == 'false' ]]; then
aapt_release_versions=( "$version" "${aapt_release_versions[@]}" )
fi
artifact="apktool-aapt"
file="$group_dir/$artifact/$version/$artifact-$version.jar"
mkdir -p "$( dirname "$file" )"
rm -f "$file"
mv -T "$aapt" "$file"
add_checksums "$file"
create_pom
fi
if [[ -f "$aapt2" ]]; then
aapt2_versions=( "$version" "${aapt2_versions[@]}" )
if [[ "$prerelease" == 'false' ]]; then
aapt2_release_versions=( "$version" "${aapt2_release_versions[@]}" )
fi
artifact="apktool-aapt2"
file="$group_dir/$artifact/$version/$artifact-$version.jar"
mkdir -p "$( dirname "$file" )"
rm -f "$file"
mv -T "$aapt2" "$file"
add_checksums "$file"
create_pom
fi
artifact="$main_artifact"
}
process_apktool_repo() {
user="iBotPeaches"
repo="Apktool"
group="dexpatcher-repo.ibotpeaches.apktool"
artifact="apktool"
setup_repo
aapt_versions=()
aapt_release_versions=()
aapt2_versions=()
aapt2_release_versions=()
process_repo "$user" "$repo" process_apktool_release
finish_repo
# apktool-aapt(2)
main_artifact="$artifact"
main_versions=( "${versions[@]}" )
main_release_versions=( "${release_versions[@]}" )
artifact="apktool-aapt"
versions=( "${aapt_versions[@]}" )
release_versions=( "${aapt_release_versions[@]}" )
create_metadata
artifact="apktool-aapt2"
versions=( "${aapt2_versions[@]}" )
release_versions=( "${aapt2_release_versions[@]}" )
create_metadata
artifact="$main_artifact"
versions=( "${main_versions[@]}" )
release_versions=( "${main_release_versions[@]}" )
}
### dex2jar
process_dex2jar_release() {
release="$1"
tag="$2"
prerelease="$3"
version="${tag#v}"
setup_version
asset="$( jq ".assets[] | select(.name == \"dex-tools-$version.zip\")" <<< "$release" )"
file="$group_dir/$artifact/$version/$artifact-$version.zip"
process_asset
create_pom
}
process_dex2jar_repo() {
user="DexPatcher"
repo="dex2jar"
group="dexpatcher-repo.dexpatcher.dex2jar"
artifact="dex-tools"
setup_repo
process_repo "$user" "$repo" process_dex2jar_release
finish_repo
}
### DexPatcher
process_dexpatcher_release() {
release="$1"
tag="$2"
prerelease="$3"
version="${tag#v}"
setup_version
asset="$( jq ".assets[] | select(.name == \"dexpatcher-$version.jar\")" <<< "$release" )"
file="$group_dir/$artifact/$version/$artifact-$version.jar"
process_asset
create_pom
# dexpatcher-annotation
jar_file="$file"
main_artifact="$artifact"
artifact="dexpatcher-annotation"
file="$group_dir/$artifact/$version/$artifact-$version.jar"
mkdir -p "$( dirname "$file" )"
rm -f "$file"
unzip -q -d "$( dirname "$file" )" "$jar_file" "$( basename "$file" )" >/dev/null
add_checksums "$file"
create_pom
artifact="$main_artifact"
}
process_dexpatcher_repo() {
user="DexPatcher"
repo="dexpatcher-tool"
group="dexpatcher-repo.dexpatcher.dexpatcher-tool"
artifact="dexpatcher"
setup_repo
process_repo "$user" "$repo" process_dexpatcher_release
finish_repo
# dexpatcher-annotation
main_artifact="$artifact"
artifact="dexpatcher-annotation"
create_metadata
artifact="$main_artifact"
}
### Main
process_all_repos() {
process_apktool_repo
process_dex2jar_repo
process_dexpatcher_repo
}
process_all_repos