-
Notifications
You must be signed in to change notification settings - Fork 2
/
gentoo-build-pkg.docker
executable file
·321 lines (296 loc) · 9.47 KB
/
gentoo-build-pkg.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
#! /usr/bin/env bash
declare trace="${TRACE:-}"
# shellcheck disable=SC2034
declare debug="${DEBUG:-}"
set -eu
set -o pipefail
[ -n "${trace:-}" ] && set -o xtrace
cd "$( dirname "$( readlink -e "${0}" )" )" || exit 1
# Set by common/vars.sh, sourced below...
#
#declare build_name=''
# 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=SC2034,SC2154
declare IMAGE="${build_name}:latest"
# shellcheck disable=SC1091
[ -s common/run.sh ] && . common/run.sh
if [ -z "${*:-}" ] || echo " ${*:-} " | grep -Eq -- ' -(h|-help) '; then
output >&2 "Usage: $( basename "${0}" ) <category/package_name [portage_atom...]> [--rebuild='<portage_atom...>'] [--force-keywords] [--cmd=<cmd>] [--entrypoint=<path>] [--memory=2g] [--memory-limit=8g]"
exit 0
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
# Extract 'entrypoint' argument - all others can be handled by the entrypoint
# script within the container itself...
args=''
rebuild=''
for arg in "${@}"; do
# pop 'arg', but then process it (and potentially re-add it) below...
shift
case "${arg}" in
-k|--force-keywords)
FORCE_KEYWORDS=1
export FORCE_KEYWORDS
continue
;;
--entrypoint=*)
DOCKER_ENTRYPOINT="$( printf '%s' "${arg}" | cut -d'=' -f 2- )"
export DOCKER_ENTRYPOINT
continue
;;
--cmd=*)
DOCKER_CMD="$( printf '%s' "${arg}" | cut -d'=' -f 2- )"
export DOCKER_CMD
continue
;;
--rebuild=*)
rebuild="${rebuild:+"${rebuild} "}${arg#"--rebuild="}"
set -- "${@}" "${arg}"
;;
--rebuild)
if [[ -n "${1:-}" ]]; then
rebuild="${rebuild:+"${rebuild} "}${1}"
set -- "${@}" "${arg}=${1}"
shift
fi
;;
--memory=*)
# shellcheck disable=SC2034
PODMAN_MEMORY_RESERVATION="$( printf '%s' "${arg}" | cut -d'=' -f 2- )"
#if (( PODMAN_MEMORY_LIMIT < PODMAN_MEMORY_RESERVATION )); then
# (( PODMAN_MEMORY_LIMIT = PODMAN_MEMORY_RESERVATION ))
#fi
;;
--memory-limit=*)
PODMAN_MEMORY_LIMIT="$( printf '%s' "${arg}" | cut -d'=' -f 2- )"
# shellcheck disable=SC2034
PODMAN_SWAP_LIMIT="${PODMAN_MEMORY_LIMIT}"
#if (( PODMAN_MEMORY_RESERVATION < PODMAN_MEMORY_LIMIT )); then
# (( PODMAN_MEMORY_RESERVATION = PODMAN_MEMORY_LIMIT ))
#fi
;;
*)
args="${args:+"${args} "}${arg}"
set -- "${@}" "${arg}"
;;
esac
done
if [ -z "${args:-}" ] && [ -n "${rebuild:-}" ]; then
# We only need to specify one package, as the rebuild logic will
# pull-in each original package prior to recompiling it...
set -- "${rebuild%%" "*}" "${@}"
fi
# FIXME: shellcheck wants:
#
# docker_extra_mounts+=( $( add_mount ... ) )
#
# ... to be expressed in the form of:
#
# readarray -O "${#docker_extra_mounts[@]}" -t docker_extra_mounts < <(
# add_mount ...
# )
#
# shellcheck disable=SC2207
{
declare -a docker_extra_mounts=()
docker_extra_mounts+=(
$( add_mount --print '/etc/locale.gen' )
$( add_mount --dir --print '/etc/portage/package.accept_keywords' )
$( add_mount --print '/etc/portage/package.license' )
$( add_mount --print '/etc/portage/profile/use.mask' )
$( add_mount --print '/etc/portage/profile/package.use.force' )
$( add_mount --print '/etc/portage/profile/package.use.mask' )
) || :
# Use host package.mask (if present), overriding the container build-time
# default...
if ! [ -d /etc/portage/package.mask ]; then
docker_extra_mounts+=( $( add_mount --print \
'/etc/portage/package.mask' \
'../host.mask'
) ) || :
else
docker_extra_mounts+=( $( add_mount --print \
'/etc/portage/package.mask/package.mask' \
'/etc/portage/package.mask/host.mask'
) ) || :
declare extra_mask='' file=''
while read -r extra_mask; do
file="$( basename "${extra_mask}" )"
docker_extra_mounts+=( $( add_mount --print \
"/etc/portage/package.mask/${file}"
) ) || :
done < <( # <- Syntax
find /etc/portage/package.mask/ \
-mindepth 1 \
-maxdepth 1 \
-type f \
-not -name 'package.mask' \
-print0 |
grep -vz -- '^repo-.*-mask'
)
unset file extra_mask
fi # [ -d /etc/portage/package.mask ]
# Use host package.unmask (if present), overriding the container build-time
# default...
if ! [ -d /etc/portage/package.unmask ]; then
#docker_extra_mounts+=( $( add_mount --print \
# '/etc/portage/package.unmask'
# ) ) || :
docker_extra_mounts+=( $( add_mount --print \
'/etc/portage/package.unmask' \
'.../host.unmask'
) ) || :
else
docker_extra_mounts+=( $( add_mount --print \
'/etc/portage/package.unmask/package.unmask' \
'/etc/portage/package.unmask/host.unmask'
) ) || :
declare extra_unmask='' file=''
while read -r extra_unmask; do
file="$( basename "${extra_unmask}" )"
docker_extra_mounts+=( $( add_mount --print \
"/etc/portage/package.unmask/${file}"
) ) || :
done < <( # <- Syntax
find /etc/portage/package.unmask/ \
-mindepth 1 \
-maxdepth 1 \
-type f \
-not -name 'package.unmask' \
-print
)
unset file extra_unmask
fi # [ -d /etc/portage/package.unmask ]
if ! [ -d /etc/portage/package.use ]; then
docker_extra_mounts+=( $( add_mount --print \
'/etc/portage/package.use' \
'.../package.use'
) ) || :
else
docker_extra_mounts+=( # <- Syntax
$( add_mount --print '/etc/portage/package.use/00_package.use' )
$( add_mount --print '/etc/portage/package.use/01_package.use.local' )
$( add_mount --print '/etc/portage/package.use/05_host.use' )
) || :
declare targets='' file=''
while read -r targets; do
file="$( basename "${targets}" )"
docker_extra_mounts+=( $( add_mount --print \
"/etc/portage/package.use/${file}"
) ) || :
done < <( # <- Syntax
find /etc/portage/package.use/ \
-mindepth 1 \
-maxdepth 1 \
-type f \
-name '*_targets'
find /etc/portage/package.use/ \
-mindepth 1 \
-maxdepth 1 \
-type f \
-print0 |
xargs -0rn 1 basename |
grep -FvZ -e '.use' -e '_targets'
)
unset file targets
fi # [ -d /etc/portage/package.use ]
# Even with all of the below made available, linux-info.eclass still causes
# builds to fail due to not being able to find a valid kernel configuration?!
#
#docker_extra_mounts+=( $( add_mount --print \
# '/usr/src/linux/.config'
# ) ) || :
#KBUILD_OUTPUT='/usr/src/linux'
#export KBUILD_OUTPUT
export DOCKER_EXTRA_MOUNTS="${docker_extra_mounts[*]:-}"
unset docker_extra_mounts
}
# We're including USE later (via ${use}/--with-use) and so this block was
# simply duplicating arguments...
#
#if [ -n "${USE:-}" ]; then
# # Without passing USE flags in this way, they appear to be getting lost (when /etc/portage/package.use exists?)
# set -- "${@}" --with-use="${USE}"
#fi
#note >&2 'Adding circular-dependency fixes ...'
#if echo "${*}" | grep -q -- 'app-arch/libarchive'; then
# pkg="${pkg:+"${pkg} "}$( echo " ${*} " | sed -r 's|^.*\s([^[:space:]]*app-arch/libarchive[^[:space:]]*)\s.*$|\1|' )"
#else
# pkg="${pkg:+"${pkg} "}app-arch/libarchive"
#fi
##if echo "${*}" | grep -q -- 'dev-util/pkgconfig'; then
## pkg="${pkg:+"${pkg} "}$( echo " ${*} " | sed -r 's|^.*\s([^[:space:]]*dev-util/pkgconfig[^[:space:]]*)\s.*$|\1|' )"
##else
## pkg="${pkg:+"${pkg} "}dev-util/pkgconfig"
##fi
#set -- "${@}" --pre-pkgs="${pkg}" --pre-use='-lz4 internal-glib'
#unset pkg
#set -- "${@}" --pre-use='-lz4 internal-glib'
prepkg=''
preuse="${PREUSE:-}"
use="${USE:-}"
postuse="${POSTUSE:-}"
for arg in "${@:-}"; do
case "$( echo "${arg}" | sed -r 's/^[<>]?=?//' )" in
media-libs/freetype|freetype|media-libs/freetype-*|freetype-*)
prepkg="${prepkg:+"${prepkg} "}${arg} media-libs/harfbuzz"
preuse="$( replace_flags '-harfbuzz' '-truetype' -- "${preuse}" )"
;;
media-libs/harfbuzz|harfbuzz|media-libs/harfbuzz-*|harfbuzz-*)
prepkg="${prepkg:+"${prepkg} "}${arg} media-libs/freetype"
preuse="$( replace_flags '-harfbuzz' '-truetype' -- "${preuse}" )"
;;
#sys-libs/glibc|glibc|sys-libs/glibc-*|glibc-*)
# prepkg="${prepkg:+"${prepkg} "}${arg}"
# ;;
esac
done
preuse="$( replace_flags '-lib-only' -- "${preuse:-}" )"
use="$( replace_flags '-lib-only' -- "${use:-}" )"
postuse="$( replace_flags 'lib-only' -- "${postuse:-}" )"
if [ -n "${prepkg:-}" ]; then
note >&2 "Adding pre-build package(s) '$( xargs -r <<<"${prepkg}" )' to resolve depenency loops ..."
set -- "${@}" --pre-pkgs="${prepkg}"
fi
if [ -n "${preuse:-}" ]; then
note >&2 "Adding pre-build USE flag(s) '$( xargs -r <<<"${preuse}" )' to resolve depenency loops ..."
set -- "${@}" --pre-use="${preuse}"
fi
if [ -n "${use:-}" ]; then
note >&2 "Adding build-time USE flag(s) '$( xargs -r <<<"${use}" )' ..."
set -- "${@}" --with-use="${use}"
fi
if [ -n "${postuse:-}" ]; then
note >&2 "Adding post-build USE flag(s) '$( xargs -r <<<"${postuse}" )' to minimise host requirements ..."
set -- "${@}" --post-use="${postuse}"
fi
# Add '--cap-add' entries sync'd with 'fcaps' calls in ebuilds...
#
# FIXME: Add a distinct 'DOCKER_CAPS' or similar
DOCKER_CMD_VARS="
--cap-add=DAC_OVERRIDE
--cap-add=DAC_READ_SEARCH
--cap-add=NET_ADMIN
--cap-add=NET_BIND_SERVICE
--cap-add=NET_RAW
--cap-add=SETGID
--cap-add=SETUID
--cap-add=SYS_ADMIN
--cap-add=SYS_RESOURCE
--cap-add=SYS_TTY_CONFIG
"
# Provide a '--name' to prevent the container being removed on exit;
# invoke with '--usepkg=n' to rebuild existing packages...
#
_docker_build --intent=discard ${@+"${@}"} \
# vi: set colorcolumn=80 syntax=sh: