2 # aur-chroot - build packages with systemd-nspawn
3 [[ -v AUR_DEBUG
]] && set -o xtrace
6 PATH
=/usr
/local
/sbin
:/usr
/local
/bin
:/usr
/sbin
:/usr
/bin
:/sbin
:/bin
7 PS4
='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
11 directory
=/var
/lib
/aurbuild
/$machine
13 makechrootpkg_args
=(-cu) # XXX: allow unsetting these options?
14 makechrootpkg_makepkg_args
=()
17 update
=0 build
=0 create
=0 print_path
=0
20 # shellcheck disable=SC2155
21 local str
=$
(printf '%s,' "$@")
22 printf '%s' "${str%,}"
25 # XXX: a missing makepkg.conf usually indicates a missing devtools, whereas
26 # a missing pacman.conf usually indicates the local repository was not configured
30 cat <<EOF | pr -to 4 >&2
31 aur-$argv0 could not find a makepkg.conf(5) file for container usage. Before
32 using aur-$argv0, make sure this file is created and valid. See OPTIONS in
33 aur-$argv0(1) for configuration details.
35 The following file paths were checked:
37 printf '%s\n' "${@@Q}" |
pr -to 8 >&2
43 cat <<EOF | pr -to 4 >&2
44 aur-$argv0 could not find a pacman.conf(5) file for container usage. Before
45 using aur-$argv0, make sure this file is created and valid. See OPTIONS in
46 aur-$argv0(1) for configuration details.
48 The following file paths were checked:
50 printf '%s\n' "${@@Q}" |
pr -to 8 >&2
54 printf 'usage: %s [-BU] [--create] [-CDM path] [package...]\n' "$argv0"
58 opt_short
='C:D:M:x:ABNTU'
59 opt_long
=('directory:' 'pacman-conf:' 'makepkg-conf:' 'build' 'update'
60 'create' 'bind:' 'bind-rw:' 'user:' 'path' 'makepkg-args:'
61 'ignorearch' 'namcap' 'checkpkg' 'temp' 'makechrootpkg-args:'
62 'margs:' 'cargs:' 'nocheck' 'suffix:')
63 opt_hidden
=('dump-options')
65 if opts
=$
(getopt
-o "$opt_short" -l "$(args_csv "${opt_long[@]}" "${opt_hidden[@]}")" -n "$argv0" -- "$@"); then
71 unset bindmounts_ro bindmounts_rw makepkg_conf pacman_conf
84 # makepkg options (`--build`)
86 makechrootpkg_makepkg_args
+=(--ignorearch) ;;
88 makechrootpkg_makepkg_args
+=(--nocheck) ;;
89 # XXX: cannot take arguments that contain commas (e.g. for file paths)
90 --makepkg-args|
--margs)
91 shift; IFS
=, read -a arg
-r <<< "$1"
92 makechrootpkg_makepkg_args
+=("${arg[@]}") ;;
93 # devtools options (`--build`)
95 shift; pacman_conf
=$1 ;;
97 shift; directory
=$1 ;;
99 shift; makepkg_conf
=$1 ;;
101 shift; bindmounts_ro
+=("$1") ;;
103 shift; bindmounts_rw
+=("$1") ;;
105 makechrootpkg_args
+=(-n) ;;
107 makechrootpkg_args
+=(-C) ;;
109 makechrootpkg_args
+=(-T) ;;
111 shift; makechrootpkg_args
+=(-U "$1") ;;
112 # XXX: cannot take arguments that contain commas (e.g. for file paths)
113 --makechrootpkg-args|
--cargs)
114 shift; IFS
=, read -a arg
-r <<< "$1"
115 makechrootpkg_args
+=("${arg[@]}") ;;
118 printf -- '--%s\n' "${opt_long[@]}" ${AUR_DEBUG+"${opt_hidden[@]}"}
119 printf -- '%s' "${opt_short}" | sed 's/.:\?/-&\n/g'
126 # The pacman configuration in the chroot may contain a local repository that
127 # is not configured on the host. Therefore, $db_name is only used for the
128 # default paths below when specified on the command-line or through `AUR_REPO`.
129 # XXX: default paths can be set through the Makefile (`aur-chroot.in`)
130 if [[ -v suffix ]]; then
131 default_pacman_paths=("/etc
/aurutils
/pacman-
$suffix.conf
"
132 "/etc
/aurutils
/pacman-
$machine.conf
"
133 "/usr
/share
/devtools
/pacman.conf.d
/$suffix.conf
"
134 "/usr
/share
/devtools
/pacman.conf.d
/aurutils.conf
"
135 "/usr
/share
/devtools
/pacman.conf.d
/aurutils-
$machine.conf
")
137 default_makepkg_paths=("/etc
/aurutils
/makepkg-
$suffix.conf
"
138 "/etc
/aurutils
/makepkg-
$machine.conf
"
139 "/usr
/share
/devtools
/makepkg.conf.d
/$suffix.conf
"
140 "/usr
/share
/devtools
/makepkg.conf.d
/$machine.conf
")
142 default_pacman_paths=("/etc
/aurutils
/pacman-
$machine.conf
"
143 "/usr
/share
/devtools
/pacman.conf.d
/aurutils.conf
"
144 "/usr
/share
/devtools
/pacman.conf.d
/aurutils-
$machine.conf
")
146 default_makepkg_paths=("/etc
/aurutils
/makepkg-
$machine.conf
"
147 "/usr
/share
/devtools
/makepkg.conf.d
/$machine.conf
")
150 # Change the default /usr/share/devtools/pacman-extra.conf in aur-chroot to
151 # /etc/aurutils/pacman-<repo>.conf or /etc/aurutils/pacman-<uname>.conf in
152 # aur-build, and pass it on to aur-chroot (#824, #846)
153 for def in "${default_pacman_paths[@]}"; do
154 if [[ -f $def ]] && [[ ! -v pacman_conf ]]; then
160 # The same as above but for /etc/aurutils/makepkg-<repo>.conf or
161 # /etc/aurutils/makepkg-<uname>.conf. If the file is not found, fallback to
162 # makepkg.conf files in /usr/share/devtools.
163 for def in "${default_makepkg_paths[@]}"; do
164 if [[ -f $def ]] && [[ ! -v makepkg_conf ]]; then
170 # No pacman configuration is available for the container, or it points to a
171 # non-existing file. Print a matching diagnostic and exit.
172 if [[ ! -v pacman_conf ]]; then
173 diag_pacman_conf "${default_pacman_paths[@]}"
175 elif [[ ! -f $pacman_conf ]]; then
176 diag_pacman_conf "$pacman_conf"
178 elif [[ ! -v makepkg_conf ]]; then
179 diag_makepkg_conf "${default_makepkg_paths[@]}"
181 elif [[ ! -f $makepkg_conf ]]; then
182 diag_makepkg_conf "$makepkg_conf"
186 # Custom elevation command (#1024)
188 AUR_PACMAN_AUTH=${AUR_PACMAN_AUTH:-sudo}
190 case $AUR_PACMAN_AUTH in
191 sudo) auth_args+=('--preserve-env=GNUPGHOME,SSH_AUTH_SOCK,PKGDEST') ;;
194 # bind mount file:// paths to container (#461)
195 # required for update/build steps
196 while read -r key _ value; do
199 bindmounts_rw+=("${value#file://}") ;;
201 done < <(pacman-conf --config "$pacman_conf")
204 # create new container, required for update/build steps
205 if (( create )); then
206 # default to base-devel or multilib-devel, unless packages are
207 # specified on the command-line.
208 # available packages depend on the configured pacman configuration
212 # XXX: use pacini to not process Include directives in pacman.conf
213 # (not supported by devtools)
214 elif [[ $(pacini --section=multilib "$pacman_conf") ]] && [[ $machine == "x86_64
" ]]; then
215 base_packages=('base-devel' 'multilib-devel')
217 base_packages=('base-devel')
220 # parent path is not created by mkarchroot (#371)
221 if [[ ! -d $directory ]]; then
222 # shellcheck disable=SC2086
223 $AUR_PACMAN_AUTH install -d "$directory" -m 755 -v
226 if [[ ! -d $directory/root ]]; then
227 # shellcheck disable=SC2086
228 $AUR_PACMAN_AUTH mkarchroot -C "$pacman_conf" -M "$makepkg_conf" "$directory"/root "${base_packages[@]}"
232 # arch-nspawn makes no distinction between a missing working directory
233 # and one which does not exist
234 if [[ ! -d $directory/root ]]; then
235 printf >&2 '%s: %q is not a directory\n' "$argv0" "$directory"/root
236 printf >&2 '%s: did you run aur chroot --create?\n' "$argv0"
240 if (( update )); then
241 # locking is done by systemd-nspawn
242 # shellcheck disable=SC2086
243 $AUR_PACMAN_AUTH arch-nspawn -C "$pacman_conf" -M "$makepkg_conf" "$directory"/root \
244 "${bindmounts_ro[@]/#/--bind-ro=}" \
245 "${bindmounts_rw[@]/#/--bind=}" pacman -Syu --noconfirm "$@
"
248 # print path for processing by other tools (e.g. makepkg --packagelist)
249 if (( print_path )); then
250 realpath -- "$directory"/root
255 # use makechrootpkg -c as default build command (sync /root container)
256 # arguments after -- are used as makechrootpkg arguments
257 # shellcheck disable=SC2086
258 $AUR_PACMAN_AUTH "${auth_args[@]}" makechrootpkg -r "$directory" \
259 "${bindmounts_ro[@]/#/-D}" "${bindmounts_rw[@]/#/-d}" \
260 "${makechrootpkg_args[@]}" -- "${makechrootpkg_makepkg_args[@]}"
263 # vim: set et sw=4 sts=4 ft=sh: