summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archbuild.in4
-rw-r--r--lib/common.sh66
-rw-r--r--makechrootpkg.in37
-rw-r--r--mkarchroot.in2
4 files changed, 69 insertions, 40 deletions
diff --git a/archbuild.in b/archbuild.in
index b1c96f9..06b9d4b 100644
--- a/archbuild.in
+++ b/archbuild.in
@@ -51,14 +51,14 @@ if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then
[[ -d $copy ]] || continue
msg2 "Deleting chroot copy '$(basename "${copy}")'..."
- lock 9 "$copydir.lock" "Locking chroot copy '$copy'"
+ lock 9 "$copy.lock" "Locking chroot copy '$copy'"
if [[ "$(stat -f -c %T "${copy}")" == btrfs ]]; then
{ type -P btrfs && btrfs subvolume delete "${copy}"; } &>/dev/null
fi
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 3ec26ff..c9deebc 100644
--- a/lib/common.sh
+++ b/lib/common.sh
@@ -2,7 +2,7 @@
export LANG=C
# check if messages are to be printed using color
-unset ALL_OFF BOLD BLUE GREEN RED YELLOW
+declare ALL_OFF= BOLD= BLUE= GREEN= RED= YELLOW=
if [[ -t 2 ]]; then
# prefer terminal safe colored and bold text when tput is supported
if tput setaf 0 &>/dev/null; then
@@ -40,12 +40,12 @@ msg2() {
warning() {
local mesg=$1; shift
- printf "${YELLOW}==> WARNING:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+ printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
error() {
local mesg=$1; shift
- printf "${RED}==> ERROR:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+ printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
stat_busy() {
@@ -54,16 +54,22 @@ stat_busy() {
}
stat_done() {
- printf "${BOLD}done${ALL_OFF}\n" >&2
+ printf "${BOLD}$(gettext "done")${ALL_OFF}\n" >&2
}
+_setup_workdir=false
setup_workdir() {
- [[ -z $WORKDIR ]] && WORKDIR=$(mktemp -d --tmpdir "${0##*/}.XXXXXXXXXX")
+ [[ -z ${WORKDIR:-} ]] && WORKDIR=$(mktemp -d --tmpdir "${0##*/}.XXXXXXXXXX")
+ _setup_workdir=true
+ trap 'trap_abort' INT QUIT TERM HUP
+ trap 'trap_exit' EXIT
}
cleanup() {
- [[ -n $WORKDIR ]] && rm -rf "$WORKDIR"
- [[ $1 ]] && exit $1
+ if [[ -n ${WORKDIR:-} ]] && $_setup_workdir; then
+ rm -rf "$WORKDIR"
+ fi
+ [[ -n ${1:-} ]] && exit $1
}
abort() {
@@ -86,9 +92,6 @@ die() {
cleanup 1
}
-trap 'trap_abort' INT QUIT TERM HUP
-trap 'trap_exit' EXIT
-
##
# usage : in_array( $needle, $haystack )
# return : 0 - found
@@ -135,10 +138,19 @@ get_full_version() {
# usage : lock( $fd, $file, $message )
##
lock() {
- eval "exec $1>"'"$2"'
- if ! flock -n $1; then
- stat_busy "$3"
- flock $1
+ local fd=$1
+ local file=$2
+ local mesg=$3
+
+ # Only reopen the FD if it wasn't handed to us
+ if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "$file")" ]]; then
+ mkdir -p "${file%/*}"
+ eval "exec $fd>"'"$file"'
+ fi
+
+ if ! flock -n $fd; then
+ stat_busy "$mesg"
+ flock $fd
stat_done
fi
}
@@ -147,10 +159,28 @@ lock() {
# usage : slock( $fd, $file, $message )
##
slock() {
- eval "exec $1>"'"$2"'
- if ! flock -sn $1; then
- stat_busy "$3"
- flock -s $1
+ local fd=$1
+ local file=$2
+ local mesg=$3
+
+ # Only reopen the FD if it wasn't handed to us
+ if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "$file")" ]]; then
+ mkdir -p "${file%/*}"
+ eval "exec $fd>"'"$file"'
+ fi
+
+ eval "exec $fd>"'"$file"'
+ if ! flock -sn $fd; then
+ stat_busy "$mesg"
+ flock -s $fd
stat_done
fi
}
+
+##
+# usage : lock_close( $fd )
+##
+lock_close() {
+ local fd=$1
+ eval "exec $fd>&-"
+}
diff --git a/makechrootpkg.in b/makechrootpkg.in
index 1cd08fb..ce003c8 100644
--- a/makechrootpkg.in
+++ b/makechrootpkg.in
@@ -12,7 +12,8 @@ m4_include(lib/common.sh)
shopt -s nullglob
-makepkg_args='-s --noconfirm -L --holdver'
+_makepkg_args=(-s --noconfirm -L --holdver)
+makepkg_args=("${_makepkg_args[@]}")
repack=false
update_first=false
clean_first=false
@@ -43,7 +44,7 @@ usage() {
echo 'command:'
echo ' mkarchroot <chrootdir>/root base-devel'
echo ''
- echo "Default makepkg args: $makepkg_args"
+ echo "Default makepkg args: ${_makepkg_args[*]}"
echo ''
echo 'Flags:'
echo '-h This help'
@@ -69,11 +70,12 @@ while getopts 'hcur:I:l:nT' arg; do
r) passeddir="$OPTARG" ;;
I) install_pkgs+=("$OPTARG") ;;
l) copy="$OPTARG" ;;
- n) run_namcap=true; makepkg_args="$makepkg_args -i" ;;
+ n) run_namcap=true; makepkg_args+=('-i') ;;
T) temp_chroot=true; copy+="-$$" ;;
- *) makepkg_args="$makepkg_args -$arg $OPTARG" ;;
+ *) usage >&2 ;;
esac
done
+shift $(($OPTIND - 1))
(( EUID != 0 )) && die 'This script must be run as root.'
@@ -94,15 +96,12 @@ else
fi
# Pass all arguments after -- right to makepkg
-makepkg_args="$makepkg_args ${*:$OPTIND}"
+makepkg_args+=("$@")
# See if -R was passed to makepkg
-for arg in ${*:$OPTIND}; do
- if [[ $arg = -R ]]; then
- repack=true
- break
- fi
-done
+if in_array '-R' "${makepkg_args[@]}"; then
+ repack=true
+fi
if [[ -n $SUDO_USER ]]; then
USER_HOME=$(eval echo ~$SUDO_USER)
@@ -147,7 +146,7 @@ create_chroot() {
stat_done
# Drop the read lock again
- exec 8>&-
+ lock_close 8
fi
}
@@ -238,8 +237,8 @@ EOF
# This is a little gross, but this way the script is recreated every time in the
# working copy
- printf $'#!/bin/bash\n%s\n_chrootbuild %q %q' "$(declare -f _chrootbuild)" \
- "$makepkg_args" "$run_namcap" >"$copydir/chrootbuild"
+ printf $'#!/bin/bash\n%s\n_chrootbuild %q "$@"' "$(declare -f _chrootbuild)" \
+ "$run_namcap" >"$copydir/chrootbuild"
chmod +x "$copydir/chrootbuild"
}
@@ -265,8 +264,8 @@ download_sources() {
_chrootbuild() {
# This function isn't run in makechrootpkg,
# so no global variables
- local makepkg_args="$1"
- local run_namcap="$2"
+ local run_namcap="$1"; shift
+ local makepkg_args=("$@")
. /etc/profile
export HOME=/build
@@ -300,7 +299,7 @@ _chrootbuild() {
exit 1
fi
- sudo -u nobody makepkg $makepkg_args || exit 1
+ sudo -u nobody makepkg "${makepkg_args[@]}" || exit 1
if $run_namcap; then
pacman -S --needed --noconfirm namcap
@@ -328,8 +327,8 @@ move_products() {
umask 0022
-load_vars "$USER_HOME/.makepkg.conf"
load_vars /etc/makepkg.conf
+load_vars "$USER_HOME/.makepkg.conf"
# Use PKGBUILD directory if these don't exist
[[ -d $PKGDEST ]] || PKGDEST=$PWD
@@ -349,7 +348,7 @@ download_sources
if arch-nspawn "$copydir" \
--bind-ro="$PWD:/startdir_host" \
--bind-ro="$SRCDEST:/srcdest_host" \
- /chrootbuild
+ /chrootbuild "${makepkg_args[@]}"
then
move_products
else
diff --git a/mkarchroot.in b/mkarchroot.in
index 7cdb274..ba92e15 100644
--- a/mkarchroot.in
+++ b/mkarchroot.in
@@ -15,7 +15,7 @@ CHROOT_VERSION='v3'
working_dir=''
usage() {
- echo "Usage: ${0##*/} [options] working-dir [package-list | app]"
+ echo "Usage: ${0##*/} [options] working-dir package-list..."
echo ' options:'
echo ' -C <file> Location of a pacman config file'
echo ' -M <file> Location of a makepkg config file'