-
Notifications
You must be signed in to change notification settings - Fork 2
/
gentoo-build-svc.docker
executable file
·2121 lines (1971 loc) · 63.7 KB
/
gentoo-build-svc.docker
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
#! /usr/bin/env bash
declare trace="${TRACE:-}"
# shellcheck disable=SC2034
#declare debug="${DEBUG:-}"
set -eu
set -o pipefail
cd "$( dirname "$( readlink -e "${0}" )" )" || exit 1
#(( trace )) && set -o xtrace
# Set in vars.sh
#
#declare build_name=''
#declare base_dir=''
#declare use_essential=''
#declare use_essential_gcc=''
#declare python_default_target=''
# Set in run.sh
#
#declare docker='docker'
#declare docker_readonly=''
#declare environment_file=''
#declare environment_filter=''
#
#declare red=''
#declare blue=''
#declare reset=''
# Redefined by common/local.sh, sourced by common/vars.sh
#declare mail_domain='localhost'
#declare mail_mta='localhost'
# shellcheck disable=SC1091
[[ ! -s common/vars.sh ]] || . common/vars.sh
# shellcheck disable=SC2034 # Set from common/vars.sh
[[ -n "${__COMMON_VARS_INCLUDED:-}" ]] || {
echo >&2 'FATAL: Inclusion of common defaults failed'
exit 1
}
# shellcheck disable=SC2154
declare IMAGE="${build_name}:latest"
# shellcheck disable=SC1091
[[ -s common/run.sh ]] && . common/run.sh >/dev/null
if [[ "$( type -t 'die' )" != 'function' ]]; then
echo >&2 "FATAL: Unable to source shared functions from" \
"'common/run.sh': ${?}"
exit 127
fi
declare -a services=() args=()
services=(
bitlbee
captive-portal
dcc
dhcpd
distccd
dovecot
fetchmail
fwupd
hpl
imapproxyd
irqbalance
kea
less
lighttpd
lynis
man
mariadb
memcached
metalog
named
netdata
opendkim
opendmarc
openntpd
php
php73
php74
# Gentoo no longer supports <php-8.2 ...
#php80
#php81
php82
#php83
pinfo
postfix
postgrey
pound
powertop
privoxy
redis
spamassassin
spamassassin-update
spampd
subversion
syslog-ng
unifi
unifi60
unifi61
unifi62
unifi64
unifi65
unifi70
unifi71
unifi72
unifi73
unifi74
unifi75
unifi80
unifi81
unifi82
unifi83
unifi84
unifi85
unifi86
vim
watchdog
xmrig
zxtm
)
declare -i installed=0
declare -i tools=0
declare -i all=0
declare -i rebuildpkgs=0
declare force=''
declare build_debug=''
declare alt_log=''
declare arg=''
declare cflags='' cxxflags=''
if type -pf emerge >/dev/null 2>&1; then
cflags="$( # <- Syntax
emerge --info 2>&1 |
grep -- '^CFLAGS=' |
awk -F'"' '{print $2}' || :
)"
cxxflags="$( # <- Syntax
emerge --info 2>&1 |
grep -- '^CXXFLAGS=' |
awk -F'"' '{print $2}' || :
)"
else
# If we don't have 'emerge', then we likely lack the profile default
# value for LDFLAGS, which isn't overridden. We'll also lack any
# -march/-mcpu flags, as these are added by the build system in
# containers only.
#
eval "$(
# shellcheck disable=SC2034
[[ -n "${LDFLAGS:-}" ]] || case "${arch}" in
amd64|ppc64|x86)
LDFLAGS='-Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs'
;;
*)
LDFLAGS='-Wl,-O1 -Wl,--as-needed'
;;
esac
[[ -n "${ARCH:-}" ]] || ARCH="${arch}"
. /etc/portage/make.conf 2>&1
set |
grep -F -- 'FLAGS=' |
sed 's|^[A-Z]\+=|\L&| ; s|$|;|' |
grep -E -- '^c(xx)?flags='
)"
fi
[[ -n "${cflags:-}" ]] || cflags='-O2 -pipe'
[[ -n "${cxxflags:-}" ]] || cxxflags="${cflags}"
print "Found CFLAGS '${cflags}', CXXFLAGS '${cxxflags}'"
# Temporarily throw away all other arguments to try to get a set of parameters
# we can use to perform a manual service build (... which is largely deprecated
# at this point)
#
args=( ${@+"${@}"} )
set --
for arg in "${args[@]:-}"; do
case "${arg}" in
-*)
continue
;;
tools|installed|all)
# We can't auto-detect the presence of 'less' or 'distcc'...
set -- ${@+"${@}"} 'sys-apps/less' 'sys-devel/distcc'
;;
*)
set -- ${@+"${@}"} "${arg}"
;;
esac
done
unset arg
declare service="${1:-}"
declare original_service="${service:-}"
declare ports="${2:-"0"}"
declare user="${3:-"root"}"
declare group="${4:-"root"}"
declare container_cmd="${5:-}"
declare container_cwd="${6:-"/"}" # Optional
declare fs_name="${7:-}" # Optional: If set create /var/{run,log}/${fs_name} in container
#
# Restore our original arguments again
#
set -- "${args[@]:-}"
declare zxtm_service_version=''
declare -i rc=0
declare -a container_caps=()
usage() {
#output >&2 "Usage: $( basename "${0}" ) <service" \
# '[<ports> <user> <group> <command> [directory [fs_name]]]|--services' \
# '<service> [service...]> [--rebuild] [--force] [--force-keywords]' \
# '[--debug]'
output >&2 "Usage: $( basename "${0}" ) <service>" \
'[<ports> <user> <group> <command> [directory [fs_name]]]'
output >&2 "Usage: $( basename "${0}" ) --services" \
'<service> [service...] [--rebuild] [--force] [--force-keywords]' \
'[--debug]'
output >&2
output >&2 'Known services:'
s=''
for s in "${services[@]:-}"; do
output >&2 " ${s}"
done
unset s
output >&2
output >&2 ' tools'
output >&2 ' installed'
output >&2 ' all'
output >&2
} # usage
if [[ -z "${*:-}" ]] || grep -Eq -- ' -(h|-help) ' <<<" ${*:-} "; then
usage
if [[ -z "${*:-}" ]]; then
exit 1
else
exit 0
fi
fi
# Support 'core' user for podman+machine Fedora default user...
if [[ "$( uname -s )" == 'Darwin' ]]; then
if (( EUID )) && [[ "$( id -nu )" == 'core' ]]; then
die "Please re-run '$( basename "${0}" )' as user 'root'"
fi
fi
declare arg=''
declare service_list=''
for arg in "${@:-}"; do
shift
case "${arg:-}" in
-a|--all|all)
service=''
all=1
;;
-d|--debug)
build_debug=1
;;
-f|--force)
force=1
;;
-i|--installed|installed)
service=''
installed=1
;;
-k|--force-keywords)
FORCE_KEYWORDS=1
export FORCE_KEYWORDS
;;
-r|--rebuild)
rebuildpkgs=1
;;
-s|--services)
service_list=1
;;
-t|--tools|tools)
tools=1
;;
'')
:
;;
*)
set -- ${@+"${@}"} "${arg}"
;;
esac
done
unset arg
# BEGIN WRAPPER CODE
#
# All we're doing here is figuring out the arguments to re-invoke ourselves
# with!
#
if (( all && installed )); then
warn "options 'all' and 'installed' are mutually exclusive - using 'all'"
installed=0
fi
if (( installed )); then
service_list=1
# shellcheck disable=SC2046 # We want word-splitting here...
set -- "${@}" $( xargs -n 1 echo <<<"$( # <- Syntax
# Build list based on installed packages... (useful if the local image
# cache has been cleared!)
#
[[ -d /var/db/pkg/container ]] && find /var/db/pkg/container/ \
-mindepth 2 -maxdepth 2 -type f -name CONTENTS -print |
awk -F '/' 'NF-1 { print $(NF-1) }' |
sed \
-e 's/^php-\([0-9]\).\([0-9]\)\(.*\)$/php\1\2-\1.\2\3/g' \
-e 's/^unifi\(-controller\(-bin\)\?\)\?-\([0-9]\).\([0-9]\)\(.*\)$/unifi\3\4-\3.\4\5/g' |
sed -r 's/-[0-9][0-9.]*(_p[0-9]+)?(-r[0-9]+)?//'
# Build list based on present images...
#
docker image list --noheading --sort repository \
--format '{{.Repository}}-{{.Tag}}' 'localhost/service.' |
grep -vx -- 'localhost/service.www-servers.web-content-latest' |
cut -d'.' -f 3- |
sed \
-e 's/^php-\([0-9]\).\([0-9]\)\(.*\)$/php\1\2-\1.\2\3/g' \
-e 's/^unifi\(-controller\(-bin\)\?\)\?-\([0-9]\).\([0-9]\)\(.*\)$/unifi\3\4-\3.\4\5/g' |
sed -r 's/-[0-9][0-9.]*(_p[0-9]+)?(-r[0-9]+)?//'
)" | sort | uniq )
fi
if (( tools )); then
service_list=1
set -- "${@}" 'distcc' 'less' 'lynis' 'man' 'pinfo' 'powertop' 'vim' # 'fwupd'
fi
for arg in "${@:-}"; do
shift
case "${arg:-}" in
# In some cases, the package name and service name differ :(
bind)
set -- "${@}" 'named'
;;
dhcp)
set -- "${@}" 'dhcpd'
;;
distcc)
set -- "${@}" 'distccd'
;;
imapproxy)
set -- "${@}" 'imapproxyd'
;;
man-db)
set -- "${@}" 'man'
;;
spamd|spamassassin*)
# The idea here is to ensure that if spamassassin is rebuilt, then
# so is spamassassin's updater...
if ! grep -Eq -- ' spam(d|assassin) ' <<<" ${*:-} "; then
set -- "${@}" 'spamassassin'
fi
if ! grep -q -- ' spamassassin-update ' <<<" ${*:-} "; then
set -- "${@}" 'spamassassin-update'
fi
;;
unifi-controller|unifi-controller-bin)
set -- "${@}" 'unifi'
;;
web-content)
:
;;
'')
:
;;
*)
set -- "${@}" "${arg}"
;;
esac
done
unset arg
if (( service_list )); then
list=''
for arg in "${@:-}"; do
if grep -wq -- "${arg}" <<<" ${services[*]:-} "; then
list="${list:+"${list} "}${arg}"
else
error "Service '${arg}' not known"
rc=1
fi
done
unset arg
(( rc )) && die 'Unable to process service list'
# This logic isn't great - if we're given a (reduced) service list, then we
# replace the master list of services with the specified set but then still
# process what we believe to be all services (as a result) with the 'all'
# logic :|
#
IFS=' ' read -r -a services <<<"${list:-}"
service=''
all=1
else
# 'ports' pattern is '([1-9][0-9]{0-4}(/(tc|ud)p)?) +'
if grep -q -- '[^0-9,/tcpud]' <<<"${ports}"; then
output >&2 "FATAL: Illegal value '${ports}' for 'ports' argument of" \
'component-based assembly'
output >&2
usage
exit 1
fi
fi
if (( all )); then
# Prevent recursion on 'all'...
if ! [[ "${service:-}" == 'all' ]]; then
declare -i c=0
declare s='' f=''
for s in "${services[@]:-}"; do
output >&2
# shellcheck disable=SC2154
output >&2 " ${red}*${reset} Examining service '${s}'" \
"[${c}/${#services[@]}:${rc}] ..."
output >&2
: $(( c++ ))
# Call ourself for each service in turn...
print "Re-invoking script as './$( basename "${0}" ) ${s}${rebuildpkgs:+" --rebuild"}${force:+" --force"}${FORCE_KEYWORDS:+" --force-keywords"}'"
./"$( basename "${0}" )" "${s}" ${rebuildpkgs:+"--rebuild"} ${force:+"--force"} ${FORCE_KEYWORDS:+"--force-keywords"} || {
: $(( rc++ ))
f="${f:+"${f} "}${s}"
}
sleep 0.1 2>/dev/null || sleep 1
done
unset s
if (( rc )); then
warn "${rc} out of ${c} services failed to build:"
warn "Failed service builds: ${f}"
fi
# shellcheck disable=SC2086
exit ${rc}
fi
fi
#
# END WRAPPER CODE
#replace_flags() {
# # Moved to common/run.sh!
#} # replace_flags
[ -n "${trace:-}" ] && set -o xtrace
images="$( docker image list --noheading "${IMAGE%":"*}" 2>&1 )"
if ! echo "${images}" | grep -Eq -- "^(localhost/)?${IMAGE%":"*}"; then
die "svc stage: docker image '${IMAGE%":"*}' not found"
fi
unset images
_docker_setup
case "${service:-}" in
bitlbee)
service='>=net-im/bitlbee-3.6-r1' ;;
captive-portal)
# This ebuild lives in a private repo unless/until refactored at some
# future date to remote internal network, email, and user references...
service='www-servers/captive-portal' ;;
dcc)
service='mail-filter/dcc' ;;
dhcp|dhcpd)
service='net-misc/dhcp' ;;
distcc|distccd)
service='sys-devel/distcc' ;;
dovecot)
service='net-mail/dovecot' ;;
eix)
service='app-portage/eix' ;;
fetchmail)
service='net-mail/fetchmail' ;;
fwupd)
service='sys-apps/fwupd' ;;
hpl)
service='sys-cluster/hpl' ;;
imapproxy|imapproxyd)
service='>=net-mail/imapproxy-1.2.8_p14637::srcshelton' ;;
irqbalance)
service='sys-apps/irqbalance' ;;
kea)
service='net-misc/kea' ;;
less)
# Launcher loads running services' /usr/share/doc volumes
service='sys-apps/less' ;;
lighttp|lighttpd)
service='www-servers/lighttpd' ;;
lynis)
service='app-forensics/lynis' ;;
man|man-db)
# Launcher loads running services' /usr/share/man volumes
service='sys-apps/man-db' ;;
memcache|memcached)
service='net-misc/memcached' ;;
metalog)
service='app-admin/metalog::container' ;;
mysql|mysqld|mariadb)
service='dev-db/mariadb' ;;
named|bind)
#service='>=net-dns/bind-9.14.12::container'
service='>=net-dns/bind-9.16.6' ;;
netdata)
service='net-analyzer/netdata' ;;
ntpd|openntpd)
#service='>=net-misc/openntpd-6.8_p1::container' ;; # turns out, it's broken :(
service='net-misc/openntpd::container' ;;
opendkim)
service='>=mail-filter/opendkim-2.10.3-r3' ;;
opendmarc)
service='mail-filter/opendmarc' ;;
php)
service='dev-lang/php' ;;
php73)
service='=dev-lang/php-7.3*' ;;
php74)
service='=dev-lang/php-7.4*' ;;
# Gentoo no longer supports <php-8.2 ...
#php80)
# service='=dev-lang/php-8.0*' ;;
#php81)
# service='=dev-lang/php-8.1*' ;;
php82)
service='=dev-lang/php-8.2*' ;;
#php83)
# service='=dev-lang/php-8.3*' ;;
pinfo|info)
# Launcher loads running services' /usr/share/info volumes
service='app-text/pinfo' ;;
postfix)
service='mail-mta/postfix' ;;
postgrey|postgray)
#service='mail-filter/postgrey::container' # 1.36-r1 and prior didn't use account packages
service='mail-filter/postgrey' ;;
pound)
service='www-servers/pound' ;;
powertop)
service='sys-power/powertop' ;;
privoxy)
service='net-proxy/privoxy' ;;
redis)
service='dev-db/redis' ;;
spamassassin|spamd)
service='>=mail-filter/spamassassin-3.4.4-r1::srcshelton' ;;
spamassassin-update|sa-update)
service='>=mail-filter/spamassassin-3.4.4-r1::srcshelton' ;;
spampd)
service='mail-filter/spampd' ;;
svn|svnserve|subversion)
service='dev-vcs/subversion' ;;
syslog-ng)
service='app-admin/syslog-ng' ;;
unifi|unifi-controller|unifi-controller-bin)
service='net-misc/unifi-controller-bin' ;;
unifi60|unifi-controller60|unifi-controller-60|unifi-controller-bin60|unifi-controller-bin-60)
service='=net-misc/unifi-controller-bin-6.0*' ;;
unifi61|unifi-controller61|unifi-controller-61|unifi-controller-bin61|unifi-controller-bin-61)
service='=net-misc/unifi-controller-bin-6.1*' ;;
unifi62|unifi-controller62|unifi-controller-62|unifi-controller-bin62|unifi-controller-bin-62)
service='=net-misc/unifi-controller-bin-6.2*' ;;
unifi64|unifi-controller64|unifi-controller-64|unifi-controller-bin64|unifi-controller-bin-64)
service='=net-misc/unifi-controller-bin-6.4*' ;;
unifi65|unifi-controller65|unifi-controller-65|unifi-controller-bin65|unifi-controller-bin-65)
service='=net-misc/unifi-controller-bin-6.5*' ;;
unifi70|unifi-controller70|unifi-controller-70|unifi-controller-bin70|unifi-controller-bin-70)
service='=net-misc/unifi-controller-bin-7.0*' ;;
unifi71|unifi-controller71|unifi-controller-71|unifi-controller-bin71|unifi-controller-bin-71)
service='=net-misc/unifi-controller-bin-7.1*' ;;
unifi72|unifi-controller72|unifi-controller-72|unifi-controller-bin72|unifi-controller-bin-72)
service='=net-misc/unifi-controller-bin-7.2*' ;;
unifi73|unifi-controller73|unifi-controller-73|unifi-controller-bin73|unifi-controller-bin-73)
service='=net-misc/unifi-controller-bin-7.3*' ;;
unifi74|unifi-controller74|unifi-controller-74|unifi-controller-bin74|unifi-controller-bin-74)
service='=net-misc/unifi-controller-bin-7.4*' ;;
unifi75|unifi-controller75|unifi-controller-75|unifi-controller-bin75|unifi-controller-bin-75)
service='=net-misc/unifi-controller-bin-7.5*' ;;
unifi80|unifi-controller80|unifi-controller-80|unifi-controller-bin80|unifi-controller-bin-80)
service='=net-misc/unifi-controller-bin-8.0*' ;;
unifi81|unifi-controller81|unifi-controller-81|unifi-controller-bin81|unifi-controller-bin-81)
service='=net-misc/unifi-controller-bin-8.1*' ;;
unifi82|unifi-controller82|unifi-controller-82|unifi-controller-bin82|unifi-controller-bin-82)
service='=net-misc/unifi-controller-bin-8.2*' ;;
unifi83|unifi-controller83|unifi-controller-83|unifi-controller-bin83|unifi-controller-bin-83)
service='=net-misc/unifi-controller-bin-8.3*' ;;
unifi84|unifi-controller84|unifi-controller-84|unifi-controller-bin84|unifi-controller-bin-84)
service='=net-misc/unifi-controller-bin-8.4*' ;;
unifi85|unifi-controller85|unifi-controller-85|unifi-controller-bin85|unifi-controller-bin-85)
service='=net-misc/unifi-controller-bin-8.5*' ;;
unifi86|unifi-controller86|unifi-controller-86|unifi-controller-bin86|unifi-controller-bin-86)
service='=net-misc/unifi-controller-bin-8.6*' ;;
vim|vi)
# Launcher loads running services' /usr/share/doc volumes
service='app-editors/vim' ;;
watchdog)
service='sys-apps/watchdog' ;;
xmrig)
service='net-misc/xmrig' ;;
zxtm)
# The Docker Registry API documenation describes a default page_size of
# 10 with a maximum of 1000 results, although a practical limit of 100
# has been reported.
# There are no details of how the tag-list is sorted into pages, but
# the list appears to be sorted most-recently-changed first...
zxtm_service_version="$( # <- Syntax
curl -Ls 'https://registry.hub.docker.com/v2/repositories/pulsesecure/vtm/tags' |
jq -r '.results[].name' |
grep -v -- 'latest' |
sort -V |
tail -n 1
)"
service="net-misc/zxtm-init-scripts-${zxtm_service_version/[Rr]/-r}"
;;
'')
die 'No service name or description provided' ;;
*)
info "Building manually-specified service '${service}'" ;;
esac
package=''
package_name=''
package_version=''
repo=''
container_name=''
container_prefix='buildsvc'
_docker_resolve "${service%"::"*}" "${container_prefix}"
# shellcheck disable=SC2001 # POSIX sh compatibility
container_name="$( echo "${package}" | sed 's|/|.|' )"
# shellcheck disable=SC2001 # POSIX sh compatibility
package_name="$( echo "${package_name}" | sed 's|/|.|' )"
keep_base='yes'
case "${package_name}" in
'net-misc.zxtm-init-scripts')
package_name='net-misc.zxtm' ;;
'mail-filter.spamassassin')
if [ "${original_service}" = 'spamassassin-update' ] || [ "${original_service}" = 'sa-update' ]; then
pkgname='mail-filter.spamassassin-update'
alt_log="${pkgname}${container_name#"${package_name}"}"
package_name="${pkgname}"
unset pkgname
fi
;;
esac
export container_name package_name
echo "${service}" | grep -Fq -- '::' && repo="${service#*"::"}"
if [ "${container_name}" = 'podman' ]; then
die "Suspicious container name '${container_name}'"
else
print "Using container name '${container_name}'"
fi
if [ -z "${package_name:-}" ]; then
die "Cannot extract package name from service name '${service}' (${package})"
fi
if [ -z "${package_version:-}" ]; then
die "Cannot extract package version from service name '${service}' (${package})"
fi
if [ $(( ${force:-"0"} )) -eq 0 ]; then
images="$( docker image list --noheading "service.${package_name}:${package_version}" 2>&1 )"
if echo "${images:-}" | grep -q -- "service.${package_name}\s\+${package_version}\s"; then
note "Docker image 'service.${package_name}:${package_version}' already exists - remove or use --force to rebuild"
exit 0
else
output "Creating new 'service.${package_name}:${package_version}' image ..."
fi
unset images
else
warn "Forcing creation of new 'service.${package_name}:${package_version}' image ..."
fi
# ... from common/vars.sh:
#use_essential="asm ipv6 perl_features_ithreads ktls mdev multiarch native-extensions split-usr ssp threads$ ${use_cpu_flags:-}
#use_essential_gcc='default-stack-clash-protection default-znow graphite -jit nptl openmp pch pie -sanitize ssp -vtv zstd'
force_python=''
pre_remove='' pre_pkgs='' pre_use=''
with_use='' extra_pkgs=''
post_pkgs='' post_use='' post_remove=''
gcc_extra_use_flags='pch' # N.B. 'pch' now masked due to fragility...
python_target='' etcdir=''
# There's probably a better way of doing this, but for now let's assume that
# the python configuration for the root system and the python confguration for
# the container build environment is the same (... which is reasonable, unless
# overridden, as they share a common portage tree and therefore base set of
# python defaults).
if type -pf portageq >/dev/null 2>&1; then
python_target="$( portageq envvar 'PYTHON_SINGLE_TARGET' )"
case "${original_service:-}" in
php[0-9][0-9])
php_targets="${original_service%[0-9]}-${original_service#"php"[0-9]}"
;;
*)
php_targets="$( for t in $( portageq envvar 'PHP_TARGETS' ); do echo "php_targets_${t}"; done | sort -V | tail -n 1 )"
;;
esac
else
# shellcheck disable=SC2154
python_single_target="${python_default_target##*" "}"
python_target="${python_single_target:-"${python_default_target}"}"
case "${original_service:-}" in
php[0-9][0-9])
php_targets="${original_service%[0-9]}-${original_service#"php"[0-9]}"
;;
*)
# FIXME: Hard-coded
php_targets='php_targets_php8-2'
;;
esac
fi
print "Building for python version '${python_target}'"
print "Building for PHP versions '${php_targets}'"
case "${package_name}" in
*.bind)
output "Setting build variables for package 'bind' ..."
pre_pkgs='sys-apps/help2man sys-devel/gcc acct-group/named acct-user/named'
extra_pkgs='app-alternatives/bc dev-lang/perl sys-apps/coreutils sys-apps/file sys-apps/gentoo-functions'
extra_pkgs+=' app-shells/bash sys-devel/bc'
ports='53/tcp 53/udp 853/tcp 953/tcp 8053/tcp'
container_cmd='/usr/sbin/named'
etcdir='bind'
;;
*.bitlbee)
output "Setting build variables for package 'bitlbee' ..."
pre_pkgs='acct-group/bitlbee acct-user/bitlbee'
ports='6667/tcp'
user='bitlbee'
group='bitlbee'
container_cmd='/usr/sbin/bitlbee'
container_cwd='/var/lib/bitlbee'
etcdir='bitlbee'
;;
*.captive-portal)
output "Setting build variables for private package 'captive-portal' ..."
ports='8088/tcp'
#user='root'
#group='root'
container_cmd='/usr/local/sbin/shttpd.pl'
container_cwd='/var/lib/shttpd'
etcdir='iptables.d'
;;
*.dcc)
output "Setting build variables for package 'dcc' ..."
extra_pkgs='sys-apps/findutils'
ports='6276/udp 6276/tcp 6277/udp 6277/tcp'
container_cmd='/etc/init.d/dcc'
etcdir='dcc'
;;
*.dhcp)
output "Setting build variables for package 'dhcp' ..."
pre_pkgs='acct-group/dhcp acct-user/dhcp'
ports='67/udp 68/udp 647/tcp 7911/tcp'
#user='dhcp'
#group='dhcp'
container_cmd='/usr/sbin/dhcpd'
etcdir='dhcp'
;;
*.distcc)
output "Setting build variables for package 'distcc' ..."
pre_pkgs='acct-group/distcc acct-user/distcc'
extra_pkgs='dev-lang/python'
ports='3632/tcp 3635/tcp 3636/tcp'
#user='distcc'
#group='distcc'
container_cmd='/usr/bin/distccd'
etcdir='distcc'
;;
*.dovecot)
output "Setting build variables for package 'dovecot' ..."
pre_pkgs='sys-apps/help2man sys-devel/gcc'
pre_pkgs+=' acct-group/dovecot acct-group/dovenull acct-group/mail acct-user/dovecot acct-user/dovenull acct-user/mail acct-user/postmaster'
extra_pkgs='app-shells/bash'
ports='143/tcp 993/tcp 24242/tcp'
container_cmd='/usr/sbin/dovecot'
etcdir='dovecot'
;;
*.eix)
output 'Setting build variables for non-native tools ...'
pre_pkgs='app-arch/bzip2 app-alternatives/bzip2 dev-lang/python dev-lang/python-exec sys-devel/gcc' # virtual/linux-sources
with_use='reference'
extra_pkgs='app-eselect/eselect-python app-portage/gentoolkit'
# This container must be able to be invoked as 'versionsort' or 'equery'...
container_cmd='/usr/bin/versionsort'
;;
*.fetchmail)
output "Setting build variables for packages 'fetchmail', 'procmail', and 'postfix' ..."
pre_pkgs='sys-apps/help2man sys-devel/gcc'
pre_pkgs+=' acct-group/mail acct-user/mail acct-user/postmaster'
extra_pkgs='mail-filter/procmail net-mail/dovecot dev-lang/perl'
extra_pkgs+=' app-shells/bash'
container_cmd='/usr/bin/fetchmail'
;;
*.fwupd)
output "Setting build variables for package 'fwupd' ..."
pre_remove='sys-libs/libeudev'
pre_pkgs='sys-devel/gcc'
keep_base='no'
container_cmd='/usr/bin/fwupdtool'
etcdir='fwupd'
;;
*.hpl)
output "Setting build variables for package 'hpl' ..."
pre_use='fortran graphite openmp'
pre_pkgs='dev-libs/isl sys-devel/gcc sys-devel/gcc-config'
with_use="${pre_use}"
extra_pkgs="${pre_pkgs}
app-shells/bash
dev-debug/strace
sci-libs/blis
sci-libs/openblas
sys-apps/portage
sys-cluster/mpich
sys-devel/binutils
sys-devel/binutils-config
sys-kernel/linux-headers
virtual/openssh
"
post_use="${pre_use} -lib-only graphite -nls"
container_cmd='__wait__'
;;
*.imapproxy)
output "Setting build variables for package 'imapproxy' ..."
pre_pkgs='acct-group/nogroup'
#ports='143/tcp'
ports='8143/tcp'
container_cmd='/usr/sbin/imapproxyd'
etcdir='imapproxy'
;;
*.irqbalance)
output "Setting build variables for package 'irqbalance' ..."
pre_pkgs='sys-apps/help2man'
container_cmd='/usr/sbin/irqbalance'
;;
*.kea)
output "Setting build variables for package 'kea' ..."
pre_pkgs='sys-devel/gcc'
#ports='67/udp 68/udp 647/tcp 7911/tcp'
#user='dhcp'
#group='dhcp'
container_caps=( # <- Syntax
--cap-add NET_BIND_SERVICE
--cap-add NET_RAW
)
container_cmd='/usr/sbin/kea-dhcp4'
etcdir='kea'
;;
*.less)
output "Setting build variables for package 'less' ..."
extra_pkgs='app-text/lesspipe'
container_cmd='/usr/bin/less'
;;
*.lighttpd)
output "Setting build variables for package 'lighttpd' ..."
# Gentoo no longer supports <php-8.2 ...
#pre_pkgs='>=dev-lang/php-8.1 media-gfx/imagemagick sys-apps/help2man sys-devel/gcc'
pre_pkgs='>=dev-lang/php-8.2 media-gfx/imagemagick sys-apps/help2man sys-devel/gcc'
pre_pkgs+=' acct-group/lighttpd acct-user/lighttpd'
extra_pkgs='
dev-lang/perl
dev-perl/CGI
dev-perl/IO-Socket-INET6
dev-perl/IO-Socket-SSL
dev-php/pecl-imagick
mail-filter/dcc
media-gfx/imagemagick
sys-apps/findutils
'
extra_pkgs+=' app-shells/bash'
if [[ "$( # <- Syntax
printf '1.4.76\n%s' "${package_version:-}" |
sort -V |
head -n 1
)" == '1.4.76' ]]; then
output "Configuring '${package_name##*.}-${package_version:-}' for v1.4.76 or later ..."
else
output "Configuring '${package_name##*.}-${package_version:-}' for v1.4.75 or prior ..."
pre_pkgs+=' app-admin/gamin virtual/fam'
extra_pkgs+=' app-admin/gamin'
fi
#ports='80/tcp 443/tcp'
ports='7080/tcp 7443/tcp'
container_cmd='/usr/sbin/lighttpd'
etcdir='lighttpd'
;;
*.lynis)
output "Setting build variables for package 'lynis' ..."
# 'srcshelton' repo relocates gawk to /bin/
impl='::srcshelton'
with_use='gawk'
extra_pkgs="net-misc/openssh sys-apps/coreutils sys-apps/findutils sys-apps/gawk${impl:+"${impl}"} app-alternatives/awk${impl:+"${impl}"}"
container_cmd='/usr/sbin/lynis'
;;
*.man-db)
output "Setting build variables for package 'man-db' ..."
pre_pkgs='sys-apps/help2man sys-apps/man-pages sys-apps/man-pages-posix sys-devel/gcc' # sys-libs/glibc'
# sys-libs/timezone-data needed for man-page tools...
extra_pkgs='app-text/manpager net-misc/rsync sys-apps/less' # sys-libs/glibc sys-libs/timezone-data'
container_cmd='/usr/bin/man'
;;
*.mariadb)
output "Setting build variables for package 'mariadb' ..."
pre_pkgs='sys-apps/help2man sys-devel/gcc'
pre_pkgs+=' acct-group/hugetlb acct-group/mysql acct-user/mysql' # sys-libs/glibc'
# app-shells/bash needed to run ebuild 'pkg_config' function within container (now from USE-flag to app-alternatives/sh)
# sys-libs/glibc needed to provide locale data
# sys-libs/timezone-data needed to provide time-zone data for new installations...
extra_pkgs='dev-db/mysqltuner' # sys-libs/glibc sys-libs/timezone-data'
extra_pkgs+=' app-shells/bash'
ports='3306/tcp 4444/tcp 4567/tcp 4568/tcp' # 4444, 4567-8 for Galera SST
user='mysql'
group='mysql'
container_cmd='/usr/sbin/mysqld'
container_cwd='/var/lib/mysql'
etcdir='mysql'
;;
*.memcached)
output "Setting build variables for package 'memcached' ..."
pre_pkgs='acct-group/hugetlb acct-group/memcached acct-user/memcached'
container_cmd='/usr/bin/memcached'
;;
*.metalog)
output "Setting build variables for package 'metalog' ..."
ports='514/udp'
container_cmd='/usr/sbin/metalog'
etcdir='metalog'
;;
*.netdata)
output "Setting build variables for package 'netdata' ..."
pre_pkgs='acct-group/netdata acct-user/netdata'
pre_pkgs+=' acct-group/cron acct-user/cron'
pre_pkgs+=' acct-group/crontab'
pre_pkgs+=' acct-group/dhcp acct-user/dhcp'
pre_pkgs+=' acct-group/dovecot acct-group/dovenull acct-user/dovecot'
pre_pkgs+=' acct-group/hugetlb'
pre_pkgs+=' acct-group/ldap acct-user/ldap'
pre_pkgs+=' acct-group/mail acct-user/mail'
pre_pkgs+=' acct-group/mysql acct-user/mysql'
pre_pkgs+=' acct-group/named acct-user/named'
pre_pkgs+=' acct-group/netdata acct-user/netdata'
pre_pkgs+=' acct-group/pcap acct-user/pcap'
pre_pkgs+=' acct-group/podman'
pre_pkgs+=' acct-group/postdrop'
pre_pkgs+=' acct-group/postfix acct-user/postfix'
pre_pkgs+=' acct-group/tty'
pre_pkgs+=' acct-group/ulogd acct-user/ulogd'
pre_pkgs+=' acct-group/wheel'
pre_pkgs+=' acct-user/postmaster'
# 'compile-locales' forces 'minimal', which breaks sys-apps/iproute2
# dependency for net-firewall/firehol...
#
with_use='-timezone-tools' # compile-locales
extra_pkgs='sys-apps/util-linux'
# portage sometimes struggles to resolve apparently obvious
# dependencies :(
#
pre_use='-timezone-tools'
pre_pkgs+=' sys-libs/glibc'
with_use+=' ncurses unicode zlib'