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
12 makechrootpkg_args
=(-cu) # XXX: allow unsetting these options?
13 makechrootpkg_makepkg_args
=()
16 update
=0 build
=0 create
=0 status
=0 print_path
=0
19 # shellcheck disable=SC2155
20 local str
=$
(printf '%s,' "$@")
21 printf '%s' "${str%,}"
24 # XXX: a missing makepkg.conf usually indicates a missing devtools, whereas
25 # a missing pacman.conf usually indicates the local repository was not configured
29 cat <<EOF | pr -to 4 >&2
30 aur-$argv0 could not find a makepkg.conf(5) file for container usage. Before
31 using aur-$argv0, make sure this file is created and valid. See OPTIONS in
32 aur-$argv0(1) for configuration details.
34 The following file paths were checked:
36 printf '%s\n' "${@@Q}" |
pr -to 8 >&2
42 cat <<EOF | pr -to 4 >&2
43 aur-$argv0 could not find a pacman.conf(5) file for container usage. Before
44 using aur-$argv0, make sure this file is created and valid. See OPTIONS in
45 aur-$argv0(1) for configuration details.
47 The following file paths were checked:
49 printf '%s\n' "${@@Q}" |
pr -to 8 >&2
53 printf 'usage: %s [-BU] [--create] [-CDM path] [package...]\n' "$argv0"
57 opt_short
='C:D:M:x:ABNTU'
58 opt_long
=('directory:' 'pacman-conf:' 'makepkg-conf:' 'build' 'update'
59 'create' 'bind:' 'bind-rw:' 'user:' 'makepkg-args:'
60 'ignorearch' 'namcap' 'checkpkg' 'temp' 'makechrootpkg-args:'
61 'margs:' 'cargs:' 'nocheck' 'suffix:')
62 opt_hidden
=('dump-options' 'status' 'path')
64 if opts
=$
(getopt
-o "$opt_short" -l "$(args_csv "${opt_long[@]}" "${opt_hidden[@]}")" -n "$argv0" -- "$@"); then
70 unset bindmounts_ro bindmounts_rw makepkg_conf pacman_conf suffix
85 # makepkg options (`--build`)
87 makechrootpkg_makepkg_args
+=(--ignorearch) ;;
89 makechrootpkg_makepkg_args
+=(--nocheck) ;;
90 # XXX: cannot take arguments that contain commas (e.g. for file paths)
91 --makepkg-args|
--margs)
92 shift; IFS
=, read -a arg
-r <<< "$1"
93 makechrootpkg_makepkg_args
+=("${arg[@]}") ;;
94 # devtools options (`--build`)
96 shift; pacman_conf
=$1 ;;
98 shift; directory
=$1 ;;
100 shift; makepkg_conf
=$1 ;;
102 shift; bindmounts_ro
+=("$1") ;;
104 shift; bindmounts_rw
+=("$1") ;;
106 makechrootpkg_args
+=(-n) ;;
108 makechrootpkg_args
+=(-C) ;;
110 makechrootpkg_args
+=(-T) ;;
112 shift; makechrootpkg_args
+=(-U "$1") ;;
113 # XXX: cannot take arguments that contain commas (e.g. for file paths)
114 --makechrootpkg-args|
--cargs)
115 shift; IFS
=, read -a arg
-r <<< "$1"
116 makechrootpkg_args
+=("${arg[@]}") ;;
119 printf -- '--%s\n' "${opt_long[@]}" ${AUR_DEBUG+"${opt_hidden[@]}"}
120 printf -- '%s' "${opt_short}" | sed 's/.:\?/-&\n/g'
127 # XXX: default paths can be set through the Makefile (`aur-chroot.in`)
128 etcdir=/etc/aurutils shrdir=/usr/share/devtools
130 # The pacman configuration in the chroot may contain a local repository that
131 # is not configured on the host. Therefore, $db_name is only used for the
132 # default paths below when specified on the command-line or through `AUR_REPO`.
133 if [[ -v suffix ]]; then
134 default_pacman_paths=("$etcdir/pacman-
$suffix.conf
"
135 "$etcdir/pacman-
$machine.conf
"
136 "$shrdir/pacman.conf.d
/$suffix.conf
"
137 "$shrdir/pacman.conf.d
/aurutils-
$machine.conf
")
139 default_makepkg_paths=("$etcdir/makepkg-
$suffix.conf
"
140 "$etcdir/makepkg-
$machine.conf
"
141 "$shrdir/makepkg.conf.d
/$suffix.conf
"
142 "$shrdir/makepkg.conf.d
/$machine.conf
")
144 default_pacman_paths=("$etcdir/pacman-
$machine.conf
"
145 "$shrdir/pacman.conf.d
/aurutils-
$machine.conf
")
147 default_makepkg_paths=("$etcdir/makepkg-
$machine.conf
"
148 "$shrdir/makepkg.conf.d
/$machine.conf
")
151 # Change the default /usr/share/devtools/pacman-extra.conf in aur-chroot to
152 # /etc/aurutils/pacman-<repo>.conf or /etc/aurutils/pacman-<uname>.conf in
153 # aur-build, and pass it on to aur-chroot (#824, #846)
154 for def in "${default_pacman_paths[@]}"; do
155 if [[ -f $def ]] && [[ ! -v pacman_conf ]]; then
161 # The same as above but for /etc/aurutils/makepkg-<repo>.conf or
162 # /etc/aurutils/makepkg-<uname>.conf. If the file is not found, fallback to
163 # makepkg.conf files in /usr/share/devtools.
164 for def in "${default_makepkg_paths[@]}"; do
165 if [[ -f $def ]] && [[ ! -v makepkg_conf ]]; then
171 # No pacman configuration is available for the container, or it points to a
172 # non-existing file. Print a matching diagnostic and exit.
173 if [[ ! -v pacman_conf ]]; then
174 diag_pacman_conf "${default_pacman_paths[@]}"
176 elif [[ ! -f $pacman_conf ]]; then
177 diag_pacman_conf "$pacman_conf"
179 elif [[ ! -v makepkg_conf ]]; then
180 diag_makepkg_conf "${default_makepkg_paths[@]}"
182 elif [[ ! -f $makepkg_conf ]]; then
183 diag_makepkg_conf "$makepkg_conf"
187 # Print paths to container and used makepkg/pacman paths. This does
188 # not require a priorly created container.
189 if (( status )); then
190 printf 'chroot:%q\npacman:%q\nmakepkg:%q\n' "$directory" "$pacman_conf" "$makepkg_conf"
194 # Custom elevation command (#1024)
196 AUR_PACMAN_AUTH=${AUR_PACMAN_AUTH:-sudo}
198 case $AUR_PACMAN_AUTH in
199 sudo) auth_args+=('--preserve-env=GNUPGHOME,SSH_AUTH_SOCK,PKGDEST') ;;
202 # bind mount file:// paths to container (#461)
203 # required for update/build steps
204 while read -r key _ value; do
207 bindmounts_rw+=("${value#file://}") ;;
209 done < <(pacman-conf --config "$pacman_conf")
212 # create new container, required for update/build steps
213 if (( create )); then
214 # default to base-devel or multilib-devel, unless packages are
215 # specified on the command-line.
216 # available packages depend on the configured pacman configuration
220 # XXX: use pacini to not process Include directives in pacman.conf
221 # (not supported by devtools)
222 elif [[ $(pacini --section=multilib "$pacman_conf") ]] && [[ $machine == "x86_64
" ]]; then
223 base_packages=('base-devel' 'multilib-devel')
225 base_packages=('base-devel')
228 # parent path is not created by mkarchroot (#371)
229 if [[ ! -d $directory ]]; then
230 # shellcheck disable=SC2086
231 $AUR_PACMAN_AUTH install -d "$directory" -m 755 -v
234 if [[ ! -d $directory/root ]]; then
235 # shellcheck disable=SC2086
236 $AUR_PACMAN_AUTH mkarchroot -C "$pacman_conf" -M "$makepkg_conf" "$directory"/root "${base_packages[@]}"
240 # arch-nspawn makes no distinction between a missing working directory
241 # and one which does not exist
242 if [[ ! -d $directory/root ]]; then
243 printf >&2 '%s: %q is not a directory\n' "$argv0" "$directory"/root
244 printf >&2 '%s: did you run aur chroot --create?\n' "$argv0"
248 if (( update )); then
249 # locking is done by systemd-nspawn
250 # shellcheck disable=SC2086
251 $AUR_PACMAN_AUTH arch-nspawn -C "$pacman_conf" -M "$makepkg_conf" "$directory"/root \
252 "${bindmounts_ro[@]/#/--bind-ro=}" \
253 "${bindmounts_rw[@]/#/--bind=}" pacman -Syu --noconfirm "$@
"
256 # print path for processing by other tools (e.g. makepkg --packagelist)
257 if (( print_path )); then
258 realpath -- "$directory"/root
263 # use makechrootpkg -c as default build command (sync /root container)
264 # arguments after -- are used as makechrootpkg arguments
265 # shellcheck disable=SC2086
266 $AUR_PACMAN_AUTH "${auth_args[@]}" makechrootpkg -r "$directory" \
267 "${bindmounts_ro[@]/#/-D}" "${bindmounts_rw[@]/#/-d}" \
268 "${makechrootpkg_args[@]}" -- "${makechrootpkg_makepkg_args[@]}"
271 # vim: set et sw=4 sts=4 ft=sh: