-
Notifications
You must be signed in to change notification settings - Fork 52
/
abuild.in
3005 lines (2643 loc) · 76.1 KB
/
abuild.in
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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/ash -e
# vim: set filetype=sh:
# abuild - build apk packages (light version of makepkg)
# Copyright (c) 2008-2015 Natanael Copa <[email protected]>
# Copyright (c) 2016 Timo Teräs <[email protected]>
#
# Distributed under GPL-2.0-only
#
program_version=@VERSION@
sharedir=${ABUILD_SHAREDIR:-@sharedir@}
abuild_path=$(readlink -f $0)
: ${git:=$(command -v git || echo true)}
export git
if ! [ -f "$sharedir/functions.sh" ]; then
echo "$sharedir/functions.sh: not found" >&2
exit 1
fi
. "$sharedir/functions.sh"
# defaults
: ${FAKEROOT:="fakeroot"}
: ${SUDO_APK:="abuild-apk"}
: ${APK:="apk"}
: ${ADDUSER:="abuild-adduser"}
: ${ADDGROUP:="abuild-addgroup"}
apk_opt_wait="--wait 30"
doc_threshold=$((2 * 1024 * 1024)) # 2 MiB
umask 022
shell_escape() {
printf '%s\n' "'${1//\'/\'\\\'\'}'"
}
# run optional log command for remote logging
logcmd() {
${ABUILD_LOG_CMD:-true} "$@"
return 0
}
# we override the default msg, warning and error as we want the pkgname
msg() {
[ -n "$quiet" ] && return 0
local prompt="$GREEN>>>${NORMAL}"
local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
local name="${STRONG}${subpkgname:-$pkgname}${NORMAL}"
printf "${prompt} ${name}${fake}: %s\n" "$1" >&2
}
warning() {
local prompt="${YELLOW}>>> WARNING:${NORMAL}"
local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
local name="${STRONG}${subpkgname:-$pkgname}${NORMAL}"
printf "${prompt} ${name}${fake}: %s\n" "$1" >&2
}
error() {
local prompt="${RED}>>> ERROR:${NORMAL}"
local fake="${FAKEROOTKEY:+${BLUE}*${NORMAL}}"
local name="${STRONG}${subpkgname:-$pkgname}${NORMAL}"
printf "${prompt} ${name}${fake}: %s\n" "$1" >&2
logcmd "ERROR: $pkgname: $1"
}
amove() {
[ -n "$subpkgdir" ] || return 1
local olddir="$(pwd -L)"
cd "$pkgdir"
local ret=0 IFS="" pattern f d
for pattern; do
for f in ${pattern#"${pattern%%[!/]*}"}; do # let shell expand the pattern
[ -L "$f" ] || [ -e "$f" ] || {
ret=1
continue
}
# strip all trailing /
f=${f%"${f##*[!/]}"}
d=${f%/*}
[ "$d" = "$f" ] && d=.
mkdir -p "$subpkgdir/$d"
mv -v "$f" "$subpkgdir/$d"
rmdir -p "$d" 2>/dev/null || :
done
done
cd "$olddir"
return $ret
}
cross_creating() {
test "$CHOST" != "$CTARGET"
}
cross_compiling() {
test "$CBUILD" != "$CHOST"
}
want_check() {
[ -n "$ABUILD_BOOTSTRAP" ] && return 1
cross_compiling && return 1
options_has "!check" && return 1
return 0
}
set_source_date() {
# dont error out if APKBUILD is not in git
if ! $git rev-parse --show-toplevel >/dev/null 2>&1; then
git=true
fi
# set time stamp for reproducible builds
if [ -z "$ABUILD_LAST_COMMIT" ]; then
ABUILD_LAST_COMMIT="$(git_last_commit)$(git_dirty)"
fi
if [ -z "$SOURCE_DATE_EPOCH" ] && [ "${ABUILD_LAST_COMMIT%-dirty}" = "$ABUILD_LAST_COMMIT" ]; then
SOURCE_DATE_EPOCH=$(git_last_commit_epoch $ABUILD_LAST_COMMIT)
fi
if [ -z "$SOURCE_DATE_EPOCH" ]; then
SOURCE_DATE_EPOCH=$(stat -c "%Y" "$APKBUILD")
fi
export SOURCE_DATE_EPOCH ABUILD_LAST_COMMIT
}
default_cleanup_srcdir() {
if options_has "chmod-clean" && test -d "$srcdir"; then
chmod -R +w "$srcdir"
fi
rm -rf "$srcdir"
}
cleanup_srcdir() {
default_cleanup_srcdir
}
cleanup() {
local i=
[ -z "$subpkgdir" ] && set_xterm_title ""
if [ -n "$keep_build" ]; then
return 0
fi
for i; do
case $i in
bldroot)
if [ "$BUILD_ROOT" ]; then
msg "Cleaning up build chroot"
abuild-rmtemp "$BUILD_ROOT"
fi;;
pkgdir) msg "Cleaning up pkgdir"; rm -rf "$pkgbasedir";;
srcdir) msg "Cleaning up srcdir"; cleanup_srcdir;;
tmpdir) msg "Cleaning up tmpdir"; rm -rf "$tmpdir";;
deps)
if [ -n "$uninstall_after" ]; then
msg "Uninstalling dependencies..."
undeps
fi
;;
esac
done
}
die() {
trap - EXIT
error "$@"
cleanup $ERROR_CLEANUP
exit 1
}
spell_error() {
die "APKBUILD contains '$1'. It should be '$2'"
}
verify_pkgname() {
case $1 in
''|*[!a-zA-Z0-9._+-]*|[!a-zA-Z0-9]*) return 1;;
esac
return 0
}
# check if apkbuild is valid
default_validate() {
local i= j=
msg "Validating $APKBUILD..."
[ -z "$pkgver" ] && die "Missing pkgver in APKBUILD"
$APK version --check --quiet -- "$pkgver"-r0 || \
die "$pkgver is not a valid version"
[ -z "$pkgrel" ] && die "Missing pkgrel in APKBUILD"
# give 0 as it is always valid and give the pkgrel
$APK version --check --quiet 0-r"$pkgrel" || \
die "$pkgrel is not a valid pkgrel"
# digit+letter+digit passes the apk2 version check
case $pkgver in
*[0-9][a-z][0-9]*)
die "the digit+letter+digit version format is invalid. Use suffixes instead"
;;
esac
[ -z "$pkgdesc" ] && die "Missing pkgdesc in APKBUILD"
[ -z "$url" ] && die "Missing url in APKBUILD"
[ -z "$license" ] && die "Missing license in APKBUILD"
if [ $(echo "$pkgdesc" | wc -c) -gt 128 ]; then
die "pkgdesc is too long"
fi
if [ $(echo "$pkgdesc" | wc -l) -gt 1 ]; then
die "pkgdesc is not a single line"
fi
is_function package || die "Missing package() function in APKBUILD"
if [ -n "$replaces_priority" ] \
&& ! echo $replaces_priority | grep -E -q '^[0-9]+$'; then
die "replaces_priority must be a number"
fi
if [ -n "$provider_priority" ] \
&& ! echo $provider_priority | grep -E -q '^[0-9]+$'; then
die "provider_priority must be a number"
fi
# check pkgname and subpkgnames
for i in "$pkgname" $subpackages; do
verify_pkgname "${i%%:*}" || die "${i%%:*} is not a valid package name"
done
# check dependencies
for i in $depends $makedepends; do
check_depver "$i" || return 1
done
for i in $install; do
local n=${i%.*}
local suff=${i##*.}
case "$suff" in
pre-install|post-install|pre-upgrade|post-upgrade|pre-deinstall|post-deinstall);;
*) die "$i: unknown install script suffix"
esac
if ! subpackages_has "$n" && [ "$n" != "$pkgname" ]; then
die "$i: install script does not match pkgname or any subpackage"
fi
[ -e "$startdir/$i" ] || die "install script $i is missing"
for j in chown chmod chgrp; do
if grep -q $j "$startdir"/$i; then
warning "$i: found $j"
warning2 "Permissions should be fixed in APKBUILD package()"
fi
done
done
for i in $triggers; do
local f=${i%=*}
local p=${f%.trigger}
[ "$f" = "$i" ] && die "$f: triggers must contain '='"
[ "$p" = "$f" ] && die "$f: triggers scripts must have .trigger suffix"
if ! subpackages_has "$p" && [ "$p" != "$pkgname" ]; then
die "$p: trigger script does not match pkgname or any subpackage"
fi
if source_has "$f"; then
warning "You should not have \$triggers in source"
continue
fi
[ -e "$startdir"/$f ] || die "trigger script $f is missing"
done
for i in $source; do
if install_has "$i"; then
warning "You should not have \$install in source"
continue
fi
case "$i" in
*::*) i=${i%%::*};;
https://*) makedepends_has wget && warning "wget no longer need to be in makedepends when source has https://" ;;
esac
list_has ${i##*/} $sha256sums $sha512sums \
|| die "${i##*/} is missing in checksums"
# verify that our source does not have git tag version
# name as tarball (typically github)
if is_remote "$i" && [ "${i#*::}" = "$i" ]; then
case ${i##*/} in
v$pkgver.tar.*|$pkgver.tar.*)
die "source ${i##*/} needs to be renamed to avoid possible collisions"
;;
esac
fi
done
# verify that things listed in checksum also is listed in source
local algo=
for algo in sha256 sha512; do
eval set -- \$${algo}sums
while [ $# -gt 1 ]; do
local file="$2"
shift 2
source_has $file || die "$file exists in ${algo}sums but is missing in \$source"
done
done
# common spelling errors
[ -n "$depend" ] && spell_error depend depends
[ -n "$makedepend" ] && spell_error makedepend makedepends
[ -n "$pkguser" ] && spell_error pkguser pkgusers
[ -n "$pkggroup" ] && spell_error pkggroup pkggroups
[ -n "$subpackage" ] && spell_error subpackage subpackages
[ -n "$checkdepend" ] && spell_error checkdepend checkdepends
[ -n "$conflicts" ] && die "APKBUILD contains \$conflicts. Explicit conflicts should be added as '!pkgname' to depends"
check_maintainer || die "Provide a valid RFC822 maintainer address"
[ $(grep '^# *Maintainer:' "$APKBUILD" | wc -l) -gt 1 ] \
&& die "More than one maintainer"
check_license || warning "Please use valid SPDX license identifiers found at: https://spdx.org/licenses"
check_depends_dev || warning "depends_dev found but no development subpackage found"
check_secfixes_comment || return 1
makedepends_has 'g++' && ! options_has toolchain && warning "g++ should not be in makedepends"
if makedepends_has 'go' && ! options_has 'net'; then
warning "Go packages require network connection to build. Maybe add 'net' to options"
fi
if ! options_has "!check" && [ -n "$REQUIRE_CHECK" ]; then
(unset check; . "$APKBUILD"; type check >/dev/null 2>&1) || \
die "Testsuites (abuild check) are required or need to be explicitly disabled!"
fi
check_provides || die "provides must not contain $pkgname"
return 0
}
validate() {
default_validate
}
# for backwards compat
sanitycheck() {
warning "'sanitycheck' is renamed. Use 'validate' instead."
}
sumcheck() {
local algo="$1" sums="$2"
local f endreturnval origin csum file
# get number of checksums
set -- $sums
local numsums=$(( $# / 2 ))
set -- $source
if [ $# -ne $numsums ]; then
die "Number of ${algo}sums($numsums) does not correspond to number of sources($#)"
fi
fetch || return 1
msg "Checking ${algo}sums..."
cd "$srcdir" || return 1
local IFS=$'\n'
endreturnval=0
for src in $sums; do
origin=$1; shift
if ! echo "$src" | ${algo}sum -c; then
endreturnval=1
is_remote $origin || continue
csum="${src:0:8}"
file="$SRCDEST/$(filename_from_uri $origin)"
echo "Because the remote file above failed the ${algo}sum check it will be renamed."
echo "Rebuilding will cause it to re-download which in some cases may fix the problem."
echo "Renaming: ${file##*/} to ${file##*/}.$csum"
mv "$file" "$file.$csum"
fi
done
return $endreturnval
}
# verify checksums
verify() {
local verified=false algo=
for algo in sha512 sha256; do
local sums=
eval sums=\"\$${algo}sums\"
if [ -z "$sums" ] || [ -z "$source" ]; then
continue
fi
sumcheck "$algo" "$sums" || return 1
verified=true
break
done
if [ -n "$source" ] && ! $verified; then
die "Use 'abuild checksum' to generate/update the checksum(s)"
fi
return 0
}
# verify upstream sources
sourcecheck() {
local uri
for uri in $source; do
is_remote $uri || continue
case "$uri" in
*::*)
uri=${uri##*::}
;;
esac
wget --spider -q "$uri" || return 1
done
return 0
}
uri_fetch() {
local uri="$1"
mkdir -p "$SRCDEST"
msg "Fetching $uri"
abuild-fetch -d "$SRCDEST" "$uri"
}
is_remote() {
case "${1#*::}" in
http://*|ftp://*|https://*)
return 0;;
esac
return 1
}
filename_from_uri() {
local uri="$1"
local filename="${uri##*/}" # $(basename $uri)
case "$uri" in
*::*) filename=${uri%%::*};;
esac
echo "$filename"
}
# try download from file from mirror first
uri_fetch_mirror() {
local uri="$1"
if [ -n "$DISTFILES_MIRROR" ]; then
if is_remote "$DISTFILES_MIRROR"; then
uri_fetch "$DISTFILES_MIRROR"/$(filename_from_uri $uri)\
&& return 0
else
cp "$DISTFILES_MIRROR"/$(filename_from_uri $uri) \
"$SRCDEST" && return 0
fi
fi
uri_fetch "$uri"
}
symlinksrc() {
local s
mkdir -p "$srcdir"
for s in $source; do
if is_remote "$s"; then
ln -sf "$SRCDEST/$(filename_from_uri $s)" "$srcdir"/
else
ln -sf "$startdir/$s" "$srcdir/"
fi
done
}
default_fetch() {
local s
mkdir -p "$srcdir"
for s in $source; do
if is_remote "$s"; then
uri_fetch_mirror "$s" || return 1
ln -sf "$SRCDEST/$(filename_from_uri $s)" "$srcdir"/
else
ln -sf "$startdir/$s" "$srcdir/"
fi
done
}
fetch() {
default_fetch
}
# verify that all init.d scripts are openrc runscripts
initdcheck() {
local i line
for i in $source; do
case $i in
*.initd)
line=$(head -n 1 "$srcdir"/"$(filename_from_uri $i)")
;;
*) continue ;;
esac
case "$line" in
*sbin/openrc-run)
;;
*sbin/runscript)
warning "$i is not an openrc #!/sbin/openrc-run"
;;
*) error "$i is not an openrc #!/sbin/openrc-run"
return 1
;;
esac
done
}
# unpack the sources
default_unpack() {
local u gunzip
verify || return 1
initdcheck || return 1
mkdir -p "$srcdir"
gunzip=$(command -v pigz || echo gunzip)
[ $gunzip = "/usr/bin/pigz" ] && gunzip="$gunzip -d"
for u in $source; do
local s
if is_remote "$u"; then
s="$SRCDEST/$(filename_from_uri $u)"
else
s="$startdir/$u"
fi
case "$s" in
*.tar)
msg "Unpacking $s..."
tar -C "$srcdir" -xf "$s" || return 1;;
*.tar.gz|*.tgz)
msg "Unpacking $s..."
$gunzip -c "$s" | tar -C "$srcdir" -x || return 1;;
*.tar.bz2)
msg "Unpacking $s..."
tar -C "$srcdir" -jxf "$s" || return 1;;
*.tar.lz)
msg "Unpacking $s..."
tar -C "$srcdir" --lzip -xf "$s" || return 1;;
*.tar.lzma)
msg "Unpacking $s..."
unlzma -T 0 -c "$s" | tar -C "$srcdir" -x \
|| return 1;;
*.tar.xz)
msg "Unpacking $s..."
local threads_opt
if [ $(readlink -f $(command -v unxz)) != "/bin/busybox" ]; then
threads_opt="--threads=0"
fi
unxz $threads_opt -c "$s" | tar -C "$srcdir" -x || return 1;;
*.tar.zst)
msg "Unpacking $s..."
tar -C "$srcdir" --zstd -xf "$s" || return 1;;
*.zip)
msg "Unpacking $s..."
unzip -n -q "$s" -d "$srcdir" || return 1;;
esac
done
}
unpack() {
default_unpack
}
# cleanup source, package and temporary dir
clean() {
cleanup srcdir
cleanup pkgdir
cleanup tmpdir
}
# cleanup fetched sources
cleancache() {
local s
for s in $source; do
if is_remote "$s"; then
s=$(filename_from_uri $s)
msg "Cleaning downloaded $s ..."
rm -f "$SRCDEST/$s"
fi
done
}
subpkg_unset() {
unset subpkgname subpkgsplit subpkgarch
}
subpkg_set() {
subpkgname=${1%%:*}
local _splitarch=${1#*:}
[ "$_splitarch" = "$1" ] && _splitarch=""
subpkgsplit=${_splitarch%%:*}
if [ -z "$subpkgsplit" ]; then
case $subpkgname in
*-bash-completion) subpkgsplit=bashcomp ;;
*-zsh-completion) subpkgsplit=zshcomp ;;
*-fish-completion) subpkgsplit=fishcomp ;;
*) subpkgsplit="${subpkgname##*-}" ;;
esac
fi
subpkgarch=${_splitarch#*:}
if [ "$subpkgarch" = "$_splitarch" -o -z "$subpkgarch" ]; then
case "$subpkgname" in
*-doc | *-openrc | *-lang | *sh-completion | *-pyc) subpkgarch="noarch" ;;
*) subpkgarch="$pkgarch" ;;
esac
fi
}
arch2dir() {
local arch="$1"
[ "$arch" = "noarch" -o "$arch" = "all" ] && arch="$CARCH"
printf '%s\n' "$arch"
}
cleanpkg() {
local i
msg "Cleaning built packages..."
rm -f "$REPODEST/$repo/src/$pkgname-$pkgver-r$pkgrel.src.tar.gz"
for i in $allpackages; do
subpkg_set "$i"
rm -f "$REPODEST/$repo/$(arch2dir "$subpkgarch")/$subpkgname-$pkgver-r$pkgrel.apk"
done
subpkg_unset
# remove given packages from index
update_abuildrepo_index
}
# clean all packages except current
cleanoldpkg() {
local i j
msg "Cleaning all packages except $pkgver-r$pkgrel..."
for i in $allpackages; do
subpkg_set "$i"
for j in "$REPODEST"/$repo/$CARCH/$subpkgname-[0-9]*.apk ; do
[ "${j##*/}" = "$subpkgname-$pkgver-r$pkgrel.apk" ] \
&& continue
rm -f "$j"
done
done
subpkg_unset
update_abuildrepo_index
return 0
}
mkusers() {
local i
for i in $pkggroups; do
if ! getent group $i >/dev/null; then
msg "Creating group $i"
$ADDGROUP -S $i || return 1
fi
done
for i in $pkgusers; do
if ! getent passwd $i >/dev/null; then
local gopt=
msg "Creating user $i"
if getent group $i >/dev/null; then
gopt="-G $i"
fi
$ADDUSER -S -D -H $gopt $i || return 1
fi
done
}
# helper to update config.sub to a recent version
update_config_sub() {
find . -name config.sub | (local changed=false; while read f; do
if ! ./$f loongarch64-alpine-linux-musl 2>/dev/null; then
msg "Updating $f"
cp "$sharedir"/${f##*/} "$f" || return 1
changed=true
else
msg "No update needed for $f"
fi
done; $changed)
}
# helper to update config.guess to a recent version
update_config_guess() {
find . -name config.guess | (local changed=false; while read f; do
if grep -q aarch64 "$f" && grep -q ppc64le "$f" && grep -q riscv64 "$f" && grep -q loongarch64 "$f"; then
msg "No update needed for $f"
else
msg "Updating $f"
cp "$sharedir"/${f##*/} "$f" || return 1
changed=true
fi
done; $changed)
}
runpart() {
local part=$1
[ -n "$DEBUG" ] && msg "$part"
trap "die '$part failed'" EXIT
if [ -d "$builddir" ]; then
case "$part" in
prepare|build|package|check)
# exclude aports from git repo discovery
export GIT_CEILING_DIRECTORIES="$startdir"
# prevent using global cache directories
if [ -n "$MOVE_CACHES" ]; then
export GOCACHE="${GOCACHE:-"$tmpdir/go"}"
export GOMODCACHE="${GOCACHE:-"$tmpdir/gomod"}"
export GOTMPDIR="${GOTMPDIR:-"$tmpdir"}"
# https://github.com/golang/go/issues/32320
mkdir -p "$GOTMPDIR"
export CARGO_HOME="${CARGO_HOME:-"$tmpdir/cargo"}"
fi
cd "$builddir"
;;
esac
fi
$part
trap - EXIT
}
have_patches() {
local i
for i in $source; do
case ${i%::*} in
*.patch|*.patch.gz|*.patch.xz) return 0;;
esac
done
return 1
}
default_prepare() {
local i failed=
[ -n "$builddir" -a -d "$builddir" ] && cd "$builddir"
if ! have_patches; then
return 0
fi
[ -d "$builddir" ] || { error "Is \$builddir set correctly?"; return 1; }
for i in $source; do
case ${i%::*} in
*.patch)
msg "${i%::*}"
patch ${patch_args:--p1} -i "$srcdir/$(filename_from_uri $i)" || failed="$failed $i"
;;
*.patch.gz)
msg "${i%::*}"
gunzip -c "$srcdir/$(filename_from_uri $i)" | patch ${patch_args:--p1} || failed="$failed $i"
;;
*.patch.xz)
msg "${i%::*}"
unxz -c "$srcdir/$(filename_from_uri $i)" | patch ${patch_args:--p1} || failed="$failed $i"
;;
esac
done
if [ -z "$failed" ]; then
return 0
fi
error "The following patches failed to apply:"
for i in $failed; do
printf " %s\n" "$i" >&2
done
return 1
}
prepare() {
default_prepare
}
build() {
:
}
# generate a simple tar.gz package of pkgdir
targz() {
cd "$pkgdir" || return 1
mkdir -p "$REPODEST"/src
tar -czf "$REPODEST"/src/$pkgname-$pkgver-r$pkgrel.tar.gz *
}
postcheck() {
local dir="$1" name="$2" i= j= e=0
msg "Running postcheck for $name"
# checking for FHS compat
if ! options_has "!fhs"; then
for i in srv usr/local opt tmp var/tmp var/lock var/empty home sys proc mnt dev; do
for j in "$dir"/"$i"/* "$dir"/"$i"/.[!.]* "$dir"/"$i"/..?*; do
if [ -L "$j" ] || [ -e "$j" ]; then
error "Packages must not put anything under /$i"
e=1
break
fi
done
done
if [ -d "$dir"/usr/var ]; then
error "Found /usr/var, localstatedir is most likely wrong"
e=1
fi
fi
# Alpine Linux as a musl libc distro does not use /lib64 or /usr/lib64 under
# any circumstance, packages installing to it are 100% sure a packaging error
# except when we are doing GNU Libc compatibility which should be rare enough
# to warrant a lib64 check
if ! options_has "lib64"; then
if [ -e "$dir"/lib64 ]; then
error "Packages must not put anything under /lib64, use /usr/lib instead"
e=1
elif [ -e "$dir"/usr/lib64 ]; then
error "Packages must not put anything under /usr/lib64, use /usr/lib instead"
e=1
fi
fi
# /usr merge
if ! options_has "!usrmerge"; then
for i in bin sbin lib; do
if [ -L "$dir"/$i ] || [ -e "$dir"/$i ]; then
warning "Packages must not put anything under /$i, use /usr/${i##*s} instead"
fi
done
fi
# remove *.la files if libtool is not set
if ! options_has "libtool"; then
find "$dir" -name '*.la' -type f -delete
fi
# look for /usr/lib/charset.alias
if [ -e "$dir"/usr/lib/charset.alias ] \
&& ! options_has "charset.alias"; then
error "Found /usr/lib/charset.alias"
e=1
fi
# look for /etc/init.d and /etc/conf.d
if [ -e "$dir"/etc/init.d -o -e "$dir"/etc/conf.d ] \
&& ! is_openrc_pkg "$name"; then
warning "Found OpenRC directory (/etc/conf.d or /etc/init.d) but name doesn't end with -openrc"
fi
# look for /usr/share/doc
if [ -e "$dir"/usr/share/doc ] \
&& ! is_doc_pkg "$name"; then
warning "Found /usr/share/doc but package name doesn't end with -doc"
fi
# look for /usr/share/devhelp
if [ -e "$dir"/usr/share/devhelp ] \
&& ! is_devhelp_pkg "$name"; then
warning "Found /usr/share/devhelp but package name doesn't end with -devhelp"
fi
# look for /usr/share/man
if [ -e "$dir"/usr/share/man ]; then
if ! is_doc_pkg "$name"; then
warning "Found /usr/share/man but package name doesn't end with -doc"
fi
# check for uncompressed man pages
i=$(find "$dir"/usr/share/man -name '*.[0-8]' -type f | sed -e 's/^/\t/')
if [ -n "$i" ]; then
error "Found uncompressed man pages:"
echo "$i"
e=1
fi
fi
# look for pycache
# wildcard should always get the system python dir, and this is faster than
# trying to calculate the python version.
i="$(find "$dir"/usr/lib/python* \( -type d -a -name "__pycache__" \) 2>/dev/null || :)"
if [ -n "$i" ] && [ "${name%-pyc}" = "$name" ]; then
warning "Found __pycache__ but package name doesn't end with -pyc"
fi
# check that we don't have any files names with newline
i=$(find "$dir" -name $'*\n*')
if [ -n "$i" ]; then
error "Found filenames with newline:"
echo "$i" >&2
e=1
fi
# check directory permissions
i=$(find "$dir" -type d -perm -777 | sed -e 's/^/\t/')
if [ -n "$i" ]; then
warning "World writeable directories found:"
echo "$i"
fi
# check so we dont have any suid root binaries that are not PIE
i=$(find "$dir" -type f -perm /6000 \
| xargs scanelf --nobanner --etype ET_EXEC \
| sed -e 's/ET_EXEC /\t/')
if [ -n "$i" ]; then
warning "Found non-PIE files that have SUID:"
echo "$i"
warning "suid executables SHOULD be compiled with PIE if possible"
fi
# test suid bit on executable
if ! options_has "suid"; then
i=$(find "$dir" \( -perm -u+s -o -perm -g+s \) -a -type f \
-a -perm -o+x)
if [ -n "$i" ]; then
error "Found executable files with SUID bit set:"
echo "$i"
e=1
fi
fi
# test capabilities on executables
# see: https://gitlab.alpinelinux.org/alpine/tsc/-/issues/45
getcap -r "$dir" | (local r=true execothers; while read -r line; do
local filename="${line% *}"
if ! options_has "setcap"; then
error "Found binary with extra capabilities: $filename"
r=false
fi
execothers="$(find "$filename" -perm -o+x)"
if [ -n "$execothers" ]; then
warning "Found setcap binary executable by others: $filename"
fi
done; $r) || e=1
# test for textrels
if ! options_has "textrels"; then
local res
res="$(scanelf --recursive --textrel --quiet "$dir")"
if [ -n "$res" ]; then
error "Found textrels:"
echo "$res"
e=1
fi
fi
return $e
}
pre_split() {
if [ -z "$subpkgname" ]; then
return 0
fi
# the subpackages should not inherit these from main package
provides=""
install_if=""
}
prepare_subpackages() {
local i
cd "$startdir"
for i in $subpackages; do
# call abuild recursively, setting subpkg{dir,name}
( subpkg_set "$i"; msg "Running split function $subpkgsplit..."; \
subpkgdir="$pkgbasedir/$subpkgname" subpkgname="$subpkgname" subpkgarch="$subpkgarch" \
"$abuild_path" $forceroot $verbose pre_split $subpkgsplit prepare_package \
&& postcheck "$pkgbasedir/$subpkgname" "$subpkgname" ) || return 1
done
postcheck "$pkgdir" "$pkgname" || return 1
# post check for /usr/share/locale
if [ -d "$pkgdir"/usr/share/locale ]; then
warning "Found /usr/share/locale"
warning2 "Maybe add \$pkgname-lang to subpackages?"
fi
# post check for shell completions
if [ -d "$pkgdir"/usr/share/bash-completion ]; then
warning "Found /usr/share/bash-completion"
warning2 "Add \$pkgname-bash-completion to subpackages"
fi
if [ -d "$pkgdir"/usr/share/zsh/site-functions ]; then
warning "Found /usr/share/zsh/site-functions"
warning2 "Add \$pkgname-zsh-completion to subpackages"
fi
if [ -d "$pkgdir"/usr/share/fish/completions ]; then
warning "Found /usr/share/fish/completions"
warning2 "fish completions for programs should be located in /usr/share/fish/vendor_completions.d"
fi
if [ -d "$pkgdir"/usr/share/fish/vendor_completions.d ]; then
warning "Found /usr/share/fish/completions"
warning2 "Add \$pkgname-fish-completion to subpackages"
fi
}
default_lang() {
pkgdesc="Languages for package $pkgname"
install_if="$pkgname=$pkgver-r$pkgrel lang"
depends="$depends_lang"
amove ${langdir:-/usr/share/locale}
}
lang() {
default_lang
}
# echo '-dirty' if git is not clean
git_dirty() {
[ $($git status -s -- "$startdir" | wc -l) -eq 0 ] || echo "-dirty"
}
# echo last commit hash id
git_last_commit() {
$git rev-list -n 1 HEAD -- "$startdir"
}
# date of last commit
git_last_commit_epoch() {
$git log -1 --format=%cd --date=unix $1 -- "$startdir"
}
get_maintainer() {
if [ -z "$maintainer" ]; then
maintainer=$(awk -F': ' '/# *Maintainer/ {print $2}' "$APKBUILD")