summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archbuild.in9
-rw-r--r--lib/common.sh49
-rw-r--r--makechrootpkg.in19
-rw-r--r--mkarchroot.in27
4 files changed, 69 insertions, 35 deletions
diff --git a/archbuild.in b/archbuild.in
index 10d33b8..a41d490 100644
--- a/archbuild.in
+++ b/archbuild.in
@@ -43,17 +43,12 @@ if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then
[[ -d $copy ]] || continue
msg2 "Deleting chroot copy '$(basename "${copy}")'..."
- exec 9>"$copydir.lock"
- if ! flock -n 9; then
- stat_busy "Locking chroot copy '$copy'"
- flock 9
- stat_done
- fi
+ lock_open_write 9 "$copy.lock" "Locking chroot copy '$copy'"
{ type -P btrfs && btrfs subvolume delete "${copy}"; } &>/dev/null
rm -rf --one-file-system "${copy}"
done
- exec 9>&-
+ lock_close 9
rm -rf --one-file-system "${chroots}/${repo}-${arch}"
mkdir -p "${chroots}/${repo}-${arch}"
diff --git a/lib/common.sh b/lib/common.sh
index b39bbbc..5204091 100644
--- a/lib/common.sh
+++ b/lib/common.sh
@@ -104,6 +104,55 @@ in_array() {
}
##
+# usage : lock_open_write( $fd, $path, $wait_message )
+##
+lock_open_write() {
+ local fd=$1
+ local path=$2
+ local msg=$3
+
+ # Only reopen the FD if it wasn't handed to us
+ if [[ $(readlink -f /dev/fd/$fd) != "${path}.lock" ]]; then
+ eval "exec $fd>${path}.lock"
+ fi
+
+ if ! flock -n $fd; then
+ stat_busy "$msg"
+ flock $fd
+ stat_done
+ fi
+}
+
+##
+# usage : lock_open_read( $fd, $path, $wait_message )
+##
+lock_open_read() {
+ local fd=$1
+ local path=$2
+ local msg=$3
+
+ # Only reopen the FD if it wasn't handed to us
+ if [[ $(readlink -f /dev/fd/$fd) != "${path}.lock" ]]; then
+ eval "exec $fd>${path}.lock"
+ fi
+
+ if ! flock -sn $fd; then
+ stat_busy "$msg"
+ flock -s $fd
+ stat_done
+ fi
+}
+
+
+##
+# usage : lock_close( $fd )
+##
+lock_close() {
+ local fd=$1
+ eval "exec $fd>&-"
+}
+
+##
# usage : get_full_version( [$pkgname] )
# return : full version spec, including epoch (if necessary), pkgver, pkgrel
##
diff --git a/makechrootpkg.in b/makechrootpkg.in
index 762ad7b..05286c6 100644
--- a/makechrootpkg.in
+++ b/makechrootpkg.in
@@ -114,23 +114,12 @@ umask 0022
# Lock the chroot we want to use. We'll keep this lock until we exit.
# Note this is the same FD number as in mkarchroot
-exec 9>"$copydir.lock"
-if ! flock -n 9; then
- stat_busy "Locking chroot copy '$copy'"
- flock 9
- stat_done
-fi
+lock_open_write 9 "$copydir.lock" "Locking chroot copy '$copy'"
if [[ ! -d $copydir ]] || $clean_first; then
# Get a read lock on the root chroot to make
# sure we don't clone a half-updated chroot
- exec 8>"$chrootdir/root.lock"
-
- if ! flock -sn 8; then
- stat_busy "Locking clean chroot"
- flock -s 8
- stat_done
- fi
+ lock_open_read 8 "$chrootdir/root.lock" "Locking clean chroot"
stat_busy 'Creating clean working copy'
use_rsync=false
@@ -149,7 +138,7 @@ if [[ ! -d $copydir ]] || $clean_first; then
stat_done
# Drop the read lock again
- exec 8>&-
+ lock_close 8
fi
if [[ -n $install_pkg ]]; then
@@ -267,7 +256,7 @@ cat >"$copydir/chrootbuild" <<EOF
export HOME=/build
cd /build
-sudo -u nobody makepkg $makepkg_args || touch BUILD_FAILED
+sudo -u nobody ${MAKEPKG:-makepkg} $makepkg_args || touch BUILD_FAILED
[[ -f BUILD_FAILED ]] && exit 1
diff --git a/mkarchroot.in b/mkarchroot.in
index cb95f8e..7b6adf7 100644
--- a/mkarchroot.in
+++ b/mkarchroot.in
@@ -15,6 +15,7 @@ CHROOT_VERSION='v2'
FORCE='n'
RUN=''
NOCOPY='n'
+NONETWORK='n'
working_dir=''
@@ -31,6 +32,7 @@ usage() {
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 ' -h This message'
exit 1
}
@@ -44,6 +46,7 @@ while getopts 'r:ufnhC:M:c:' arg; do
M) makepkg_conf="$OPTARG" ;;
n) NOCOPY='y' ;;
c) cache_dir="$OPTARG" ;;
+ N) NONETWORK='y' ;;
h|?) usage ;;
*) error "invalid argument '${arg}'"; usage ;;
esac
@@ -183,26 +186,24 @@ trap_chroot_umount () {
}
chroot_lock () {
- # 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
-
- # Lock the chroot. Take note of the FD number.
- if ! flock -n 9; then
- stat_busy "Locking chroot"
- flock 9
- stat_done
- fi
+ lock_open_write 9 "${working_dir}.lock" "Locking chroot"u
}
chroot_run() {
local dir=$1
shift
if (( have_nspawn)); then
- eval systemd-nspawn -D "${dir}" -- ${@} 2>/dev/null
+ local nspawn_args=(-D "$dir")
+ if [[ $NONETWORK = y ]]; then
+ nspawn_args+=(--private-network)
+ fi
+ eval systemd-nspawn "${nspawn_args[@]}" -- "${@}" 2>/dev/null
else
- eval unshare -mui -- chroot "${dir}" ${@}
+ local unshare_args=(-mui)
+ if [[ $NONETWORK = y ]]; then
+ unshare_args+=(-n)
+ fi
+ eval unshare "${unshare_args[@]}" -- chroot "${dir}" "${@}"
fi
}