From 294543f415c50b7fbcee7e9794cda1ba80bf7fd8 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 2 Dec 2012 19:08:41 -0500 Subject: fix a bug in makechrootpkg.in --- makechrootpkg.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index 05286c6..244700c 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -119,7 +119,7 @@ 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 - lock_open_read 8 "$chrootdir/root.lock" "Locking clean chroot" + lock_open_read 8 "$chrootdir/root" "Locking clean chroot" stat_busy 'Creating clean working copy' use_rsync=false -- cgit v1.2.2 From ad5a0cc59ccf5c0927323db081686f902cbbca28 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 2 Dec 2012 20:39:58 -0500 Subject: lib/common.sh: create directories for locks if they don't exist --- lib/common.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/common.sh b/lib/common.sh index 5204091..932799e 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -113,6 +113,7 @@ lock_open_write() { # Only reopen the FD if it wasn't handed to us if [[ $(readlink -f /dev/fd/$fd) != "${path}.lock" ]]; then + mkdir -p "${path%/*}" eval "exec $fd>${path}.lock" fi @@ -133,6 +134,7 @@ lock_open_read() { # Only reopen the FD if it wasn't handed to us if [[ $(readlink -f /dev/fd/$fd) != "${path}.lock" ]]; then + mkdir -p "${path%/*}" eval "exec $fd>${path}.lock" fi -- cgit v1.2.2 From 68438c5cc1a43aaf7b3f93aa39b63bd1877e542b Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 2 Dec 2012 20:40:49 -0500 Subject: mkarchroot: fix bug with lock file name --- mkarchroot.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkarchroot.in b/mkarchroot.in index 7b6adf7..6dd8003 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -186,7 +186,7 @@ trap_chroot_umount () { } chroot_lock () { - lock_open_write 9 "${working_dir}.lock" "Locking chroot"u + lock_open_write 9 "${working_dir}" "Locking chroot" } chroot_run() { -- cgit v1.2.2 From b4d5cad408161af5fc551c62bee5b69d424a9d17 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 2 Dec 2012 20:43:20 -0500 Subject: mkarchroot: fix bug where a umount error would abort all umounts --- mkarchroot.in | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mkarchroot.in b/mkarchroot.in index 6dd8003..7473a01 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -162,9 +162,12 @@ copy_hostconf () { sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${cache_dirs[@]})|g" -i ${working_dir}/etc/pacman.conf } +trap_unmount_err () { + error "Error unmounting" +} + trap_chroot_umount () { - trap 'trap_abort' INT QUIT TERM HUP - trap 'trap_exit' EXIT + trap 'trap_unmount_err' INT QUIT TERM HUP EXIT for cache_dir in ${cache_dirs[@]}; do umount "${working_dir}/${cache_dir}" @@ -183,6 +186,9 @@ trap_chroot_umount () { umount "${working_dir}/dev" umount "${working_dir}/run" fi + + trap 'trap_abort' INT QUIT TERM HUP + trap 'trap_exit' EXIT } chroot_lock () { -- cgit v1.2.2 From a2346ecb02de3d30c4d2bbb53f7e661854aa4df6 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 2 Dec 2012 21:05:03 -0500 Subject: mkarchroot: redo option parsing to make more sense. It is still compatable with the old way, with some hacks. --- mkarchroot.in | 75 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/mkarchroot.in b/mkarchroot.in index 7473a01..cb2135d 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -23,52 +23,87 @@ APPNAME=$(basename "${0}") # usage: usage usage() { - echo "Usage: ${APPNAME} [options] working-dir [package-list | app]" + echo "Usage: ${APPNAME} [options] working-dir [action]" echo ' options:' - echo ' -r Run "app" within the context of the chroot' - echo ' -u Update the chroot via pacman' echo ' -f Force overwrite of files in the working-dir' echo ' -C Location of a pacman config file' echo ' -M Location of a makepkg config file' echo ' -n Do not copy config files into the chroot' echo ' -c Set pacman cache' echo ' -N Disable networking in the chroot' - echo ' -h This message' - exit 1 + echo ' actions:' + echo ' -i Install "pkg-list" in the chroot.' + echo ' Creates the chroot if necessary, workding-dir must exist' + echo ' -r Run "cmd" within the context of the chroot' + echo ' -u Update the chroot via pacman' + echo ' -h Print this message' + + exit ${1-1} } -while getopts 'r:ufnhC:M:c:' arg; do +################################################################################ + +while getopts 'fC:M:nc:Nr:uh' arg; do case "${arg}" in - r) RUN="$OPTARG" ;; - u) RUN='/bin/sh -c "pacman -Syu --noconfirm && (pacman -Qqu >/dev/null && pacman -Su --noconfirm || exit 0)"' ;; f) FORCE='y' ;; C) pac_conf="$OPTARG" ;; M) makepkg_conf="$OPTARG" ;; n) NOCOPY='y' ;; c) cache_dir="$OPTARG" ;; N) NONETWORK='y' ;; - h|?) usage ;; + + r) action="-$arg"; action_arg="$OPTARG" ;; + u|h) action="-$arg" ;; + *) error "invalid argument '${arg}'"; usage ;; esac done -if (( $EUID != 0 )); then - die 'This script must be run as root.' -fi - shift $(($OPTIND - 1)) -if [[ -z $RUN ]] && (( $# < 2 )); then - die 'You must specify a directory and one or more packages.' -elif (( $# < 1 )); then - die 'You must specify a directory.' +if [[ -n $action ]]; then + case $# in + 0) error 'You must specify a directory.'; usage ;; + 1) + args=("$1" "$action") + [[ -n $action_arg ]] && args+=("$action_arg") + set -- "${args[@]}" + unset args action action_arg + ;; + *) error 'Extra arguments.'; usage ;; + esac +else + if (( $# < 2 )); then + error 'You must specify a directory and an action.' + usage + fi fi -working_dir="$(readlink -f ${1})" +working_dir="$(readlink -f "${1}")" shift 1 - [[ -z $working_dir ]] && die 'Please specify a working directory.' +action=$1 +shift 1 +case "$action" in + -i) PKGS=("$@") ;; + -r) RUN="$*" ;; + -u) + (( $# > 0 )) && { error 'Extra arguments.'; usage; } + RUN='/bin/sh -c "pacman -Syu --noconfirm && (pacman -Qqu >/dev/null && pacman -Su --noconfirm || exit 0)"' + ;; + -h) usage 0 ;; + -*) error "invalid argument '${action#-}'"; usage ;; + *) PKGS=("$action" "$@") ;; # for compatability with mkarchroot +esac +unset action + +################################################################################ + +if (( $EUID != 0 )); then + die 'This script must be run as root.' +fi + if [[ -z $cache_dir ]]; then cache_dirs=($(pacman -v $cache_conf 2>&1 | grep '^Cache Dirs:' | sed 's/Cache Dirs:\s*//g')) else @@ -259,7 +294,7 @@ else if [[ $FORCE = 'y' ]]; then pacargs="$pacargs --force" fi - if ! pacstrap -GMcd "${working_dir}" ${pacargs} $@; then + if ! pacstrap -GMcd "${working_dir}" ${pacargs} "${PKGS[@]}"; then die 'Failed to install all packages' fi fi -- cgit v1.2.2 From 9526f3d12d80fb06b3ddd27432ef232478f92dee Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 2 Dec 2012 21:07:54 -0500 Subject: drop mkarchroot compatability code --- mkarchroot.in | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/mkarchroot.in b/mkarchroot.in index cb2135d..aeeacc2 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -43,7 +43,7 @@ usage() { ################################################################################ -while getopts 'fC:M:nc:Nr:uh' arg; do +while getopts 'fC:M:nc:Nh' arg; do case "${arg}" in f) FORCE='y' ;; C) pac_conf="$OPTARG" ;; @@ -52,8 +52,7 @@ while getopts 'fC:M:nc:Nr:uh' arg; do c) cache_dir="$OPTARG" ;; N) NONETWORK='y' ;; - r) action="-$arg"; action_arg="$OPTARG" ;; - u|h) action="-$arg" ;; + h) action="-$arg" ;; *) error "invalid argument '${arg}'"; usage ;; esac @@ -61,22 +60,9 @@ done shift $(($OPTIND - 1)) -if [[ -n $action ]]; then - case $# in - 0) error 'You must specify a directory.'; usage ;; - 1) - args=("$1" "$action") - [[ -n $action_arg ]] && args+=("$action_arg") - set -- "${args[@]}" - unset args action action_arg - ;; - *) error 'Extra arguments.'; usage ;; - esac -else - if (( $# < 2 )); then - error 'You must specify a directory and an action.' - usage - fi +if (( $# < 2 )); then + error 'You must specify a directory and an action.' + usage fi working_dir="$(readlink -f "${1}")" @@ -94,7 +80,7 @@ case "$action" in ;; -h) usage 0 ;; -*) error "invalid argument '${action#-}'"; usage ;; - *) PKGS=("$action" "$@") ;; # for compatability with mkarchroot + *) error "invalid action '${action}'"; usage ;; esac unset action -- cgit v1.2.2