summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-06-15 11:00:02 -0600
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-06-15 11:00:02 -0600
commiteba252eca59c3d110e90c97d114bacceca343426 (patch)
treec771345d885f449648b2e252bcc4c8fdd6d2d30c
parentbf8513ae631484a0c292ad085ea7ede9859f8e0f (diff)
parent453558c4bb44b4bff43fcd22f96d4cfe1dbcf6f1 (diff)
downloaddevtools32-eba252eca59c3d110e90c97d114bacceca343426.tar.xz
Merge commit '4535'
Conflicts: makechrootpkg.in mkarchroot.in
-rw-r--r--Makefile1
-rw-r--r--arch-nspawn.in99
-rw-r--r--archbuild.in6
-rw-r--r--bash_completion.in19
-rw-r--r--makechrootpkg.in12
-rw-r--r--mkarchroot.in197
-rw-r--r--zsh_completion.in14
7 files changed, 173 insertions, 175 deletions
diff --git a/Makefile b/Makefile
index 3bb6464..d73682a 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,7 @@ BINPROGS = \
crossrepomove
SBINPROGS = \
+ arch-nspawn \
mkarchroot \
makechrootpkg
diff --git a/arch-nspawn.in b/arch-nspawn.in
new file mode 100644
index 0000000..0df4875
--- /dev/null
+++ b/arch-nspawn.in
@@ -0,0 +1,99 @@
+#!/bin/bash
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+m4_include(lib/common.sh)
+
+CHROOT_VERSION='v3'
+
+working_dir=''
+
+usage() {
+ echo "Usage: ${0##*/} [options] working-dir [systemd-nspawn arguments]"
+ echo "A wrapper around systemd-nspawn. Provides support for pacman."
+ echo
+ echo ' options:'
+ echo ' -C <file> Location of a pacman config file'
+ echo ' -M <file> Location of a makepkg config file'
+ echo ' -c <dir> Set pacman cache'
+ echo ' -h This message'
+ exit 1
+}
+
+while getopts 'hC:M:c:' arg; do
+ case "$arg" in
+ C) pac_conf="$OPTARG" ;;
+ M) makepkg_conf="$OPTARG" ;;
+ c) cache_dir="$OPTARG" ;;
+ h|?) usage ;;
+ *) error "invalid argument '$arg'"; usage ;;
+ esac
+done
+shift $(($OPTIND - 1))
+
+(( $EUID != 0 )) && die 'This script must be run as root.'
+(( $# < 1 )) && die 'You must specify a directory.'
+
+working_dir="$(readlink -f $1)"
+shift 1
+
+[[ -z $working_dir ]] && die 'Please specify a working directory.'
+
+if [[ -z $cache_dir ]]; then
+ cache_dirs=($(pacman -v $cache_conf 2>&1 | grep '^Cache Dirs:' | sed 's/Cache Dirs:\s*//g'))
+else
+ cache_dirs=(${cache_dir})
+fi
+
+host_mirror=$(pacman -Sddp extra/devtools 2>/dev/null | sed -r 's#(.*/)extra/os/.*#\1$repo/os/$arch#')
+[[ $host_mirror == *file://* ]] && host_mirror_path=$(echo "$host_mirror" | sed -r 's#file://(/.*)/\$repo/os/\$arch#\1#g')
+
+# {{{ functions
+build_mount_args() {
+ local p
+ declare -g mount_args=()
+
+ if [[ -n $host_mirror_path ]]; then
+ printf -v p '%q' "$host_mirror_path"
+ mount_args+=(--bind-ro="$p")
+ fi
+
+ printf -v p '%q' "${cache_dirs[0]}"
+ mount_args+=(--bind="$p")
+
+ for cache_dir in ${cache_dirs[@]:1}; do
+ printf -v p '%q' "$cache_dir"
+ mount_args+=(--bind-ro="$p")
+ done
+}
+
+copy_hostconf () {
+ cp -a /etc/pacman.d/gnupg "$working_dir/etc/pacman.d"
+ echo "Server = $host_mirror" > $working_dir/etc/pacman.d/mirrorlist
+
+ [[ -n $pac_conf ]] && cp $pac_conf $working_dir/etc/pacman.conf
+ [[ -n $makepkg_conf ]] && cp $makepkg_conf $working_dir/etc/makepkg.conf
+
+ sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${cache_dirs[@]})|g" -i $working_dir/etc/pacman.conf
+}
+# }}}
+
+umask 0022
+
+# Sanity check
+if [[ ! -f "$working_dir/.arch-chroot" ]]; then
+ die "'$working_dir' does not appear to be a Arch chroot."
+elif [[ $(cat "$working_dir/.arch-chroot") != $CHROOT_VERSION ]]; then
+ die "chroot '$working_dir' is not at version $CHROOT_VERSION. Please rebuild."
+fi
+
+build_mount_args
+copy_hostconf
+
+exec systemd-nspawn -D "$working_dir" "${mount_args[@]}" "$@"
diff --git a/archbuild.in b/archbuild.in
index 06c9815..38fb8bf 100644
--- a/archbuild.in
+++ b/archbuild.in
@@ -68,11 +68,11 @@ if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then
"${chroots}/${repo}-${arch}/root" \
"${base_packages[@]}" || abort
else
- setarch ${arch} mkarchroot \
- -u \
+ setarch ${arch} arch-nspawn \
-C "@pkgdatadir@/pacman-${repo}.conf" \
-M "@pkgdatadir@/makepkg-${arch}.conf" \
- "${chroots}/${repo}-${arch}/root" || abort
+ "${chroots}/${repo}-${arch}/root" \
+ pacman -Syu --noconfirm || abort
fi
msg "Building in chroot for [${repo}] (${arch})..."
diff --git a/bash_completion.in b/bash_completion.in
index 9395d3a..d9948af 100644
--- a/bash_completion.in
+++ b/bash_completion.in
@@ -53,7 +53,7 @@ _mkarchroot() {
case $cur in
-*)
- COMPREPLY=( $( compgen -W '-C -M -c -h -n -r -u' -- "$cur" ) )
+ COMPREPLY=( $( compgen -W '-C -M -c -h' -- "$cur" ) )
;;
*)
_filedir
@@ -65,5 +65,22 @@ _mkarchroot() {
} &&
complete -F _mkarchroot mkarchroot
+_arch-nspawn() {
+ local cur
+ COMPREPLY=()
+ _get_comp_words_by_ref cur
+
+ case $cur in
+ -*)
+ COMPREPLY=( $( compgen -W '-C -M -c -h' -- "$cur" ) )
+ ;;
+ *)
+ _filedir
+ return 0
+ ;;
+ esac
+ true
+} &&
+complete -F _arch-nspawn arch-nspawn
# ex:et ts=2 sw=2 ft=sh
diff --git a/makechrootpkg.in b/makechrootpkg.in
index b0241f2..0164754 100644
--- a/makechrootpkg.in
+++ b/makechrootpkg.in
@@ -12,12 +12,6 @@ m4_include(lib/common.sh)
shopt -s nullglob
-# So that usage conflicts between upstream and -par mkarchroot don't get hidden
-# silently in a merge.
-archroot() {
- mkarchroot "$@"
-}
-
makepkg_args='-s --noconfirm -L'
repack=false
update_first=false
@@ -159,7 +153,7 @@ if [[ -n "${install_pkgs[*]}" ]]; then
pkgname="${install_pkg##*/}"
cp "$install_pkg" "$copydir/$pkgname"
- archroot -r "$copydir" pacman -U "/$pkgname" --noconfirm
+ arch-nspawn "$copydir" pacman -U /$pkgname --noconfirm
(( ret += !! $? ))
rm "$copydir/$pkgname"
@@ -169,7 +163,7 @@ if [[ -n "${install_pkgs[*]}" ]]; then
[[ -f PKGBUILD ]] || exit $ret
fi
-$update_first && archroot -u "$copydir"
+$update_first && arch-nspawn "$copydir" pacman -Syu --noconfirm
mkdir -p "$copydir/build"
@@ -285,7 +279,7 @@ exit 0
EOF
chmod +x "$copydir/chrootbuild"
-if archroot -r "$copydir" "/chrootbuild"; then
+if arch-nspawn "$copydir" /chrootbuild; then
mkdir -p "$copydir/repo"
for pkgfile in "$copydir"/pkgdest/*.pkg.tar.?z; do
if $add_to_db; then
diff --git a/mkarchroot.in b/mkarchroot.in
index d11c1e0..68db64c 100644
--- a/mkarchroot.in
+++ b/mkarchroot.in
@@ -12,89 +12,36 @@ m4_include(lib/common.sh)
CHROOT_VERSION='v3'
-MODE='m'
-NOCOPY='n'
-NONETWORK='n'
-
working_dir=''
-APPNAME=$(basename "${0}")
-
-# usage: usage <exitvalue>
usage() {
- echo "Usage: ${APPNAME} [options] working-dir [exta-arguments]"
+ echo "Usage: ${0##*/} [options] working-dir [package-list | app]"
echo ' options:'
echo ' -C <file> Location of a pacman config file'
echo ' -M <file> Location of a makepkg config file'
- echo ' -n Do not copy config files into the chroot'
echo ' -c <dir> Set pacman cache'
- echo ' -N Disable networking in the chroot'
- echo ' modes:'
- echo ' -m Make a new chroot in working-dir with packages'
- echo ' "extra-arguments" installed.'
- echo ' This is the default mode.'
- echo ' -r Run the command "extra-arguments" within the chroot'
- echo ' -u Update the chroot via pacman'
- echo ' -h Print this message'
-
- exit ${1-1}
+ echo ' -h This message'
+ exit 1
}
-################################################################################
-
-while getopts 'C:M:nc:Nmruh' arg; do
- case "${arg}" in
+while getopts 'hC:M:c:' arg; do
+ case "$arg" in
C) pac_conf="$OPTARG" ;;
M) makepkg_conf="$OPTARG" ;;
- n) NOCOPY='y' ;;
c) cache_dir="$OPTARG" ;;
- N) NONETWORK='y' ;;
-
- m|r|u) MODE="$arg" ;;
- h) usage 0 ;;
-
- *) error "invalid argument '${arg}'"; usage ;;
+ h|?) usage ;;
+ *) error "invalid argument '$arg'"; usage ;;
esac
done
-
shift $(($OPTIND - 1))
-case $MODE in
- m)
- case $# in
- 0) die 'You must specify a directory and one or more packages.' ;;
- 1) die 'You must specify one or more packages.' ;;
- esac
- ;;
- r)
- case $# in
- 0) die 'You must specify a directory and a command.' ;;
- 1) die 'You must specify a command.' ;;
- esac
- ;;
- u)
- case $# in
- 0) die 'You must specify a directory.' ;;
- 1) : ;;
- 2) die 'Extra arguments' ;;
- esac
- ;;
-esac
-
-working_dir="$(readlink -f "${1}")"
-shift 1
-[[ -z $working_dir ]] && die 'Please specify a working directory.'
+(( $EUID != 0 )) && die 'This script must be run as root.'
+(( $# < 2 )) && die 'You must specify a directory and one or more packages.'
-if [[ $MODE == u ]]; then
- MODE=r
- set -- pacman -Syu --noconfirm
-fi
-
-################################################################################
+working_dir="$(readlink -f $1)"
+shift 1
-if (( $EUID != 0 )); then
- die 'This script must be run as root.'
-fi
+[[ -z $working_dir ]] && die 'Please specify a working directory.'
if [[ -z $cache_dir ]]; then
cache_dirs=($(pacman -v $cache_conf 2>&1 | grep '^Cache Dirs:' | sed 's/Cache Dirs:\s*//g'))
@@ -102,111 +49,47 @@ else
cache_dirs=(${cache_dir})
fi
-host_mirror=$(pacman -Sddp extra/devtools 2>/dev/null | sed -E 's#(.*/)extra/os/.*#\1$repo/os/$arch#')
-if echo "${host_mirror}" | grep -q 'file://'; then
- host_mirror_path=$(echo "${host_mirror}" | sed -E 's#file://(/.*)/\$repo/os/\$arch#\1#g')
-fi
-
# {{{ functions
-build_mount_args() {
- local p
- declare -g mount_args=()
-
- if [[ -n $host_mirror_path ]]; then
- printf -v p '%q' "$host_mirror_path"
- mount_args+=(--bind-ro="$p")
- fi
-
- printf -v p '%q' "${cache_dirs[0]}"
- mount_args+=(--bind="$p")
-
- for cache_dir in ${cache_dirs[@]:1}; do
- printf -v p '%q' "$cache_dir"
- mount_args+=(--bind-ro="$p")
- done
-}
-
-copy_hostconf () {
- cp -a /etc/pacman.d/gnupg "${working_dir}/etc/pacman.d"
- echo "Server = ${host_mirror}" > ${working_dir}/etc/pacman.d/mirrorlist
-
- if [[ -n $pac_conf && $NOCOPY = 'n' ]]; then
- cp ${pac_conf} ${working_dir}/etc/pacman.conf
- fi
-
- if [[ -n $makepkg_conf && $NOCOPY = 'n' ]]; then
- cp ${makepkg_conf} ${working_dir}/etc/makepkg.conf
- fi
-
- sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${cache_dirs[@]})|g" -i ${working_dir}/etc/pacman.conf
-}
-
chroot_lock () {
- lock_open_write 9 "${working_dir}" "Locking chroot"
-}
+ # Only reopen the FD if it wasn't handed to us
+ if [[ $(readlink -f /dev/fd/9) != "${working_dir}.lock" ]]; then
+ exec 9>"${working_dir}.lock"
+ fi
-chroot_run() {
- local dir=$1
- shift
- local nspawn_args=(-D "$dir" "${mount_args[@]}")
- if [[ $NONETWORK = y ]]; then
- nspawn_args+=(--private-network)
+ # Lock the chroot. Take note of the FD number.
+ if ! flock -n 9; then
+ stat_busy "Locking chroot"
+ flock 9
+ stat_done
fi
- systemd-nspawn "${nspawn_args[@]}" -- "${@}" 2>/dev/null
}
-
# }}}
umask 0022
-if [[ $MODE == r ]]; then
- # run chroot {{{
- #Sanity check
- if [[ ! -f "${working_dir}/.arch-chroot" ]]; then
- die "'${working_dir}' does not appear to be a Arch chroot."
- elif [[ $(cat "${working_dir}/.arch-chroot") != ${CHROOT_VERSION} ]]; then
- die "'${working_dir}' is not compatible with ${APPNAME} version ${CHROOT_VERSION}. Please rebuild."
- fi
-
- chroot_lock
- build_mount_args
- copy_hostconf
-
- chroot_run "${working_dir}" "$@"
-
- # }}}
-elif [[ $MODE == m ]]; then
- # {{{ build chroot
- if [[ -e $working_dir ]]; then
- die "Working directory '${working_dir}' already exists"
- fi
- mkdir -p "${working_dir}"
+[[ -e $working_dir ]] && die "Working directory '$working_dir' already exists"
- if [[ "$(stat -f -c %T "${working_dir}")" == btrfs ]]; then
- rmdir "${working_dir}"
- if ! btrfs subvolume create "${working_dir}"; then
- die "Couldn't create subvolume for '${working_dir}'"
- fi
- chmod 0755 "${working_dir}"
- fi
-
- chroot_lock
+mkdir -p "$working_dir"
- pacargs=("${cache_dirs[@]/#/--cachedir=}")
- if [[ -n $pac_conf ]]; then
- pacargs+=("--config=${pac_conf}")
- fi
+chroot_lock
- if ! pacstrap -GMcd "${working_dir}" "${pacargs[@]}" "$@"; then
- die 'Failed to install all packages'
+if [[ $(stat -f -c %T "$working_dir") == btrfs ]]; then
+ rmdir "$working_dir"
+ if ! btrfs subvolume create "$working_dir"; then
+ die "Couldn't create subvolume for '$working_dir'"
fi
+ chmod 0755 "$working_dir"
+fi
- printf '%s.UTF-8 UTF-8\n' en_US de_DE > "${working_dir}/etc/locale.gen"
- chroot_run "${working_dir}" locale-gen
- echo 'LANG=C' > "${working_dir}/etc/locale.conf"
+pacstrap -GMcd ${pac_conf:+-C "$pac_conf"} "$working_dir" \
+ "${cache_dirs[@]/#/--cachedir=}" "$@" || die 'Failed to install all packages'
- copy_hostconf
+printf '%s.UTF-8 UTF-8\n' en_US de_DE > "$working_dir/etc/locale.gen"
+echo 'LANG=C' > "$working_dir/etc/locale.conf"
+echo "$CHROOT_VERSION" > "$working_dir/.arch-chroot"
- echo "${CHROOT_VERSION}" > "${working_dir}/.arch-chroot"
- # }}}
-fi
+exec arch-nspawn \
+ ${pac_conf:+-C "$pac_conf"} \
+ ${makepkg_conf:+-M "$makepkg_conf"} \
+ ${cache_dir:+-c "$cache_dir"} \
+ "$working_dir" locale-gen
diff --git a/zsh_completion.in b/zsh_completion.in
index c3abdfd..469df2f 100644
--- a/zsh_completion.in
+++ b/zsh_completion.in
@@ -1,4 +1,4 @@
-#compdef archbuild archco archrelease archrm commitpkg finddeps makechrootpkg mkarchroot rebuildpkgs extrapkg=commitpkg corepkg=commitpkg testingpkg=commitpkg stagingpkg=commitpkg communitypkg=commitpkg community-testingpkg=commitpkg community-stagingpkg=commitpkg multilibpkg=commitpkg multilib-testingpkg=commitpkg extra-i686-build=archbuild extra-x86_64-build=archbuild testing-i686-build=archbuild testing-x86_64-build=archbuild staging-i686-build=archbuild staging-x86_64-build=archbuild multilib-build=archbuild multilib-testing-build=archbuild multilib-staging-build=archbuild kde-unstable-i686-build=archbuild kde-unstable-x86_64-build=archbuild gnome-unstable-i686-build=archbuild gnome-unstable-x86_64-build=archbuild communityco=archco
+#compdef archbuild archco arch-nspawn archrelease archrm commitpkg finddeps makechrootpkg mkarchroot rebuildpkgs extrapkg=commitpkg corepkg=commitpkg testingpkg=commitpkg stagingpkg=commitpkg communitypkg=commitpkg community-testingpkg=commitpkg community-stagingpkg=commitpkg multilibpkg=commitpkg multilib-testingpkg=commitpkg extra-i686-build=archbuild extra-x86_64-build=archbuild testing-i686-build=archbuild testing-x86_64-build=archbuild staging-i686-build=archbuild staging-x86_64-build=archbuild multilib-build=archbuild multilib-testing-build=archbuild multilib-staging-build=archbuild kde-unstable-i686-build=archbuild kde-unstable-x86_64-build=archbuild gnome-unstable-i686-build=archbuild gnome-unstable-x86_64-build=archbuild communityco=archco
m4_include(lib/valid-tags.sh)
@@ -11,6 +11,13 @@ _archco_args=(
'*:packages:_devtools_completions_all_packages'
)
+_arch_nspawn_args=(
+ '-C[Location of a pacman config file]:pacman_config:_files'
+ '-M[Location of a makepkg config file]:makepkg_config:_files'
+ '-c[Set pacman cache]:pacman_cache:_files -/'
+ '-h[Display usage]'
+)
+
_archrelease_args=(
"*:arch:($_tags[*])"
)
@@ -40,11 +47,8 @@ _makechrootpkg_args=(
)
_mkarchroot_args=(
- '-r[Run a program within the context of the chroot]:app'
- '-u[Update the chroot via pacman]'
'-C[Location of a pacman config file]:pacman_config:_files'
'-M[Location of a makepkg config file]:makepkg_config:_files'
- '-n[Do not copy config files into the chroot]'
'-c[Set pacman cache]:pacman_cache:_files -/'
'-h[Display usage]'
)
@@ -61,7 +65,7 @@ _devtools_completions_all_packages() {
}
_devtools() {
- local argname="_${service}_args[@]"
+ local argname="_${service//-/_}_args[@]"
_arguments -s "${(P)argname}"
}