From 2343d5c3c034c2597a034f5a5de9373d7e076e60 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 25 Nov 2012 19:58:39 -0500 Subject: fix locking bug in archbuild (likely bad copy-paste) --- archbuild.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archbuild.in b/archbuild.in index 00234f3..7220391 100644 --- a/archbuild.in +++ b/archbuild.in @@ -43,7 +43,7 @@ if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then [[ -d $copy ]] || continue msg2 "Deleting chroot copy '$(basename "${copy}")'..." - exec 9>"$copydir.lock" + exec 9>"$copy.lock" if ! flock -n 9; then stat_busy "Locking chroot copy '$copy'" flock 9 -- cgit v1.2.3-70-g09d2 From e9836b6b2afa70f22d305509593b375543b20ba6 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 25 Nov 2012 20:05:09 -0500 Subject: Use common functions to handle file locking * lib/common.sh: implement - lock_open_write() - lock_open_read() - lock_close() * archbuild.in, makechrootpkg.in, mkarchroot.in: use said functions This has two benefits: 1. All programs using these methods gain the ability to inherit locks, something that only mkarchroot could do before. This allows the commands to be more compos-able. 2. It is more readable. File locking isn't obvious. --- archbuild.in | 9 ++------- lib/common.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ makechrootpkg.in | 17 +++-------------- mkarchroot.in | 12 +----------- 4 files changed, 55 insertions(+), 32 deletions(-) diff --git a/archbuild.in b/archbuild.in index 7220391..9476415 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>"$copy.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 @@ -103,6 +103,55 @@ in_array() { return 1 # Not Found } +## +# 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 6c0b013..f3333ca 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 diff --git a/mkarchroot.in b/mkarchroot.in index 76ad840..022943e 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -183,17 +183,7 @@ 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() { -- cgit v1.2.3-70-g09d2 From bc7c9c19f00a161edce3a35c51d8164baee35f40 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 26 Nov 2012 01:32:37 -0500 Subject: makechrootpkg: read $MAKEPKG --- makechrootpkg.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index f3333ca..b635432 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -256,7 +256,7 @@ cat >"$copydir/chrootbuild" < Date: Mon, 26 Nov 2012 01:48:37 -0500 Subject: mkarchroot: learn -N to disable networking in the chroot Also, fix quoting in chroot_run --- mkarchroot.in | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mkarchroot.in b/mkarchroot.in index 022943e..308f5d3 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 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 } @@ -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 0 ;; *) error "invalid argument '${arg}'"; usage ;; esac @@ -190,9 +193,17 @@ 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 } -- cgit v1.2.3-70-g09d2 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.3-70-g09d2 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.3-70-g09d2 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.3-70-g09d2 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.3-70-g09d2 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.3-70-g09d2 From f54791c247344f4077f1f25f933e62e7e45e3ab7 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 24 Apr 2013 12:21:38 -0400 Subject: once again re-do option handling for mkarchroot --- mkarchroot.in | 83 ++++++++++++++++++++++++++++------------------------------- 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/mkarchroot.in b/mkarchroot.in index 8cf9474..bfdec39 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -13,7 +13,7 @@ m4_include(lib/common.sh) CHROOT_VERSION='v2' FORCE='n' -RUN='' +MODE='i' NOCOPY='n' NONETWORK='n' @@ -23,7 +23,7 @@ APPNAME=$(basename "${0}") # usage: usage usage() { - echo "Usage: ${APPNAME} [options] working-dir [action]" + echo "Usage: ${APPNAME} [options] working-dir [exta-arguments]" echo ' options:' echo ' -f Force overwrite of files in the working-dir' echo ' -C Location of a pacman config file' @@ -31,10 +31,11 @@ usage() { echo ' -n Do not copy config files into the chroot' echo ' -c Set pacman cache' echo ' -N Disable networking in the chroot' - 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 ' modes:' + echo ' -i Install the packages "extra-arguments" in the chroot.' + echo ' This creates the chroot if it does not exist.' + 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' @@ -43,7 +44,7 @@ usage() { ################################################################################ -while getopts 'fC:M:nc:Nr:uh' arg; do +while getopts 'fC:M:nc:Niruh' arg; do case "${arg}" in f) FORCE='y' ;; C) pac_conf="$OPTARG" ;; @@ -52,8 +53,8 @@ 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" ;; + i|r|u) MODE="$arg" ;; + h) usage 0 ;; *) error "invalid argument '${arg}'"; usage ;; esac @@ -61,42 +62,36 @@ 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 -fi +case $MODE in + i) + 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.' -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 [[ $MODE == u ]]; then + MODE=r + set -- /bin/sh -c 'pacman -Syu --noconfirm && (pacman -Qqu >/dev/null && pacman -Su --noconfirm || exit 0)' +fi ################################################################################ @@ -166,7 +161,7 @@ chroot_run() { # }}} umask 0022 -if [[ -n $RUN ]]; then +if [[ $MODE == r ]]; then # run chroot {{{ #Sanity check if [[ ! -f "${working_dir}/.arch-chroot" ]]; then @@ -179,10 +174,10 @@ if [[ -n $RUN ]]; then build_mount_args copy_hostconf - chroot_run "${working_dir}" ${RUN} + chroot_run "${working_dir}" "$@" # }}} -else +elif [[ $MODE == i ]]; then # {{{ build chroot if [[ -e $working_dir && $FORCE = 'n' ]]; then die "Working directory '${working_dir}' already exists - try using -f" @@ -206,7 +201,7 @@ else if [[ $FORCE = 'y' ]]; then pacargs+=("--force") fi - if ! pacstrap -GMcd "${working_dir}" "${pacargs[@]}" "${PKGS[@]}"; then + if ! pacstrap -GMcd "${working_dir}" "${pacargs[@]}" "$@"; then die 'Failed to install all packages' fi -- cgit v1.2.3-70-g09d2 From 474fabf287cca3c65175bf05a75ae850326d9c36 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 25 Apr 2013 19:13:54 -0400 Subject: lib/common.sh: Make setup_workdir()/cleanup() safe for programs to not use --- lib/common.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/common.sh b/lib/common.sh index 932799e..d6fbe7c 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -57,13 +57,19 @@ stat_done() { printf "${BOLD}done${ALL_OFF}\n" >&2 } +_setup_workdir=false setup_workdir() { [[ -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 -- cgit v1.2.3-70-g09d2 From 705f41e25cdf89bccef22a76a163f2ea52603979 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 30 Apr 2013 21:48:54 -0400 Subject: makechrootpkg.in: adjust mkarchroot usage to our version --- makechrootpkg.in | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index 10956c9..b98951f 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -12,6 +12,12 @@ 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 @@ -151,7 +157,7 @@ if [[ -n "${install_pkgs[*]}" ]]; then pkgname="${install_pkg##*/}" cp "$install_pkg" "$copydir/$pkgname" - mkarchroot -r "pacman -U /$pkgname --noconfirm" "$copydir" + archroot -r "$copydir" pacman -U "/$pkgname" --noconfirm (( ret += !! $? )) rm "$copydir/$pkgname" @@ -161,7 +167,7 @@ if [[ -n "${install_pkgs[*]}" ]]; then [[ -f PKGBUILD ]] || exit $ret fi -$update_first && mkarchroot -u "$copydir" +$update_first && archroot -u "$copydir" mkdir -p "$copydir/build" @@ -277,7 +283,7 @@ exit 0 EOF chmod +x "$copydir/chrootbuild" -if mkarchroot -r "/chrootbuild" "$copydir"; then +if archroot -r "$copydir" "/chrootbuild"; then for pkgfile in "$copydir"/pkgdest/*.pkg.tar.?z; do if $add_to_db; then mkdir -p "$copydir/repo" -- cgit v1.2.3-70-g09d2 From fd460d96a9c1fd08bbf87ee74e7d230665b0ec18 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 30 Apr 2013 21:55:08 -0400 Subject: makechrootpkg.in: make lock waiting messages more clear, fix .lock.lock bug --- makechrootpkg.in | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index b98951f..d1a37e7 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -127,12 +127,14 @@ chroottype=$(stat -f -c %T "$chrootdir") # 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 -lock_open_write 9 "$copydir.lock" "Locking chroot copy [$copy]" +lock_open_write 9 "$copydir" \ + "Waiting for existing lock on chroot copy to be released: [$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" "Locking clean chroot" + lock_open_read 8 "$chrootdir/root" \ + "Waiting for existing lock on clean chroot to be released" stat_busy "Creating clean working copy [$copy]" if [[ "$chroottype" == btrfs ]]; then -- cgit v1.2.3-70-g09d2 From a2e3dbe23e2ed0a85b9dd049fc45ec0b2bf9c3f4 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 2 May 2013 15:11:53 -0400 Subject: mkarchroot: rename mode -i (install) to -m (make) --- mkarchroot.in | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mkarchroot.in b/mkarchroot.in index a33ba59..d11c1e0 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -12,7 +12,7 @@ m4_include(lib/common.sh) CHROOT_VERSION='v3' -MODE='i' +MODE='m' NOCOPY='n' NONETWORK='n' @@ -30,8 +30,8 @@ usage() { echo ' -c Set pacman cache' echo ' -N Disable networking in the chroot' echo ' modes:' - echo ' -i Install the packages "extra-arguments" in the chroot.' - echo ' This creates the chroot if it does not exist.' + 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' @@ -42,7 +42,7 @@ usage() { ################################################################################ -while getopts 'C:M:nc:Niruh' arg; do +while getopts 'C:M:nc:Nmruh' arg; do case "${arg}" in C) pac_conf="$OPTARG" ;; M) makepkg_conf="$OPTARG" ;; @@ -50,7 +50,7 @@ while getopts 'C:M:nc:Niruh' arg; do c) cache_dir="$OPTARG" ;; N) NONETWORK='y' ;; - i|r|u) MODE="$arg" ;; + m|r|u) MODE="$arg" ;; h) usage 0 ;; *) error "invalid argument '${arg}'"; usage ;; @@ -60,7 +60,7 @@ done shift $(($OPTIND - 1)) case $MODE in - i) + m) case $# in 0) die 'You must specify a directory and one or more packages.' ;; 1) die 'You must specify one or more packages.' ;; @@ -174,7 +174,7 @@ if [[ $MODE == r ]]; then chroot_run "${working_dir}" "$@" # }}} -elif [[ $MODE == i ]]; then +elif [[ $MODE == m ]]; then # {{{ build chroot if [[ -e $working_dir ]]; then die "Working directory '${working_dir}' already exists" -- cgit v1.2.3-70-g09d2 From a1a79ff77bb19166bd5631953a71e3d3222e5f1c Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 2 May 2013 15:12:42 -0400 Subject: lib/common.sh: use gettext for WARNING/ERROR/done hardcoded text. --- lib/common.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) mode change 100644 => 100755 lib/common.sh diff --git a/lib/common.sh b/lib/common.sh old mode 100644 new mode 100755 index d6fbe7c..d1d958e --- a/lib/common.sh +++ b/lib/common.sh @@ -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,7 +54,7 @@ stat_busy() { } stat_done() { - printf "${BOLD}done${ALL_OFF}\n" >&2 + printf "${BOLD}$(gettext "done")${ALL_OFF}\n" >&2 } _setup_workdir=false -- cgit v1.2.3-70-g09d2 From ac0f1723e25cf0488af8a30f8212cfd1c05c6f90 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 14 May 2013 21:37:51 -0400 Subject: makechrootpkg.in: even though it is, don't require $pkgfile to be absolute when adding it to the local repo --- makechrootpkg.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index d1a37e7..05634d8 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -289,8 +289,8 @@ if archroot -r "$copydir" "/chrootbuild"; then for pkgfile in "$copydir"/pkgdest/*.pkg.tar.?z; do if $add_to_db; then mkdir -p "$copydir/repo" + cp "$pkgfile" "$copydir/repo" pushd "$copydir/repo" >/dev/null - cp "$pkgfile" . repo-add repo.db.tar.gz "${pkgfile##*/}" popd >/dev/null fi -- cgit v1.2.3-70-g09d2 From 89d15e7697da2169493142f78a90b57a784d8f22 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 14 May 2013 21:44:28 -0400 Subject: makechrootpkg.in: only run `makepkg "$copydir/repo"` once --- makechrootpkg.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index 05634d8..b0241f2 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -286,9 +286,9 @@ EOF chmod +x "$copydir/chrootbuild" if archroot -r "$copydir" "/chrootbuild"; then + mkdir -p "$copydir/repo" for pkgfile in "$copydir"/pkgdest/*.pkg.tar.?z; do if $add_to_db; then - mkdir -p "$copydir/repo" cp "$pkgfile" "$copydir/repo" pushd "$copydir/repo" >/dev/null repo-add repo.db.tar.gz "${pkgfile##*/}" -- cgit v1.2.3-70-g09d2 From 6b688fce29389b52e6a4f6cd9d911f0fe062e714 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 26 May 2013 20:20:07 -0400 Subject: undo accidental change of permissions on lib/common.sh --- lib/common.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 lib/common.sh diff --git a/lib/common.sh b/lib/common.sh old mode 100755 new mode 100644 -- cgit v1.2.3-70-g09d2 From d197eacf8b7aba0796a0f6ac6ac1667564bd614e Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 27 May 2013 00:40:54 -0400 Subject: common.sh: unset COLOR variables in a way that is `set -u` safe. --- lib/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/common.sh b/lib/common.sh index d1d958e..7c0a9d3 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 -- cgit v1.2.3-70-g09d2 From 731154ea8d232f614f32049eb420a85da0a323b1 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 3 Jun 2013 22:33:17 -0600 Subject: fix bugs with `set -u` in common.sh --- lib/common.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/common.sh b/lib/common.sh index 7c0a9d3..4cf9944 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -59,17 +59,17 @@ stat_done() { _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() { - if [[ -n $WORKDIR ]] && $_setup_workdir; then + if [[ -n ${WORKDIR:-} ]] && $_setup_workdir; then rm -rf "$WORKDIR" fi - [[ -n $1 ]] && exit $1 + [[ -n ${1:-} ]] && exit $1 } abort() { -- cgit v1.2.3-70-g09d2 From bf8513ae631484a0c292ad085ea7ede9859f8e0f Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 3 Jun 2013 22:34:58 -0600 Subject: lock_open_* fix possible bug caused symlinked directories If somewhere in the path to ${path}.lock there was a symlink, then it would fail to inherit the lock from the parent program, and stall. --- lib/common.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/common.sh b/lib/common.sh index 4cf9944..65d6d15 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -115,7 +115,7 @@ lock_open_write() { local msg=$3 # Only reopen the FD if it wasn't handed to us - if [[ $(readlink -f /dev/fd/$fd) != "${path}.lock" ]]; then + if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "${path}.lock")" ]]; then mkdir -p "${path%/*}" eval "exec $fd>${path}.lock" fi @@ -136,7 +136,7 @@ lock_open_read() { local msg=$3 # Only reopen the FD if it wasn't handed to us - if [[ $(readlink -f /dev/fd/$fd) != "${path}.lock" ]]; then + if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "${path}.lock")" ]]; then mkdir -p "${path%/*}" eval "exec $fd>${path}.lock" fi -- cgit v1.2.3-70-g09d2 From a7587c1289f41d9bed47939780b7e8252000211e Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 15 Jun 2013 11:04:42 -0600 Subject: redo the lock functions to not append .lock mkarchroot.in didn't need modified because it already (incorrectly) had .lock in the filename --- lib/common.sh | 12 ++++++------ makechrootpkg.in | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/common.sh b/lib/common.sh index 65d6d15..9f537c7 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -107,7 +107,7 @@ in_array() { } ## -# usage : lock_open_write( $fd, $path, $wait_message ) +# usage : lock_open_write( $fd, $path.lock, $wait_message ) ## lock_open_write() { local fd=$1 @@ -115,9 +115,9 @@ lock_open_write() { local msg=$3 # Only reopen the FD if it wasn't handed to us - if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "${path}.lock")" ]]; then + if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "${path}")" ]]; then mkdir -p "${path%/*}" - eval "exec $fd>${path}.lock" + eval "exec $fd>${path}" fi if ! flock -n $fd; then @@ -128,7 +128,7 @@ lock_open_write() { } ## -# usage : lock_open_read( $fd, $path, $wait_message ) +# usage : lock_open_read( $fd, $path.lock, $wait_message ) ## lock_open_read() { local fd=$1 @@ -136,9 +136,9 @@ lock_open_read() { local msg=$3 # Only reopen the FD if it wasn't handed to us - if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "${path}.lock")" ]]; then + if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "${path}")" ]]; then mkdir -p "${path%/*}" - eval "exec $fd>${path}.lock" + eval "exec $fd>${path}" fi if ! flock -sn $fd; then diff --git a/makechrootpkg.in b/makechrootpkg.in index 0164754..a0941b4 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -121,13 +121,13 @@ chroottype=$(stat -f -c %T "$chrootdir") # 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 -lock_open_write 9 "$copydir" \ +lock_open_write 9 "$copydir.lock" \ "Waiting for existing lock on chroot copy to be released: [$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_open_read 8 "$chrootdir/root.lock" \ "Waiting for existing lock on clean chroot to be released" stat_busy "Creating clean working copy [$copy]" -- cgit v1.2.3-70-g09d2 From 8db300d17736e3f7e2200d2e2501e3827ba28546 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 15 Jun 2013 12:32:51 -0600 Subject: makechrootpkg: handle makepkg_args better - handle it as an array - have the usage text print out the actual default args, instead of the defaults plus whatever has been parsed before `-h` - getopts turns any unknown flag into `-?`; don't add `*)` to makepkg_args - use in_array to see if it contains -R instead of looping ourselfs - pass it as a series of flags to /chrootbuild; preserving whitespace. --- makechrootpkg.in | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index 83aa5d3..49bdc1b 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 /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) @@ -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 @@ -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 -- cgit v1.2.3-70-g09d2 From 0844b79990d4f9dbe699c8a0bbd436776e8889b2 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 15 Jun 2013 12:33:49 -0600 Subject: makechrootpkg: ~/.makepkg.conf should take precedence over /etc/ --- makechrootpkg.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index 49bdc1b..3f73f1e 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -327,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 -- cgit v1.2.3-70-g09d2 From 06e3de14a9d82b456176c1966919e0bbd457da69 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 15 Jun 2013 13:30:23 -0600 Subject: mkarchroot: update usage() text --- mkarchroot.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkarchroot.in b/mkarchroot.in index 970bbb9..d7fb884 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 Location of a pacman config file' echo ' -M Location of a makepkg config file' -- cgit v1.2.3-70-g09d2 From 9862c71c160631bfc1a14ccbd42688c547ca9c0b Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 16 Aug 2013 02:18:29 -0400 Subject: support formatted messages to stat_busy, lock, and slock --- lib/common.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/common.sh b/lib/common.sh index c9deebc..5a9f6fe 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -50,7 +50,7 @@ error() { stat_busy() { local mesg=$1; shift - printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}...${ALL_OFF}" >&2 + printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}...${ALL_OFF}" "$@" >&2 } stat_done() { @@ -140,7 +140,7 @@ get_full_version() { lock() { local fd=$1 local file=$2 - local mesg=$3 + local mesg=("$@:3") # Only reopen the FD if it wasn't handed to us if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "$file")" ]]; then @@ -149,7 +149,7 @@ lock() { fi if ! flock -n $fd; then - stat_busy "$mesg" + stat_busy "${mesg[@]}" flock $fd stat_done fi @@ -161,7 +161,7 @@ lock() { slock() { local fd=$1 local file=$2 - local mesg=$3 + local mesg=("$@:3") # Only reopen the FD if it wasn't handed to us if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "$file")" ]]; then @@ -171,7 +171,7 @@ slock() { eval "exec $fd>"'"$file"' if ! flock -sn $fd; then - stat_busy "$mesg" + stat_busy "${mesg[@]}" flock -s $fd stat_done fi -- cgit v1.2.3-70-g09d2 From 3aca3b64077cfdb5132c08958c5e0e873aca89d2 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 16 Aug 2013 02:20:09 -0400 Subject: Avoid having code/variables in format strings. --- arch-nspawn.in | 2 +- archbuild.in | 8 ++++---- archrelease.in | 2 +- checkpkg.in | 4 ++-- crossrepomove.in | 8 ++++---- lddd.in | 4 ++-- makechrootpkg.in | 6 +++--- mkarchroot.in | 2 +- rebuildpkgs.in | 14 +++++++------- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index a05ca1c..66a0f37 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -32,7 +32,7 @@ while getopts 'hC:M:c:' arg; do M) makepkg_conf="$OPTARG" ;; c) cache_dir="$OPTARG" ;; h|?) usage ;; - *) error "invalid argument '$arg'"; usage ;; + *) error "invalid argument '%s'" "$arg"; usage ;; esac done shift $(($OPTIND - 1)) diff --git a/archbuild.in b/archbuild.in index 06b9d4b..ec70b59 100644 --- a/archbuild.in +++ b/archbuild.in @@ -45,13 +45,13 @@ if (( EUID )); then fi if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then - msg "Creating chroot for [${repo}] (${arch})..." + msg "Creating chroot for [%s] (%s)..." "${repo}" "${arch}" for copy in "${chroots}/${repo}-${arch}"/*; do [[ -d $copy ]] || continue - msg2 "Deleting chroot copy '$(basename "${copy}")'..." + msg2 "Deleting chroot copy '%s'..." "$(basename "${copy}")" - lock 9 "$copy.lock" "Locking chroot copy '$copy'" + lock 9 "$copy.lock" "Locking chroot copy '%s'" "$copy" if [[ "$(stat -f -c %T "${copy}")" == btrfs ]]; then { type -P btrfs && btrfs subvolume delete "${copy}"; } &>/dev/null @@ -76,5 +76,5 @@ else pacman -Syu --noconfirm || abort fi -msg "Building in chroot for [${repo}] (${arch})..." +msg "Building in chroot for [%s] (%s)..." "${repo}" "${arch}" exec makechrootpkg -r "${chroots}/${repo}-${arch}" "${makechrootpkg_args[@]}" diff --git a/archrelease.in b/archrelease.in index 6f52dbc..4ac55db 100644 --- a/archrelease.in +++ b/archrelease.in @@ -58,7 +58,7 @@ done known_files=("${known_files[@]/%/@}") for tag in "$@"; do - stat_busy "Copying ${trunk} to ${tag}" + stat_busy "Copying %s to %s" "${trunk}" "${tag}" if [[ -d repos/$tag ]]; then declare -a trash diff --git a/checkpkg.in b/checkpkg.in index 8e0f574..ac4226c 100644 --- a/checkpkg.in +++ b/checkpkg.in @@ -35,7 +35,7 @@ for _pkgname in "${pkgname[@]}"; do elif [[ -f "$PKGDEST/$pkgfile" ]]; then ln -s "$PKGDEST/$pkgfile" "$pkgfile" else - die "File \"$pkgfile\" doesn't exist" + die "File \"%s\" doesn't exist" "$pkgfile" fi pkgurl=$(pacman -Spdd --print-format '%l' --noconfirm "$_pkgname") @@ -80,4 +80,4 @@ for _pkgname in "${pkgname[@]}"; do fi done -msg "Files saved to $TEMPDIR" +msg "Files saved to %s" "$TEMPDIR" diff --git a/crossrepomove.in b/crossrepomove.in index 912504f..ac08c67 100644 --- a/crossrepomove.in +++ b/crossrepomove.in @@ -39,13 +39,13 @@ setup_workdir pushd $WORKDIR >/dev/null -msg "Downloading sources for ${pkgbase}" +msg "Downloading sources for %s" "${pkgbase}" svn -q checkout -N "${target_svn}" target_checkout mkdir -p "target_checkout/${pkgbase}/repos" svn -q export "${source_svn}/${pkgbase}/trunk" "target_checkout/${pkgbase}/trunk" || die . "target_checkout/${pkgbase}/trunk/PKGBUILD" -msg "Downloading packages for ${pkgbase}" +msg "Downloading packages for %s" "${pkgbase}" for _arch in ${arch[@]}; do if [[ "${_arch[*]}" == 'any' ]]; then repo_arch='x86_64' @@ -59,7 +59,7 @@ for _arch in ${arch[@]}; do done done -msg "Adding ${pkgbase} to ${target_repo}" +msg "Adding %s to %s" "${pkgbase}" "${target_repo}" svn -q add "target_checkout/${pkgbase}" svn -q propset svn:keywords 'Id' "target_checkout/${pkgbase}/trunk/PKGBUILD" svn -q commit -m"${scriptname}: Moving ${pkgbase} from ${source_repo} to ${target_repo}" target_checkout @@ -69,7 +69,7 @@ popd >/dev/null ssh "${server}" "${target_dbscripts}/db-update" || die -msg "Removing ${pkgbase} from ${source_repo}" +msg "Removing %s from %s" "${pkgbase}" "${source_repo}" for _arch in ${arch[@]}; do ssh "${server}" "${source_dbscripts}/db-remove ${source_repo} ${_arch} ${pkgbase}" done diff --git a/lddd.in b/lddd.in index 43aa8c1..f111d67 100644 --- a/lddd.in +++ b/lddd.in @@ -16,7 +16,7 @@ TEMPDIR=$(mktemp -d --tmpdir lddd-script.XXXX) msg 'Go out and drink some tea, this will take a while :) ...' # Check ELF binaries in the PATH and specified dir trees. for tree in $PATH $libdirs $extras; do - msg2 "DIR $tree" + msg2 "DIR %s" "$tree" # Get list of files in tree. files=$(find $tree -type f ! -name '*.a' ! -name '*.la' ! -name '*.py*' ! -name '*.txt' ! -name '*.h' ! -name '*.ttf' ! \ @@ -45,4 +45,4 @@ done # clean list sort -u $TEMPDIR/pacman.txt >> $TEMPDIR/possible-rebuilds.txt -msg "Files saved to $TEMPDIR" +msg "Files saved to %s" "$TEMPDIR" diff --git a/makechrootpkg.in b/makechrootpkg.in index ce003c8..ce99d95 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -124,14 +124,14 @@ load_vars() { create_chroot() { # Lock the chroot we want to use. We'll keep this lock until we exit. - lock 9 "$copydir.lock" "Locking chroot copy [$copy]" + lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$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 slock 8 "$chrootdir/root.lock" "Locking clean chroot" - stat_busy "Creating clean working copy [$copy]" + stat_busy "Creating clean working copy [%s]" "$copy" if [[ "$chroottype" == btrfs ]]; then if [[ -d $copydir ]]; then btrfs subvolume delete "$copydir" >/dev/null || @@ -151,7 +151,7 @@ create_chroot() { } clean_temporary() { - stat_busy "Removing temporary copy [$copy]" + stat_busy "Removing temporary copy [%s]" "$copy" if [[ "$chroottype" == btrfs ]]; then btrfs subvolume delete "$copydir" >/dev/null || die "Unable to delete subvolume %s" "$copydir" diff --git a/mkarchroot.in b/mkarchroot.in index ba92e15..07bf7c6 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -30,7 +30,7 @@ while getopts 'hC:M:c:' arg; do M) makepkg_conf="$OPTARG" ;; c) cache_dir="$OPTARG" ;; h|?) usage ;; - *) error "invalid argument '$arg'"; usage ;; + *) error "invalid argument '%s'" "$arg"; usage ;; esac done shift $(($OPTIND - 1)) diff --git a/rebuildpkgs.in b/rebuildpkgs.in index 2f71c40..65be0de 100644 --- a/rebuildpkgs.in +++ b/rebuildpkgs.in @@ -49,7 +49,7 @@ pkgs="$@" SVNPATH='svn+ssh://nymeria.archlinux.org/srv/repos/svn-packages/svn' -msg "Work will be done in $(pwd)/rebuilds" +msg "Work will be done in %s/rebuilds" "$(pwd)" REBUILD_ROOT="$(pwd)/rebuilds" mkdir -p "$REBUILD_ROOT" @@ -61,11 +61,11 @@ FAILED="" for pkg in $pkgs; do cd "$REBUILD_ROOT/svn-packages" - msg2 "Building '$pkg'" + msg2 "Building '%s'" "$pkg" /usr/bin/svn update "$pkg" if [[ ! -d "$pkg/trunk" ]]; then FAILED="$FAILED $pkg" - warning "$pkg does not exist in SVN" + warning "%s does not exist in SVN" "$pkg" continue fi cd "$pkg/trunk/" @@ -74,14 +74,14 @@ for pkg in $pkgs; do if ! sudo makechrootpkg -u -d -r "$chrootdir" -- --noconfirm; then FAILED="$FAILED $pkg" - error "$pkg Failed!" + error "%s Failed!" "$pkg" else pkgfile=$(pkg_from_pkgbuild) if [[ -e $pkgfile ]]; then - msg2 "$pkg Complete" + msg2 "%s Complete" "$pkg" else FAILED="$FAILED $pkg" - error "$pkg Failed, no package built!" + error "%s Failed, no package built!" "$pkg" fi fi done @@ -90,7 +90,7 @@ cd "$REBUILD_ROOT" if [[ -n $FAILED ]]; then msg 'Packages failed:' for pkg in $FAILED; do - msg2 "$pkg" + msg2 "%s" "$pkg" done fi -- cgit v1.2.3-70-g09d2 From 6fbdc4eb481302541cf8fa282fb3453e4c5d0d16 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 11 Sep 2013 13:58:11 -0400 Subject: arch-nspawn: set machine_name in a safer/different way, don't hide errors --- arch-nspawn.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index 66a0f37..ec9b2d3 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -98,10 +98,10 @@ copy_hostconf eval $(grep '^CARCH=' "$working_dir/etc/makepkg.conf") -machine_name="${working_dir//\//-}" -machine_name="${machine_name#-}" +machine_name="${working_dir##*/}" +machine_name="${machine_name//\./-}" -exec ${CARCH:+setarch "$CARCH"} systemd-nspawn 2>/dev/null \ +exec ${CARCH:+setarch "$CARCH"} systemd-nspawn \ -D "$working_dir" \ --machine "$machine_name" \ "${mount_args[@]}" \ -- cgit v1.2.3-70-g09d2 From 46e8d5b656945179d7dc79c6d5c93034f1495367 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 23 Sep 2013 13:08:30 -0400 Subject: checkpkg: I missed a case of string interpolation --- checkpkg.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checkpkg.in b/checkpkg.in index ac4226c..2cceafa 100644 --- a/checkpkg.in +++ b/checkpkg.in @@ -76,7 +76,7 @@ for _pkgname in "${pkgname[@]}"; do done cd .. else - msg "No soname differences for $_pkgname." + msg "No soname differences for %s." "$_pkgname" fi done -- cgit v1.2.3-70-g09d2 From 6a87c26b84e5cab7f4a8ead8abd62e58b7ec7f6c Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 26 Sep 2013 22:57:07 -0400 Subject: arch-nspawn: limit the machine_name length to ${HOST_NAME_MAX:-64} chars. The criteria for a valid name are: - is made of of alphanumerics, "_", ".", and "-" - is not emtpy - cannot end with "." - cannot contain ".." - the maximum length is HOST_NAME_MAX, as defined in The existing code takes care of all but the last of these. So, added code after the existing code to check the length of the string, and grab the longest possible substring from the end. I hard-coded our interpretation of HOST_NAME_MAX as 64--on Linux that has been the value since version 1.0 of the kernel... I don't think it will be changing any time soon, and since systemd is Linux-only, we don't have to worry about other kernels. But, just in case, I included a commented out version that uses cpp to get the value. --- arch-nspawn.in | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch-nspawn.in b/arch-nspawn.in index bde77b6..7dcd8ca 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -96,6 +96,12 @@ eval $(grep '^CARCH=' "$working_dir/etc/makepkg.conf") machine_name="${working_dir//[![:alnum:]_-]/-}" machine_name="${machine_name#-}" +#HOST_NAME_MAX="$(printf '%s\n' '#include ' 'HOST_NAME_MAX'|cpp -|sed -n '$p')" +HOST_NAME_MAX=64 +if [[ ${#machine_name} -gt "$HOST_NAME_MAX" ]]; then + machine_name="${machine_name:(-${HOST_NAME_MAX})}" + machine_name="${machine_name#-}" +fi exec ${CARCH:+setarch "$CARCH"} systemd-nspawn \ -D "$working_dir" \ -- cgit v1.2.3-70-g09d2 From 345358c4deb71b7316b99fb025d39d5644249e17 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 9 Oct 2013 11:16:09 -0400 Subject: This is embarrassing, I messed up the braces on $@ for lock/slock --- lib/common.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/common.sh b/lib/common.sh index 5a9f6fe..1baab9c 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -140,7 +140,7 @@ get_full_version() { lock() { local fd=$1 local file=$2 - local mesg=("$@:3") + local mesg=("${@:3}") # Only reopen the FD if it wasn't handed to us if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "$file")" ]]; then @@ -161,7 +161,7 @@ lock() { slock() { local fd=$1 local file=$2 - local mesg=("$@:3") + local mesg=("${@:3}") # Only reopen the FD if it wasn't handed to us if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "$file")" ]]; then -- cgit v1.2.3-70-g09d2 From 07748c56674bc40e9ef14dc1ebb15e81c3a7c2a7 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 26 Oct 2013 12:58:08 -0400 Subject: arch-nspawn: fix grammar in error message: s/a Arch/an Arch/ --- arch-nspawn.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index 7dcd8ca..94002f1 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -84,7 +84,7 @@ umask 0022 # Sanity check if [[ ! -f "$working_dir/.arch-chroot" ]]; then - die "'%s' does not appear to be a Arch chroot." "$working_dir" + die "'%s' does not appear to be an Arch chroot." "$working_dir" elif [[ $(cat "$working_dir/.arch-chroot") != $CHROOT_VERSION ]]; then die "chroot '%s' is not at version %s. Please rebuild." "$working_dir" "$CHROOT_VERSION" fi -- cgit v1.2.3-70-g09d2 From 534d2015b45e013b37e1edbb997bd4df27d7b8fd Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 5 Jan 2014 18:45:26 -0500 Subject: makechrootpkg: fix the btrfs check in both places Upstream only fiex it in one place. --- makechrootpkg.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index 052ab71..71fd5d9 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -164,7 +164,7 @@ create_chroot() { clean_temporary() { stat_busy "Removing temporary copy [%s]" "$copy" - if [[ "$chroottype" == btrfs ]]; then + if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then btrfs subvolume delete "$copydir" >/dev/null || die "Unable to delete subvolume %s" "$copydir" else -- cgit v1.2.3-70-g09d2 From 04995cbe1c4e7494b65a63f223e5e2ddfd789e33 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 10 May 2014 18:08:49 -0400 Subject: lib/common.sh: Use `[[ a -ef b ]]` instead of double calls to `readlink -f` --- lib/common.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/common.sh b/lib/common.sh index 455e841..7f83bdd 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -145,7 +145,7 @@ lock() { local mesg=("${@:3}") # Only reopen the FD if it wasn't handed to us - if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "$file")" ]]; then + if ! [[ "/dev/fd/$fd" -ef "$file" ]]; then mkdir -p "${file%/*}" eval "exec $fd>"'"$file"' fi @@ -166,7 +166,7 @@ slock() { local mesg=("${@:3}") # Only reopen the FD if it wasn't handed to us - if [[ "$(readlink -f /dev/fd/$fd)" != "$(readlink -f "$file")" ]]; then + if ! [[ "/dev/fd/$fd" -ef "$file" ]]; then mkdir -p "${file%/*}" eval "exec $fd>"'"$file"' fi -- cgit v1.2.3-70-g09d2 From ead868c7fa430c647d52d746e515aecd0c3c0cae Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 10 May 2014 18:09:22 -0400 Subject: arch-nspawn: go back to hiding stderr --- arch-nspawn.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index 0bdd921..ca7edbe 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -103,7 +103,7 @@ if [[ ${#machine_name} -gt "$HOST_NAME_MAX" ]]; then machine_name="${machine_name#-}" fi -exec ${CARCH:+setarch "$CARCH"} systemd-nspawn \ +exec ${CARCH:+setarch "$CARCH"} systemd-nspawn 2>/dev/null \ -D "$working_dir" \ --machine "$machine_name" \ "${mount_args[@]}" \ -- cgit v1.2.3-70-g09d2 From 4fcf9f8582cc78699b64884b872fe2578464c660 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 10 May 2014 19:26:22 -0400 Subject: Tidy up. --- lib/common.sh | 5 ++--- makechrootpkg.in | 8 ++++---- rebuildpkgs.in | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/common.sh b/lib/common.sh index 7f83bdd..44d12c3 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -137,7 +137,7 @@ get_full_version() { } ## -# usage : lock( $fd, $file, $message ) +# usage : lock( $fd, $file, $message, [ $message_arguments... ] ) ## lock() { local fd=$1 @@ -158,7 +158,7 @@ lock() { } ## -# usage : slock( $fd, $file, $message ) +# usage : slock( $fd, $file, $message, [ $message_arguments... ] ) ## slock() { local fd=$1 @@ -171,7 +171,6 @@ slock() { eval "exec $fd>"'"$file"' fi - eval "exec $fd>"'"$file"' if ! flock -sn $fd; then stat_busy "${mesg[@]}" flock -s $fd diff --git a/makechrootpkg.in b/makechrootpkg.in index e2dd0b7..f646117 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -12,8 +12,8 @@ m4_include(lib/common.sh) shopt -s nullglob -_makepkg_args=(-s --noconfirm -L --holdver) -makepkg_args=("${_makepkg_args[@]}") +default_makepkg_args=(-s --noconfirm -L --holdver) +makepkg_args=("${default_makepkg_args[@]}") repack=false update_first=false clean_first=false @@ -47,7 +47,7 @@ usage() { echo 'command:' echo ' mkarchroot /root base-devel' echo '' - echo "Default makepkg args: ${_makepkg_args[*]}" + echo "Default makepkg args: ${default_makepkg_args[*]}" echo '' echo 'Flags:' echo '-h This help' @@ -355,8 +355,8 @@ move_products() { umask 0022 -load_vars /etc/makepkg.conf load_vars "$USER_HOME/.makepkg.conf" +load_vars /etc/makepkg.conf # Use PKGBUILD directory if these don't exist [[ -d $PKGDEST ]] || PKGDEST=$PWD diff --git a/rebuildpkgs.in b/rebuildpkgs.in index 65be0de..1a02954 100644 --- a/rebuildpkgs.in +++ b/rebuildpkgs.in @@ -49,7 +49,7 @@ pkgs="$@" SVNPATH='svn+ssh://nymeria.archlinux.org/srv/repos/svn-packages/svn' -msg "Work will be done in %s/rebuilds" "$(pwd)" +msg "Work will be done in %s" "$(pwd)/rebuilds" REBUILD_ROOT="$(pwd)/rebuilds" mkdir -p "$REBUILD_ROOT" -- cgit v1.2.3-70-g09d2 From 66f612510a5df14f4a017809e1eec671aee8cc26 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 11 May 2014 00:55:00 -0400 Subject: Add changes discussed with Dave Reisner on the arch-projects list. - Simplify the commented out call to find HOST_NAME_MAX - Use `systemd-nspawn -q` instead of 2>/dev/null - Use Bash 4.1's new {var}>&- syntax in lock_close() --- arch-nspawn.in | 4 ++-- lib/common.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index ca7edbe..e8b68cf 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -96,14 +96,14 @@ eval $(grep '^CARCH=' "$working_dir/etc/makepkg.conf") machine_name="${working_dir//[![:alnum:]_-]/-}" machine_name="${machine_name#-}" -#HOST_NAME_MAX="$(printf '%s\n' '#include ' 'HOST_NAME_MAX'|cpp -|sed -n '$p')" +#HOST_NAME_MAX="$(cpp -include limits.h <</dev/null \ +exec ${CARCH:+setarch "$CARCH"} systemd-nspawn -q \ -D "$working_dir" \ --machine "$machine_name" \ "${mount_args[@]}" \ diff --git a/lib/common.sh b/lib/common.sh index 44d12c3..6305528 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -183,7 +183,7 @@ slock() { ## lock_close() { local fd=$1 - eval "exec $fd>&-" + exec {fd}>&- } ## -- cgit v1.2.3-70-g09d2 From d732aae2ca57430f3dd95c0ed4dcc05df4014f91 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 15 May 2014 22:41:20 -0400 Subject: arch-nspawn: use getconf to find HOST_NAME_MAX at runtime. This is at the suggestion of Roman Neuhauser, who emailed Dave Reisner and me. --- arch-nspawn.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index e8b68cf..6c9a102 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -96,8 +96,7 @@ eval $(grep '^CARCH=' "$working_dir/etc/makepkg.conf") machine_name="${working_dir//[![:alnum:]_-]/-}" machine_name="${machine_name#-}" -#HOST_NAME_MAX="$(cpp -include limits.h << Date: Sat, 5 Jul 2014 02:00:00 -0400 Subject: commitpkg: Use printf-formatters Also, the quoting on one line confused xgettext. --- commitpkg.in | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/commitpkg.in b/commitpkg.in index 1095006..65876a3 100644 --- a/commitpkg.in +++ b/commitpkg.in @@ -47,7 +47,7 @@ done for i in 'changelog' 'install'; do while read -r file; do # evaluate any bash variables used - eval file=\"$(sed 's/^\(['\''"]\)\(.*\)\1$/\2/' <<< "$file")\" + eval file=\"$(sed "s/^\(['\"]\)\(.*\)\1\$/\2/" <<< "$file")\" needsversioning+=("$file") done < <(sed -n "s/^[[:space:]]*$i=//p" PKGBUILD) done @@ -135,7 +135,7 @@ for _arch in ${arch[@]}; do fullver=$(get_full_version $_pkgname) if ! pkgfile=$(find_cached_package "$_pkgname" "$fullver" "${_arch}"); then - warning "Skipping $_pkgname-$fullver-$_arch: failed to locate package file" + warning "Skipping %s: failed to locate package file" "$_pkgname-$fullver-$_arch" skip_arches+=($_arch) continue 2 fi @@ -143,7 +143,7 @@ for _arch in ${arch[@]}; do sigfile="${pkgfile}.sig" if [[ ! -f $sigfile ]]; then - msg "Signing package ${pkgfile}..." + msg "Signing package %s..." "${pkgfile}" if [[ -n $GPGKEY ]]; then SIGNWITHKEY="-u ${GPGKEY}" fi @@ -183,7 +183,7 @@ fi if [[ "${arch[*]}" == 'any' ]]; then if [[ -d ../repos/$repo-i686 && -d ../repos/$repo-x86_64 ]]; then pushd ../repos/ >/dev/null - stat_busy "Removing $repo-i686 and $repo-x86_64" + stat_busy "Removing %s and %s" "$repo-i686" "$repo-x86_64" svn rm -q $repo-i686 svn rm -q $repo-x86_64 svn commit -q -m "Removed $repo-i686 and $repo-x86_64 for $pkgname" @@ -193,7 +193,7 @@ if [[ "${arch[*]}" == 'any' ]]; then else if [[ -d ../repos/$repo-any ]]; then pushd ../repos/ >/dev/null - stat_busy "Removing $repo-any" + stat_busy "Removing %s" "$repo-any" svn rm -q $repo-any svn commit -q -m "Removed $repo-any for $pkgname" stat_done -- cgit v1.2.3-70-g09d2 From 3286d45fb790c9b7bc1c9669ca0338e4ab60da11 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 6 Jun 2015 14:04:21 -0600 Subject: makechrootpkg: remove extra arguments to /chrootbuild They have been part of the file itself via %q for a while. --- makechrootpkg.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index 78e3894..1d7ba5e 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -393,7 +393,7 @@ if arch-nspawn "$copydir" \ --bind-ro="$PWD:/startdir_host" \ --bind-ro="$SRCDEST:/srcdest_host" \ "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ - /chrootbuild "${makepkg_args[@]}" + /chrootbuild then move_products else -- cgit v1.2.3-70-g09d2 From c271ab745f80167f452ee6afa1ff430c2f1523b0 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 6 Jun 2015 14:35:11 -0600 Subject: Reverse the previous commit--passing in makepkg_args as args is better. --- makechrootpkg.in | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index 1d7ba5e..79f54ab 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -216,9 +216,7 @@ EOF { printf '#!/bin/bash\n' declare -f _chrootbuild - printf '_chrootbuild' - printf ' %q' "${makepkg_args[@]}" - printf ' || exit\n' + printf '_chrootbuild "$@" || exit\n' if $run_namcap; then cat <<'EOF' @@ -393,7 +391,7 @@ if arch-nspawn "$copydir" \ --bind-ro="$PWD:/startdir_host" \ --bind-ro="$SRCDEST:/srcdest_host" \ "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ - /chrootbuild + /chrootbuild "${makepkg_args[@]}" then move_products else -- cgit v1.2.3-70-g09d2 From ce7a5ea686c5acdfe6b80782b4b2059c121ed902 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 9 May 2016 18:37:02 -0400 Subject: arch-nspawn: two spaces after a period --- arch-nspawn.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index 10f79f6..4a92f09 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -16,7 +16,7 @@ working_dir='' usage() { echo "Usage: ${0##*/} [options] working-dir [systemd-nspawn arguments]" - echo "A wrapper around systemd-nspawn. Provides support for pacman." + echo "A wrapper around systemd-nspawn. Provides support for pacman." echo echo ' options:' echo ' -C Location of a pacman config file' @@ -88,7 +88,7 @@ umask 0022 if [[ ! -f "$working_dir/.arch-chroot" ]]; then die "'%s' does not appear to be an Arch chroot." "$working_dir" elif [[ $(cat "$working_dir/.arch-chroot") != $CHROOT_VERSION ]]; then - die "chroot '%s' is not at version %s. Please rebuild." "$working_dir" "$CHROOT_VERSION" + die "chroot '%s' is not at version %s. Please rebuild." "$working_dir" "$CHROOT_VERSION" fi build_mount_args -- cgit v1.2.3-70-g09d2 From c3819bb4224622c6d10ab7a3511472f314e026ba Mon Sep 17 00:00:00 2001 From: "coadde [Márcio Alexandre Silva Delgado]" Date: Tue, 10 May 2016 07:16:47 -0300 Subject: remove setarch for non-i686 to support qemu-static --- arch-nspawn.in | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index 4a92f09..dbccdda 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -96,8 +96,17 @@ copy_hostconf eval $(grep '^CARCH=' "$working_dir/etc/makepkg.conf") -exec ${CARCH:+setarch "$CARCH"} systemd-nspawn -q \ - -D "$working_dir" \ - --register=no \ - "${mount_args[@]}" \ - "$@" + +if [[ $CARCH = i686 ]]; then + exec ${CARCH:+setarch "$CARCH"} systemd-nspawn -q \ + -D "$working_dir" \ + --register=no \ + "${mount_args[@]}" \ + "$@" +else + exec systemd-nspawn -q \ + -D "$working_dir" \ + --register=no \ + "${mount_args[@]}" \ + "$@" +fi -- cgit v1.2.3-70-g09d2 From 4153cd46e23426ee725736dd4a2806d0df596ced Mon Sep 17 00:00:00 2001 From: André Fabian Silva Delgado Date: Wed, 11 May 2016 01:40:52 -0300 Subject: Revert "remove setarch for non-i686 to support qemu-static" since Libretools arch-nspawn has the `-s` flag to turn off setarch This reverts commit c3819bb4224622c6d10ab7a3511472f314e026ba. --- arch-nspawn.in | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index dbccdda..4a92f09 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -96,17 +96,8 @@ copy_hostconf eval $(grep '^CARCH=' "$working_dir/etc/makepkg.conf") - -if [[ $CARCH = i686 ]]; then - exec ${CARCH:+setarch "$CARCH"} systemd-nspawn -q \ - -D "$working_dir" \ - --register=no \ - "${mount_args[@]}" \ - "$@" -else - exec systemd-nspawn -q \ - -D "$working_dir" \ - --register=no \ - "${mount_args[@]}" \ - "$@" -fi +exec ${CARCH:+setarch "$CARCH"} systemd-nspawn -q \ + -D "$working_dir" \ + --register=no \ + "${mount_args[@]}" \ + "$@" -- cgit v1.2.3-70-g09d2 From ec8779248b4d91fb189b658097fa162e6f753991 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 10 May 2016 13:44:46 -0400 Subject: arch-nspawn: add a table of CARCH/setarch overrides (just armv7h->armv7l for now) --- arch-nspawn.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch-nspawn.in b/arch-nspawn.in index 4a92f09..efdd97e 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -95,6 +95,9 @@ build_mount_args copy_hostconf eval $(grep '^CARCH=' "$working_dir/etc/makepkg.conf") +case "$CARCH" in + armv7h) CARCH=armv7l;; +esac exec ${CARCH:+setarch "$CARCH"} systemd-nspawn -q \ -D "$working_dir" \ -- cgit v1.2.3-70-g09d2 From ca57df0221baa2eddb01d53d45e3f9f5f6420d3b Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 29 Jan 2017 22:59:49 -0500 Subject: makechrootpkg: Be recursive when deleting subvolumes. This fixes https://labs.parabola.nu/issues/1201 --- makechrootpkg.in | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index a77d14a..127514d 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -80,6 +80,61 @@ load_vars() { return 0 } +# Usage: btrfs_subvolume_id $SUBVOLUME +btrfs_subvolume_id() ( + set -o pipefail + LC_ALL=C btrfs subvolume show "$1" | sed -n 's/^\tSubvolume ID:\s*//p' +) + +# Usage: btrfs_subvolume_list_all $FILEPATH +# +# Given $FILEPATH somewhere on a mounted btrfs filesystem, print the +# ID and full path of every subvolume on the filesystem, one per line +# in the format "$ID $PATH". +btrfs_subvolume_list_all() ( + set -o pipefail + local mountpoint + mountpoint="$(df --output=target "$1" | sed 1d)" || return $? + LC_ALL=C btrfs subvolume list -a "$mountpoint" | sed -r 's|^ID ([0-9]+) .* path (/)?(\S*).*|\1 \3|' +) + +# Usage: btrfs_subvolume_list $SUBVOLUME +# +# Assuming that $SUBVOLUME is a btrfs subvolume, list all child +# subvolumes; from most deeply nested to most shallowly nested. +# +# This is intended to be a sane version of `btrfs subvolume list`. +btrfs_subvolume_list() { + local subvolume=$1 + + local id all path subpath + id="$(btrfs_subvolume_id "$subvolume")" || return $? + all="$(btrfs_subvolume_list_all "$subvolume")" || return $? + path="$(sed -n "s/^$id //p" <<<"$all")" + while read -r id subpath; do + if [[ "$subpath" = "$path"/* ]]; then + printf '%s\n' "${subpath#"${path}/"}" + fi + done <<<"$all" | LC_ALL=C sort --reverse +} + +# Usage: btrfs_subvolume_delete $SUBVOLUME +# +# Assuming that $SUBVOLUME is a btrfs subvolume, delete it and all +# subvolumes below it. +# +# This is intended to be a recursive version of +# `btrfs subvolume delete`. +btrfs_subvolume_delete() { + local dir="$1" + local subvolumes subvolume + subvolumes=($(btrfs_subvolume_list "$dir")) || return $? + for subvolume in "${subvolumes[@]}"; do + btrfs subvolume delete "$dir/$subvolume" || return $? + done + btrfs subvolume delete "$dir" +} + create_chroot() { # Lock the chroot we want to use. We'll keep this lock until we exit. lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy" @@ -92,7 +147,7 @@ create_chroot() { stat_busy "Creating clean working copy [%s]" "$copy" if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then if [[ -d $copydir ]]; then - btrfs subvolume delete "$copydir" >/dev/null || + btrfs_subvolume_delete "$copydir" >/dev/null || die "Unable to delete subvolume %s" "$copydir" fi btrfs subvolume snapshot "$chrootdir/root" "$copydir" >/dev/null || @@ -114,7 +169,7 @@ create_chroot() { clean_temporary() { stat_busy "Removing temporary copy [%s]" "$copy" if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then - btrfs subvolume delete "$copydir" >/dev/null || + btrfs_subvolume_delete "$copydir" >/dev/null || die "Unable to delete subvolume %s" "$copydir" else # avoid change of filesystem in case of an umount failure -- cgit v1.2.3-70-g09d2 From 070092d2492c6d21f42d2bb8d47bfd5e4a4ecfa5 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 14:03:56 -0500 Subject: Apply patches from libretools. --- arch-nspawn.in | 17 +++++- checkpkg.in | 27 +++++++++- find-libdeps.in | 28 ++++++++-- finddeps.in | 18 ++++--- lddd.in | 18 ++++++- lib/common.sh | 55 +++++++++++++------ makechrootpkg.in | 162 ++++++++++++++++++++++++++++++++++++++++++++++--------- mkarchroot.in | 21 +++++++- 8 files changed, 289 insertions(+), 57 deletions(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index fd4c583..85af8c5 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -16,6 +16,8 @@ CHROOT_VERSION='v3' working_dir='' +files=() + usage() { echo "Usage: ${0##*/} [options] working-dir [systemd-nspawn arguments]" echo "A wrapper around systemd-nspawn. Provides support for pacman." @@ -24,17 +26,21 @@ usage() { echo ' -C Location of a pacman config file' echo ' -M Location of a makepkg config file' echo ' -c Set pacman cache' + echo ' -f Copy file from the host to the chroot' + echo ' -s Do not run setarch' echo ' -h This message' exit 1 } orig_argv=("$@") -while getopts 'hC:M:c:' arg; do +while getopts 'hC:M:c:f:s' arg; do case "$arg" in C) pac_conf="$OPTARG" ;; M) makepkg_conf="$OPTARG" ;; c) cache_dir="$OPTARG" ;; + f) files+=("$OPTARG") ;; + s) nosetarch=1 ;; h|?) usage ;; *) error "invalid argument '%s'" "$arg"; usage ;; esac @@ -80,6 +86,12 @@ copy_hostconf () { [[ -n $pac_conf ]] && cp $pac_conf "$working_dir/etc/pacman.conf" [[ -n $makepkg_conf ]] && cp $makepkg_conf "$working_dir/etc/makepkg.conf" + local file + for file in "${files[@]}"; do + mkdir -p "$(dirname "$working_dir$file")" + cp -T "$file" "$working_dir$file" + done + sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${cache_dirs[@]})|g" -i "$working_dir/etc/pacman.conf" } # }}} @@ -94,6 +106,7 @@ elif [[ $(cat "$working_dir/.arch-chroot") != $CHROOT_VERSION ]]; then fi build_mount_args +cache_dirs+=('/repo/') copy_hostconf eval $(grep '^CARCH=' "$working_dir/etc/makepkg.conf") @@ -101,6 +114,8 @@ case "$CARCH" in armv7h) CARCH=armv7l;; esac +[[ -z $nosetarch ]] || unset CARCH + exec ${CARCH:+setarch "$CARCH"} systemd-nspawn -q \ -D "$working_dir" \ --register=no \ diff --git a/checkpkg.in b/checkpkg.in index fbd30d3..6904e32 100644 --- a/checkpkg.in +++ b/checkpkg.in @@ -3,7 +3,28 @@ shopt -s extglob -m4_include(lib/common.sh) +. "$(librelib messages)" + +usage() { + print 'Usage: %s [-h]' "${0##*/}" + print 'Compare a locally built a package with the one in the repositories.' + echo + prose 'This should be run from a directory containing a + PKGBUILD. It searches for a locally built package + corresponding to the PKGBUILD, and downloads the last + version of that package from the pacman repositories. + It then compares the list of .so files provided by each + version of the package. It does this for each part of + a split package.' +} + +if [[ $1 = '-h' ]]; then + usage + exit 0 +elif [[ $# -gt 0 ]]; then + usage >&2 + exit 1 +fi # Source makepkg.conf; fail if it is not found if [[ -r '/etc/makepkg.conf' ]]; then @@ -18,7 +39,9 @@ if [[ -r ~/.makepkg.conf ]]; then fi if [[ ! -f PKGBUILD ]]; then - die 'This must be run in the directory of a built package.' + error 'This must be run in the directory of a built package.' + usage >&2 + exit 1 fi . ./PKGBUILD diff --git a/find-libdeps.in b/find-libdeps.in index 5c350a9..794a2cd 100644 --- a/find-libdeps.in +++ b/find-libdeps.in @@ -1,7 +1,7 @@ #!/bin/bash # License: Unspecified -m4_include(lib/common.sh) +. "$(librelib messages)" set -e shopt -s extglob @@ -20,12 +20,32 @@ case $script_mode in *) die "Unknown mode %s" "$script_mode" ;; esac +usage() { + print "Usage: find-lib(deps|provides) [options] " + print "Find library dependencies or provides of a package." + echo + prose 'Prints a list of library dependencies in the format:' + echo + print ' =-' + echo + prose 'Where is the shared library version, or + repeated if there is no version attached; and + is the architecture of the library (either `32` + or `64`, based on the ELF Class).' + echo + print "Options:" + flag "--ignore-internal" "Ignore internal libraries; libraries + without a version attached" + flag "-h" "Show this message" +} if [[ -z $1 ]]; then - echo "${0##*/} [options] " - echo "Options:" - echo " --ignore-internal ignore internal libraries" + usage >&2 exit 1 fi +if [[ $1 = '-h' ]]; then + usage + exit 0 +fi if [[ -d $1 ]]; then pushd $1 >/dev/null diff --git a/finddeps.in b/finddeps.in index 89ccc41..cc1ffab 100644 --- a/finddeps.in +++ b/finddeps.in @@ -4,18 +4,24 @@ # # License: Unspecified -m4_include(lib/common.sh) +. "$(librelib messages)" match=$1 +usage() { + print 'Usage: %s ' "${0##*/}" + print 'Find packages that depend on a given depname.' + echo + prose 'Run this script from the top-level directory of your ABS tree.' +} if [[ -z $match ]]; then - echo 'Usage: finddeps ' - echo '' - echo 'Find packages that depend on a given depname.' - echo 'Run this script from the top-level directory of your ABS tree.' - echo '' + usage >&2 exit 1 fi +if [[ $match = '-h' ]]; then + usage + exit 0 +fi find . -type d | while read d; do if [[ -f "$d/PKGBUILD" ]]; then diff --git a/lddd.in b/lddd.in index f01ebf9..09e0d07 100644 --- a/lddd.in +++ b/lddd.in @@ -4,7 +4,23 @@ # # License: Unspecified -m4_include(lib/common.sh) +. "$(librelib messages)" + +usage() { + print "Usage: %s [-h]" "${0##*/}" + print "Find broken library links on your machine." + echo + prose 'Scans $PATH and library directories for ELF files with + references to missing shared libraries.' +} + +if [[ $1 = '-h' ]]; then + usage + exit 0 +elif [[ $# -gt 0 ]]; then + usage >&2 + exit 1 +fi ifs=$IFS IFS="${IFS}:" diff --git a/lib/common.sh b/lib/common.sh index 62f4e72..bb46f6c 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -1,7 +1,28 @@ +#!/hint/bash +# This may be included with or without `set -euE` + +# This file is included by libremessages. +# You should probably use libremessages instead of this. + # License: Unspecified -# Avoid any encoding problems -export LANG=C +shopt -s extglob + +if [[ -z ${_INCLUDE_COMMON_SH:-} ]]; then +_INCLUDE_COMMON_SH=true + +[[ -n ${TEXTDOMAIN:-} ]] || export TEXTDOMAIN='libretools' +[[ -n ${TEXTDOMAINDIR:-} ]] || export TEXTDOMAINDIR='/usr/share/locale' + +if type gettext &>/dev/null; then + _() { gettext "$@"; } +else + _() { echo "$@"; } +fi + +_l() { + TEXTDOMAIN='librelib' TEXTDOMAINDIR='/usr/share/locale' "$@" +} shopt -s extglob @@ -28,37 +49,37 @@ fi readonly ALL_OFF BOLD BLUE GREEN RED YELLOW plain() { - local mesg=$1; shift + local mesg="$(_ "$1")"; shift printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } msg() { - local mesg=$1; shift + local mesg="$(_ "$1")"; shift printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } msg2() { - local mesg=$1; shift + local mesg="$(_ "$1")"; shift printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } warning() { - local mesg=$1; shift - printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 + local mesg="$(_ "$1")"; shift + printf "${YELLOW}==> $(_l _ "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } error() { - local mesg=$1; shift - printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 + local mesg="$(_ "$1")"; shift + printf "${RED}==> $(_l _ "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } stat_busy() { - local mesg=$1; shift + local mesg="$(_ "$1")"; shift printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}...${ALL_OFF}" "$@" >&2 } stat_done() { - printf "${BOLD}$(gettext "done")${ALL_OFF}\n" >&2 + printf "${BOLD}$(_l _ "done")${ALL_OFF}\n" >&2 } _setup_workdir=false @@ -77,7 +98,7 @@ cleanup() { } abort() { - error 'Aborting...' + _l error 'Aborting...' cleanup 255 } @@ -142,7 +163,8 @@ get_full_version() { ## # usage : lock( $fd, $file, $message, [ $message_arguments... ] ) ## -lock() { +lock() +{ local fd=$1 local file=$2 local mesg=("${@:3}") @@ -163,7 +185,8 @@ lock() { ## # usage : slock( $fd, $file, $message, [ $message_arguments... ] ) ## -slock() { +slock() +{ local fd=$1 local file=$2 local mesg=("${@:3}") @@ -255,7 +278,7 @@ find_cached_package() { return 0 ;; *) - error 'Multiple packages found:' + _l error 'Multiple packages found:' printf '\t%s\n' "${results[@]}" >&2 return 1 esac @@ -272,3 +295,5 @@ check_root() { exec su root -c "$(printf ' %q' "$@")" fi } + +fi diff --git a/makechrootpkg.in b/makechrootpkg.in index fe6cdbe..35a1286 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -14,6 +14,7 @@ m4_include(lib/common.sh) shopt -s nullglob +init_variables() { default_makepkg_args=(-s --noconfirm -L --holdver) makepkg_args=("${default_makepkg_args[@]}") repack=false @@ -31,9 +32,10 @@ bindmounts_ro=() bindmounts_rw=() copy=$USER -[[ -n $SUDO_USER ]] && copy=$SUDO_USER +[[ -n ${SUDO_USER:-} ]] && copy=$SUDO_USER [[ -z "$copy" || $copy = root ]] && copy=copy src_owner=${SUDO_USER:-$USER} +} usage() { echo "Usage: ${0##*/} [options] -r [--] [makepkg args]" @@ -70,13 +72,21 @@ usage() { } # {{{ functions +# Usage: load_vars $makepkg_conf +# Globals: +# - SRCDEST +# - SRCPKGDEST +# - PKGDEST +# - LOGDEST +# - MAKEFLAGS +# - PACKAGER load_vars() { local makepkg_conf="$1" var [[ -f $makepkg_conf ]] || return 1 for var in {SRC,SRCPKG,PKG,LOG}DEST MAKEFLAGS PACKAGER; do - [[ -z ${!var} ]] && eval $(grep "^${var}=" "$makepkg_conf") + [[ -z ${!var:-} ]] && eval $(grep "^${var}=" "$makepkg_conf") done return 0 @@ -137,16 +147,31 @@ btrfs_subvolume_delete() { btrfs subvolume delete "$dir" } -create_chroot() { - # Lock the chroot we want to use. We'll keep this lock until we exit. - lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy" +# Usage: sync_chroot $CHROOTDIR/$CHROOT <$CHROOTCOPY|$copydir> +sync_chroot() { + local chrootdir=$1 + local copy=$2 + local copydir='' + if [[ ${copy:0:1} = / ]]; then + copydir=$copy + else + copydir="$chrootdir/$copy" + fi + + if [[ "$chrootdir/root" -ef "$copydir" ]]; then + error 'Cannot sync copy with itself: %s' "$copydir" + return 1 + fi + + # Detect chrootdir filesystem type + local chroottype=$(stat -f -c %T "$chrootdir") - 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 - slock 8 "$chrootdir/root.lock" "Locking clean chroot" + slock 8 "$chrootdir/root.lock" \ + "Locking clean chroot [%s]" "$chrootdir/root" - stat_busy "Creating clean working copy [%s]" "$copy" + stat_busy "Synchronizing chroot copy [%s] -> [%s]" "$chrootdir/root" "$copydir" if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then if [[ -d $copydir ]]; then btrfs_subvolume_delete "$copydir" >/dev/null || @@ -162,14 +187,18 @@ create_chroot() { # Drop the read lock again lock_close 8 - fi # Update mtime touch "$copydir" } -clean_temporary() { - stat_busy "Removing temporary copy [%s]" "$copy" +# Usage: delete_chroot $copydir +delete_chroot() { + local copydir=$1 + # Detect chrootdir filesystem type + local chroottype=$(stat -f -c %T "$copydir") + + stat_busy "Removing chroot copy [%s]" "$copydir" if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then btrfs_subvolume_delete "$copydir" >/dev/null || die "Unable to delete subvolume %s" "$copydir" @@ -184,9 +213,14 @@ clean_temporary() { stat_done } +# Usage: install_packages $copydir $pkgs... install_packages() { + local copydir=$1 + local install_pkgs=("${@:2}") + declare -i ret=0 local pkgname + local install_pkg for install_pkg in "${install_pkgs[@]}"; do pkgname="${install_pkg##*/}" cp "$install_pkg" "$copydir/$pkgname" @@ -199,11 +233,19 @@ install_packages() { rm "$copydir/$pkgname" done - # If there is no PKGBUILD we are done - [[ -f PKGBUILD ]] || exit $ret + return $ret } +# Usage: prepare_chroot $copydir $HOME $repack $run_namcap +# Globals: +# - MAKEFLAGS +# - PACKAGER prepare_chroot() { + local copydir=$1 + local USER_HOME=$2 + local repack=$3 + local run_namcap=$4 + $repack || rm -rf "$copydir/build" mkdir -p "$copydir/build" @@ -250,12 +292,12 @@ prepare_chroot() { printf 'builduser:x:%d:100:builduser:/build:/bin/bash\n' "$builduser_uid" >>"$copydir/etc/passwd" chown -R "$builduser_uid" "$copydir"/{build,pkgdest,srcpkgdest,logdest,srcdest,startdir} - if [[ -n $MAKEFLAGS ]]; then + if [[ -n ${MAKEFLAGS:-} ]]; then sed -i '/^MAKEFLAGS=/d' "$copydir/etc/makepkg.conf" echo "MAKEFLAGS='${MAKEFLAGS}'" >> "$copydir/etc/makepkg.conf" fi - if [[ -n $PACKAGER ]]; then + if [[ -n ${PACKAGER:-} ]]; then sed -i '/^PACKAGER=/d' "$copydir/etc/makepkg.conf" echo "PACKAGER='${PACKAGER}'" >> "$copydir/etc/makepkg.conf" fi @@ -268,8 +310,23 @@ EOF chmod 440 "$copydir/etc/sudoers.d/builduser-pacman" fi + if ! grep -q '^\[repo\]' "$copydir/etc/pacman.conf"; then + local line=$(grep -n '^\[' "$copydir/etc/pacman.conf" |grep -Fv ':[options]'|sed 's/:.*//;1q') + local ins='[repo] +SigLevel = Optional TrustAll +Server = file:///repo +' + sed -i "${line}i${ins//$'\n'/\\n}" "$copydir/etc/pacman.conf" + fi + # This is a little gross, but this way the script is recreated every time in the # working copy + { + printf '#!/bin/bash\n' + declare -f _chrootprepare + printf '_chrootprepare "$@"\n' + } > "$copydir/chrootprepare" + chmod +x "$copydir/chrootprepare" { printf '#!/bin/bash\n' declare -f _chrootbuild @@ -288,13 +345,19 @@ EOF chmod +x "$copydir/chrootbuild" } +# Usage: download_sources $copydir $src_owner +# Globals: +# - SRCDEST download_sources() { + local copydir=$1 + local src_owner=$2 + local builddir="$(mktemp -d)" chmod 1777 "$builddir" # Ensure sources are downloaded - if [[ -n $SUDO_USER ]]; then - sudo -u $SUDO_USER env SRCDEST="$SRCDEST" BUILDDIR="$builddir" \ + if [[ $USER != $src_owner ]]; then + sudo -u $src_owner env SRCDEST="$SRCDEST" BUILDDIR="$builddir" \ makepkg --config="$copydir/etc/makepkg.conf" --verifysource -o else ( export SRCDEST BUILDDIR="$builddir" @@ -304,10 +367,10 @@ download_sources() { (( $? != 0 )) && die "Could not download sources." # Clean up garbage from verifysource - rm -rf $builddir + rm -rf "$builddir" } -_chrootbuild() { +_chrootprepare() { # This function isn't run in makechrootpkg, # so no global variables @@ -316,6 +379,7 @@ _chrootbuild() { shopt -s nullglob # XXX: Workaround makepkg disliking read-only dirs + rm -rf -- /srcdest/* /startdir/* ln -sft /srcdest /srcdest_host/* ln -sft /startdir /startdir_host/* @@ -345,15 +409,42 @@ _chrootbuild() { exit 1 fi - sudo -u builduser makepkg "$@" + # Sync deps now, as networking may be disabled during _chrootbuild + cp /repo/repo.db /var/lib/pacman/sync/repo.db + sudo -u builduser makepkg "$@" --nobuild } +_chrootbuild() { + # This function isn't run in makechrootpkg, + # so no global variables + + . /etc/profile + export HOME=/build + shopt -s nullglob + + cd /startdir + + sudo -u builduser makepkg "$@" --noextract --noprepare +} + +# Usage: move_products $copydir $owner +# Globals: +# - PKGDEST +# - LOGDEST move_products() { + local copydir=$1 + local src_owner=$2 + + local pkgfile for pkgfile in "$copydir"/pkgdest/*; do chown "$src_owner" "$pkgfile" mv "$pkgfile" "$PKGDEST" + if [[ $PKGDEST != $PWD ]]; then + ln -sf "$PKGDEST/${pkgfile##*/}" . + fi done + local l for l in "$copydir"/logdest/*; do [[ $l == */logpipe.* ]] && continue chown "$src_owner" "$l" @@ -367,6 +458,9 @@ move_products() { } # }}} +main() { +init_variables + orig_argv=("$@") while getopts 'hcur:I:l:nTD:d:' arg; do @@ -432,30 +526,45 @@ load_vars /etc/makepkg.conf [[ -d $SRCPKGDEST ]] || SRCPKGDEST=$PWD [[ -d $LOGDEST ]] || LOGDEST=$PWD -create_chroot +# Lock the chroot we want to use. We'll keep this lock until we exit. +lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy" + +if [[ ! -d $copydir ]] || $clean_first; then + sync_chroot "$chrootdir" "$copy" +fi $update_first && arch-nspawn "$copydir" \ "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ pacman -Syu --noconfirm -[[ -n ${install_pkgs[*]} ]] && install_packages +if [[ -n ${install_pkgs[*]:-} ]]; then + install_packages "$copydir" "${install_pkgs[@]}" + ret=$? + # If there is no PKGBUILD we have done + [[ -f PKGBUILD ]] || exit $ret +fi -download_sources +download_sources "$copydir" "$src_owner" -prepare_chroot +prepare_chroot "$copydir" "$USER_HOME" "$repack" if arch-nspawn "$copydir" \ + --bind-ro="$PWD:/startdir_host" \ + --bind-ro="$SRCDEST:/srcdest_host" \ + "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ + /chrootprepare "${makepkg_args[@]}" && + arch-nspawn "$copydir" \ --bind-ro="$PWD:/startdir_host" \ --bind-ro="$SRCDEST:/srcdest_host" \ "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ /chrootbuild "${makepkg_args[@]}" then - move_products + move_products "$copydir" "$src_owner" else (( ret += 1 )) fi -$temp_chroot && clean_temporary +$temp_chroot && delete_chroot "$copydir" if (( ret != 0 )); then if $temp_chroot; then @@ -466,3 +575,4 @@ if (( ret != 0 )); then else true fi +} diff --git a/mkarchroot.in b/mkarchroot.in index 656c74e..f86ae35 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -16,23 +16,29 @@ CHROOT_VERSION='v3' working_dir='' +files=() + usage() { echo "Usage: ${0##*/} [options] working-dir package-list..." echo ' options:' echo ' -C Location of a pacman config file' echo ' -M Location of a makepkg config file' echo ' -c Set pacman cache' + echo ' -f Copy file from the host to the chroot' + echo ' -s Do not run setarch' echo ' -h This message' exit 1 } orig_argv=("$@") -while getopts 'hC:M:c:' arg; do +while getopts 'hC:M:c:f:s' arg; do case "$arg" in C) pac_conf="$OPTARG" ;; M) makepkg_conf="$OPTARG" ;; c) cache_dir="$OPTARG" ;; + f) files+=("$OPTARG") ;; + s) nosetarch=1 ;; h|?) usage ;; *) error "invalid argument '%s'" "$arg"; usage ;; esac @@ -70,6 +76,16 @@ if [[ $(stat -f -c %T "$working_dir") == btrfs ]]; then chmod 0755 "$working_dir" fi +for file in "${files[@]}"; do + mkdir -p "$(dirname "$working_dir$file")" + cp "$file" "$working_dir$file" +done + +_env=() +while read -r varname; do + _env+=("$varname=${!varname}") +done < <(declare -x | sed -r 's/^declare -x ([^=]*)=.*/\1/' | grep -i '_proxy$') +env -i "${_env[@]}" \ pacstrap -GMcd ${pac_conf:+-C "$pac_conf"} "$working_dir" \ "${cache_dirs[@]/#/--cachedir=}" "$@" || die 'Failed to install all packages' @@ -79,7 +95,8 @@ echo "$CHROOT_VERSION" > "$working_dir/.arch-chroot" systemd-machine-id-setup --root="$working_dir" -exec arch-nspawn \ +exec "$(librelib chroot/arch-nspawn)" \ + ${nosetarch:+-s} \ ${pac_conf:+-C "$pac_conf"} \ ${makepkg_conf:+-M "$makepkg_conf"} \ ${cache_dir:+-c "$cache_dir"} \ -- cgit v1.2.3-70-g09d2 From aa11acaf52dfd101cb6fe6f7137d2cbd5c8e0d9b Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 14:19:09 -0500 Subject: Add a "License:" tag to all code files. --- arch-nspawn.in | 2 ++ archbuild.in | 1 + archco.in | 1 + archrelease.in | 1 + archrm.in | 1 + bash_completion.in | 2 ++ checkpkg.in | 1 + commitpkg.in | 1 + crossrepomove.in | 1 + find-libdeps.in | 1 + finddeps.in | 1 + lddd.in | 1 + lib/common.sh | 2 ++ lib/valid-tags.sh | 2 ++ makechrootpkg.in | 2 ++ mkarchroot.in | 2 ++ rebuildpkgs.in | 2 ++ zsh_completion.in | 1 + 18 files changed, 25 insertions(+) diff --git a/arch-nspawn.in b/arch-nspawn.in index efdd97e..fd4c583 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -1,4 +1,6 @@ #!/bin/bash +# License: GNU GPLv2 +# # 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. diff --git a/archbuild.in b/archbuild.in index 812db7c..60e7cec 100644 --- a/archbuild.in +++ b/archbuild.in @@ -1,4 +1,5 @@ #!/bin/bash +# License: Unspecified m4_include(lib/common.sh) diff --git a/archco.in b/archco.in index 2a58921..6088b8e 100644 --- a/archco.in +++ b/archco.in @@ -1,4 +1,5 @@ #!/bin/bash +# License: Unspecified m4_include(lib/common.sh) diff --git a/archrelease.in b/archrelease.in index 4ac55db..3b11652 100644 --- a/archrelease.in +++ b/archrelease.in @@ -1,4 +1,5 @@ #!/bin/bash +# License: Unspecified m4_include(lib/common.sh) m4_include(lib/valid-tags.sh) diff --git a/archrm.in b/archrm.in index 7c7139b..3173131 100644 --- a/archrm.in +++ b/archrm.in @@ -1,4 +1,5 @@ #!/bin/bash +# License: Unspecified m4_include(lib/common.sh) diff --git a/bash_completion.in b/bash_completion.in index dd140fc..b9ed69c 100644 --- a/bash_completion.in +++ b/bash_completion.in @@ -1,3 +1,5 @@ +# License: Unspecified + _devtools_compgen() { local i r COMPREPLY=($(compgen -W '$*' -- "$cur")) diff --git a/checkpkg.in b/checkpkg.in index fcbfd80..fbd30d3 100644 --- a/checkpkg.in +++ b/checkpkg.in @@ -1,4 +1,5 @@ #!/bin/bash +# License: Unspecified shopt -s extglob diff --git a/commitpkg.in b/commitpkg.in index a5e6d65..d31f6ba 100644 --- a/commitpkg.in +++ b/commitpkg.in @@ -1,4 +1,5 @@ #!/bin/bash +# License: Unspecified m4_include(lib/common.sh) diff --git a/crossrepomove.in b/crossrepomove.in index afeec77..1be2dc3 100644 --- a/crossrepomove.in +++ b/crossrepomove.in @@ -1,4 +1,5 @@ #!/bin/bash +# License: Unspecified m4_include(lib/common.sh) diff --git a/find-libdeps.in b/find-libdeps.in index b40f794..5c350a9 100644 --- a/find-libdeps.in +++ b/find-libdeps.in @@ -1,4 +1,5 @@ #!/bin/bash +# License: Unspecified m4_include(lib/common.sh) diff --git a/finddeps.in b/finddeps.in index 7a2a3fb..89ccc41 100644 --- a/finddeps.in +++ b/finddeps.in @@ -2,6 +2,7 @@ # # finddeps - find packages that depend on a given depname # +# License: Unspecified m4_include(lib/common.sh) diff --git a/lddd.in b/lddd.in index f111d67..f01ebf9 100644 --- a/lddd.in +++ b/lddd.in @@ -2,6 +2,7 @@ # # lddd - find broken library links on your machine # +# License: Unspecified m4_include(lib/common.sh) diff --git a/lib/common.sh b/lib/common.sh index b1e7d6e..62f4e72 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -1,3 +1,5 @@ +# License: Unspecified + # Avoid any encoding problems export LANG=C diff --git a/lib/valid-tags.sh b/lib/valid-tags.sh index 36918fe..0543ab2 100644 --- a/lib/valid-tags.sh +++ b/lib/valid-tags.sh @@ -1,3 +1,5 @@ +# License: Unspecified + _arch=( i686 x86_64 diff --git a/makechrootpkg.in b/makechrootpkg.in index 127514d..fe6cdbe 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -1,4 +1,6 @@ #!/bin/bash +# License: GNU GPLv2 +# # 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. diff --git a/mkarchroot.in b/mkarchroot.in index b790bdb..656c74e 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -1,4 +1,6 @@ #!/bin/bash +# License: GNU GPLv2 +# # 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. diff --git a/rebuildpkgs.in b/rebuildpkgs.in index ba8fee4..215439f 100644 --- a/rebuildpkgs.in +++ b/rebuildpkgs.in @@ -1,4 +1,6 @@ #!/bin/bash +# License: Unspecified +# # This script rebuilds a list of packages in order # and reports anything that fails # diff --git a/zsh_completion.in b/zsh_completion.in index 4c6dd99..0f95a4c 100644 --- a/zsh_completion.in +++ b/zsh_completion.in @@ -1,4 +1,5 @@ #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 +# License: Unspecified m4_include(lib/valid-tags.sh) -- cgit v1.2.3-70-g09d2 From f1ed4b1d81dcaa04bfdf49e36f3b5e3cc5dfa338 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 14:29:19 -0500 Subject: lib/common.sh: Make it safe to include multiple times. This is similar to common C #ifdef guards. I was tempted to wrap the entire thing in the if/fi (rather than use 'return' to bail early. However, that means it won't execute anything until after it reaches 'fi'. And if `shopt -s extglob` isn't executed before parsing, then it will syntax-error on the extended globs. One solution would have been to move `shopt -s extglob` up above the include-guard. But the committed solution is all-around simpler. --- lib/common.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/common.sh b/lib/common.sh index 62f4e72..33f9552 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -1,5 +1,11 @@ +#!/hint/bash +# This may be included with or without `set -euE` + # License: Unspecified +[[ -z ${_INCLUDE_COMMON_SH:-} ]] || return 0 +_INCLUDE_COMMON_SH=true + # Avoid any encoding problems export LANG=C -- cgit v1.2.3-70-g09d2 From e1ca5a0bc28697c545b619fe1f07bc6145ef5c38 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 14:37:10 -0500 Subject: mkarchroot, arch-nspawn: Add an `-f` flag to add files to copy. This allows us to copy in files like `qemu-arm-static`, which is necessary for running an ARM chroot on an x86 box. --- arch-nspawn.in | 12 +++++++++++- mkarchroot.in | 11 ++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index fd4c583..19a1a89 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -16,6 +16,8 @@ CHROOT_VERSION='v3' working_dir='' +files=() + usage() { echo "Usage: ${0##*/} [options] working-dir [systemd-nspawn arguments]" echo "A wrapper around systemd-nspawn. Provides support for pacman." @@ -24,17 +26,19 @@ usage() { echo ' -C Location of a pacman config file' echo ' -M Location of a makepkg config file' echo ' -c Set pacman cache' + echo ' -f Copy file from the host to the chroot' echo ' -h This message' exit 1 } orig_argv=("$@") -while getopts 'hC:M:c:' arg; do +while getopts 'hC:M:c:f:' arg; do case "$arg" in C) pac_conf="$OPTARG" ;; M) makepkg_conf="$OPTARG" ;; c) cache_dir="$OPTARG" ;; + f) files+=("$OPTARG") ;; h|?) usage ;; *) error "invalid argument '%s'" "$arg"; usage ;; esac @@ -80,6 +84,12 @@ copy_hostconf () { [[ -n $pac_conf ]] && cp $pac_conf "$working_dir/etc/pacman.conf" [[ -n $makepkg_conf ]] && cp $makepkg_conf "$working_dir/etc/makepkg.conf" + local file + for file in "${files[@]}"; do + mkdir -p "$(dirname "$working_dir$file")" + cp -T "$file" "$working_dir$file" + done + sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${cache_dirs[@]})|g" -i "$working_dir/etc/pacman.conf" } # }}} diff --git a/mkarchroot.in b/mkarchroot.in index 656c74e..8499ed1 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -16,23 +16,27 @@ CHROOT_VERSION='v3' working_dir='' +files=() + usage() { echo "Usage: ${0##*/} [options] working-dir package-list..." echo ' options:' echo ' -C Location of a pacman config file' echo ' -M Location of a makepkg config file' echo ' -c Set pacman cache' + echo ' -f Copy file from the host to the chroot' echo ' -h This message' exit 1 } orig_argv=("$@") -while getopts 'hC:M:c:' arg; do +while getopts 'hC:M:c:f:' arg; do case "$arg" in C) pac_conf="$OPTARG" ;; M) makepkg_conf="$OPTARG" ;; c) cache_dir="$OPTARG" ;; + f) files+=("$OPTARG") ;; h|?) usage ;; *) error "invalid argument '%s'" "$arg"; usage ;; esac @@ -70,6 +74,11 @@ if [[ $(stat -f -c %T "$working_dir") == btrfs ]]; then chmod 0755 "$working_dir" fi +for file in "${files[@]}"; do + mkdir -p "$(dirname "$working_dir$file")" + cp "$file" "$working_dir$file" +done + pacstrap -GMcd ${pac_conf:+-C "$pac_conf"} "$working_dir" \ "${cache_dirs[@]/#/--cachedir=}" "$@" || die 'Failed to install all packages' -- cgit v1.2.3-70-g09d2 From df3eee40d3ff0a6c8532a1d19bad25d057330cd2 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 14:39:25 -0500 Subject: mkarchroot, arch-nspawn: Add an `-s` flag to inhibit `setarch`. This allows us to run an ARM chroot on an x86 box; as the binfmt runner will set the architecture for us, and the x86 `/usr/bin/setarch` program won't know about the ARM architecture string. --- arch-nspawn.in | 6 +++++- mkarchroot.in | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index 19a1a89..ea6e5ea 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -27,18 +27,20 @@ usage() { echo ' -M Location of a makepkg config file' echo ' -c Set pacman cache' echo ' -f Copy file from the host to the chroot' + echo ' -s Do not run setarch' echo ' -h This message' exit 1 } orig_argv=("$@") -while getopts 'hC:M:c:f:' arg; do +while getopts 'hC:M:c:f:s' arg; do case "$arg" in C) pac_conf="$OPTARG" ;; M) makepkg_conf="$OPTARG" ;; c) cache_dir="$OPTARG" ;; f) files+=("$OPTARG") ;; + s) nosetarch=1 ;; h|?) usage ;; *) error "invalid argument '%s'" "$arg"; usage ;; esac @@ -111,6 +113,8 @@ case "$CARCH" in armv7h) CARCH=armv7l;; esac +[[ -z $nosetarch ]] || unset CARCH + exec ${CARCH:+setarch "$CARCH"} systemd-nspawn -q \ -D "$working_dir" \ --register=no \ diff --git a/mkarchroot.in b/mkarchroot.in index 8499ed1..4cf8e56 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -25,18 +25,20 @@ usage() { echo ' -M Location of a makepkg config file' echo ' -c Set pacman cache' echo ' -f Copy file from the host to the chroot' + echo ' -s Do not run setarch' echo ' -h This message' exit 1 } orig_argv=("$@") -while getopts 'hC:M:c:f:' arg; do +while getopts 'hC:M:c:f:s' arg; do case "$arg" in C) pac_conf="$OPTARG" ;; M) makepkg_conf="$OPTARG" ;; c) cache_dir="$OPTARG" ;; f) files+=("$OPTARG") ;; + s) nosetarch=1 ;; h|?) usage ;; *) error "invalid argument '%s'" "$arg"; usage ;; esac @@ -89,6 +91,7 @@ echo "$CHROOT_VERSION" > "$working_dir/.arch-chroot" systemd-machine-id-setup --root="$working_dir" exec arch-nspawn \ + ${nosetarch:+-s} \ ${pac_conf:+-C "$pac_conf"} \ ${makepkg_conf:+-M "$makepkg_conf"} \ ${cache_dir:+-c "$cache_dir"} \ -- cgit v1.2.3-70-g09d2 From 2c504b8edc4f5ffde99323a65442675402cbd83b Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 15:00:12 -0500 Subject: mkarchroot: Don't let the environment affect pacstrap (sans proxy settings). A previous iteration of this change (libretools commit d7dcce53396d) simply inserted `env -i` to clear the environment. However, that lead to it ignoring proxy settings, which some users had problems with: https://labs.parabola.nu/issues/487: > To fix other bugs, the pacstrap environment is blank, which also > means that the proxy settings are blank. So (in libretools commit d17d1d82349f), I changed it to use `declare -x` to inspect the environment, and create a version of it only consisting of variables ending with "_proxy" (case-insensitive). I honestly don't remember what "other bugs" prompted me to clear the environment in the first place. --- mkarchroot.in | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mkarchroot.in b/mkarchroot.in index 4cf8e56..4ebafa6 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -81,6 +81,11 @@ for file in "${files[@]}"; do cp "$file" "$working_dir$file" done +_env=() +while read -r varname; do + _env+=("$varname=${!varname}") +done < <(declare -x | sed -r 's/^declare -x ([^=]*)=.*/\1/' | grep -i '_proxy$') +env -i "${_env[@]}" \ pacstrap -GMcd ${pac_conf:+-C "$pac_conf"} "$working_dir" \ "${cache_dirs[@]/#/--cachedir=}" "$@" || die 'Failed to install all packages' -- cgit v1.2.3-70-g09d2 From 54749b7fce6d95c1653ca1e2cf0936d1cecc688e Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 17:05:37 -0500 Subject: makechrootpkg: Quote directory passed to `rm -rf`. --- makechrootpkg.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index fe6cdbe..871537c 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -304,7 +304,7 @@ download_sources() { (( $? != 0 )) && die "Could not download sources." # Clean up garbage from verifysource - rm -rf $builddir + rm -rf "$builddir" } _chrootbuild() { -- cgit v1.2.3-70-g09d2 From 914cf4f45d3dfc3a566e77397a0ef8ed97ad41cc Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 17:06:32 -0500 Subject: makechrootpkg: Improve status messages. --- makechrootpkg.in | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index 871537c..ee4a933 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -144,9 +144,10 @@ create_chroot() { 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 - slock 8 "$chrootdir/root.lock" "Locking clean chroot" + slock 8 "$chrootdir/root.lock" \ + "Locking clean chroot [%s]" "$chrootdir/root" - stat_busy "Creating clean working copy [%s]" "$copy" + stat_busy "Synchronizing chroot copy [%s] -> [%s]" "$chrootdir/root" "$copydir" if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then if [[ -d $copydir ]]; then btrfs_subvolume_delete "$copydir" >/dev/null || @@ -169,7 +170,7 @@ create_chroot() { } clean_temporary() { - stat_busy "Removing temporary copy [%s]" "$copy" + stat_busy "Removing chroot copy [%s]" "$copydir" if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then btrfs_subvolume_delete "$copydir" >/dev/null || die "Unable to delete subvolume %s" "$copydir" -- cgit v1.2.3-70-g09d2 From 37eec3ff31c4a709fcd8e21dbf4e53624f0fc2f1 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 15:36:21 -0500 Subject: makechrootpkg: Have functions be more function-y. Rather than them simply being named blocks of code with braces around them. That is: have them take things via arguments rather than global variables. Specific notes: - download_sources: Observation: if $SUDO_USER is set, then src_owner=$SUDO_USER. So (for clarity), rather than checking if $SUDO_USER is set, check if $src_owner is different than $USER. This reduces how much we have to worry about global state. - install_packages: 1. Receive the list of packages as arguments, rather than a global variable. 2. Make the caller responsible for looking at PKGBUILD. From the name and arguments, one would never expect it to look at PKGBUILD. - create_chroot->sync_chroot: I pulled the `if [[ ! -d $copydir ]] || $clean_first;` check out; it is now the caller's responsibility to use that check when deciding if to call sync_chroot. --- makechrootpkg.in | 136 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 100 insertions(+), 36 deletions(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index ee4a933..970d3e9 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -70,6 +70,14 @@ usage() { } # {{{ functions +# Usage: load_vars $makepkg_conf +# Globals: +# - SRCDEST +# - SRCPKGDEST +# - PKGDEST +# - LOGDEST +# - MAKEFLAGS +# - PACKAGER load_vars() { local makepkg_conf="$1" var @@ -137,39 +145,56 @@ btrfs_subvolume_delete() { btrfs subvolume delete "$dir" } -create_chroot() { - # Lock the chroot we want to use. We'll keep this lock until we exit. - lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$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 - slock 8 "$chrootdir/root.lock" \ - "Locking clean chroot [%s]" "$chrootdir/root" - - stat_busy "Synchronizing chroot copy [%s] -> [%s]" "$chrootdir/root" "$copydir" - if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then - if [[ -d $copydir ]]; then - btrfs_subvolume_delete "$copydir" >/dev/null || - die "Unable to delete subvolume %s" "$copydir" - fi - btrfs subvolume snapshot "$chrootdir/root" "$copydir" >/dev/null || - die "Unable to create subvolume %s" "$copydir" - else - mkdir -p "$copydir" - rsync -a --delete -q -W -x "$chrootdir/root/" "$copydir" - fi - stat_done +# Usage: sync_chroot $CHROOTDIR/$CHROOT <$CHROOTCOPY|$copydir> +# Globals: +# - chroottype +sync_chroot() { + local chrootdir=$1 + local copy=$2 + local copydir='' + if [[ ${copy:0:1} = / ]]; then + copydir=$copy + else + copydir="$chrootdir/$copy" + fi + + if [[ "$chrootdir/root" -ef "$copydir" ]]; then + error 'Cannot sync copy with itself: %s' "$copydir" + return 1 + fi - # Drop the read lock again - lock_close 8 + # Get a read lock on the root chroot to make + # sure we don't clone a half-updated chroot + slock 8 "$chrootdir/root.lock" \ + "Locking clean chroot [%s]" "$chrootdir/root" + + stat_busy "Synchronizing chroot copy [%s] -> [%s]" "$chrootdir/root" "$copydir" + if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then + if [[ -d $copydir ]]; then + btrfs_subvolume_delete "$copydir" >/dev/null || + die "Unable to delete subvolume %s" "$copydir" + fi + btrfs subvolume snapshot "$chrootdir/root" "$copydir" >/dev/null || + die "Unable to create subvolume %s" "$copydir" + else + mkdir -p "$copydir" + rsync -a --delete -q -W -x "$chrootdir/root/" "$copydir" fi + stat_done + + # Drop the read lock again + lock_close 8 # Update mtime touch "$copydir" } -clean_temporary() { +# Usage: delete_chroot $copydir +# Globals: +# - chroottype +delete_chroot() { + local copydir=$1 + stat_busy "Removing chroot copy [%s]" "$copydir" if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then btrfs_subvolume_delete "$copydir" >/dev/null || @@ -185,9 +210,14 @@ clean_temporary() { stat_done } +# Usage: install_packages $copydir $pkgs... install_packages() { + local copydir=$1 + local install_pkgs=("${@:2}") + declare -i ret=0 local pkgname + local install_pkg for install_pkg in "${install_pkgs[@]}"; do pkgname="${install_pkg##*/}" cp "$install_pkg" "$copydir/$pkgname" @@ -200,11 +230,19 @@ install_packages() { rm "$copydir/$pkgname" done - # If there is no PKGBUILD we are done - [[ -f PKGBUILD ]] || exit $ret + return $ret } +# Usage: prepare_chroot $copydir $HOME $repack $run_namcap +# Globals: +# - MAKEFLAGS +# - PACKAGER prepare_chroot() { + local copydir=$1 + local USER_HOME=$2 + local repack=$3 + local run_namcap=$4 + $repack || rm -rf "$copydir/build" mkdir -p "$copydir/build" @@ -289,13 +327,20 @@ EOF chmod +x "$copydir/chrootbuild" } +# Usage: download_sources $copydir $src_owner +# Globals: +# - SRCDEST +# - USER download_sources() { + local copydir=$1 + local src_owner=$2 + local builddir="$(mktemp -d)" chmod 1777 "$builddir" # Ensure sources are downloaded - if [[ -n $SUDO_USER ]]; then - sudo -u $SUDO_USER env SRCDEST="$SRCDEST" BUILDDIR="$builddir" \ + if [[ $USER != $src_owner ]]; then + sudo -u $src_owner env SRCDEST="$SRCDEST" BUILDDIR="$builddir" \ makepkg --config="$copydir/etc/makepkg.conf" --verifysource -o else ( export SRCDEST BUILDDIR="$builddir" @@ -349,12 +394,21 @@ _chrootbuild() { sudo -u builduser makepkg "$@" } +# Usage: move_products $copydir $owner +# Globals: +# - PKGDEST +# - LOGDEST move_products() { + local copydir=$1 + local src_owner=$2 + + local pkgfile for pkgfile in "$copydir"/pkgdest/*; do chown "$src_owner" "$pkgfile" mv "$pkgfile" "$PKGDEST" done + local l for l in "$copydir"/logdest/*; do [[ $l == */logpipe.* ]] && continue chown "$src_owner" "$l" @@ -433,17 +487,27 @@ load_vars /etc/makepkg.conf [[ -d $SRCPKGDEST ]] || SRCPKGDEST=$PWD [[ -d $LOGDEST ]] || LOGDEST=$PWD -create_chroot +# Lock the chroot we want to use. We'll keep this lock until we exit. +lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy" + +if [[ ! -d $copydir ]] || $clean_first; then + sync_chroot "$chrootdir" "$copy" +fi $update_first && arch-nspawn "$copydir" \ "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ pacman -Syu --noconfirm -[[ -n ${install_pkgs[*]} ]] && install_packages +if [[ -n ${install_pkgs[*]} ]]; then + install_packages "$copydir" "${install_pkgs[@]}" + ret=$? + # If there is no PKGBUILD we have done + [[ -f PKGBUILD ]] || return $ret +fi -download_sources +download_sources "$copydir" "$src_owner" -prepare_chroot +prepare_chroot "$copydir" "$USER_HOME" "$repack" if arch-nspawn "$copydir" \ --bind-ro="$PWD:/startdir_host" \ @@ -451,12 +515,12 @@ if arch-nspawn "$copydir" \ "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ /chrootbuild "${makepkg_args[@]}" then - move_products + move_products "$copydir" "$src_owner" else (( ret += 1 )) fi -$temp_chroot && clean_temporary +$temp_chroot && delete_chroot "$copydir" if (( ret != 0 )); then if $temp_chroot; then -- cgit v1.2.3-70-g09d2 From 05a65ee16dce078e87f5dba576d0d087e22c34d7 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 18:41:58 -0500 Subject: makechrootpkg: Detect the chroottype in individual functions, not globally. --- makechrootpkg.in | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index 970d3e9..8e1fd95 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -146,8 +146,6 @@ btrfs_subvolume_delete() { } # Usage: sync_chroot $CHROOTDIR/$CHROOT <$CHROOTCOPY|$copydir> -# Globals: -# - chroottype sync_chroot() { local chrootdir=$1 local copy=$2 @@ -163,6 +161,9 @@ sync_chroot() { return 1 fi + # Detect chrootdir filesystem type + local chroottype=$(stat -f -c %T "$chrootdir") + # Get a read lock on the root chroot to make # sure we don't clone a half-updated chroot slock 8 "$chrootdir/root.lock" \ @@ -190,10 +191,10 @@ sync_chroot() { } # Usage: delete_chroot $copydir -# Globals: -# - chroottype delete_chroot() { local copydir=$1 + # Detect chrootdir filesystem type + local chroottype=$(stat -f -c %T "$copydir") stat_busy "Removing chroot copy [%s]" "$copydir" if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then @@ -448,9 +449,6 @@ chrootdir=$(readlink -e "$passeddir") [[ ! -d $chrootdir ]] && die "No chroot dir defined, or invalid path '%s'" "$passeddir" [[ ! -d $chrootdir/root ]] && die "Missing chroot dir root directory. Try using: mkarchroot %s/root base-devel" "$chrootdir" -# Detect chrootdir filesystem type -chroottype=$(stat -f -c %T "$chrootdir") - if [[ ${copy:0:1} = / ]]; then copydir=$copy else -- cgit v1.2.3-70-g09d2 From 5f3b9de5178b6be3bb12390d5fb299594a757844 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 15:56:42 -0500 Subject: makechrootpkg: _chrootbuild: Split into _chroot{prepare,build}. --- makechrootpkg.in | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index 8e1fd95..67d2cf8 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -310,6 +310,12 @@ EOF # This is a little gross, but this way the script is recreated every time in the # working copy + { + printf '#!/bin/bash\n' + declare -f _chrootprepare + printf '_chrootprepare "$@"\n' + } > "$copydir/chrootprepare" + chmod +x "$copydir/chrootprepare" { printf '#!/bin/bash\n' declare -f _chrootbuild @@ -354,7 +360,7 @@ download_sources() { rm -rf "$builddir" } -_chrootbuild() { +_chrootprepare() { # This function isn't run in makechrootpkg, # so no global variables @@ -392,7 +398,20 @@ _chrootbuild() { exit 1 fi - sudo -u builduser makepkg "$@" + sudo -u builduser makepkg "$@" --nobuild +} + +_chrootbuild() { + # This function isn't run in makechrootpkg, + # so no global variables + + . /etc/profile + export HOME=/build + shopt -s nullglob + + cd /startdir + + sudo -u builduser makepkg "$@" --noextract --noprepare } # Usage: move_products $copydir $owner @@ -508,6 +527,11 @@ download_sources "$copydir" "$src_owner" prepare_chroot "$copydir" "$USER_HOME" "$repack" if arch-nspawn "$copydir" \ + --bind-ro="$PWD:/startdir_host" \ + --bind-ro="$SRCDEST:/srcdest_host" \ + "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ + /chrootprepare "${makepkg_args[@]}" && + arch-nspawn "$copydir" \ --bind-ro="$PWD:/startdir_host" \ --bind-ro="$SRCDEST:/srcdest_host" \ "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ -- cgit v1.2.3-70-g09d2 From 428cf5f1f8718f0abc2a9410677222889b9c8470 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 17:34:31 -0500 Subject: makechrootpkg: _chrootprepare: Clean srcdest and startdir. --- makechrootpkg.in | 1 + 1 file changed, 1 insertion(+) diff --git a/makechrootpkg.in b/makechrootpkg.in index 67d2cf8..d40bb88 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -369,6 +369,7 @@ _chrootprepare() { shopt -s nullglob # XXX: Workaround makepkg disliking read-only dirs + rm -rf -- /srcdest/* /startdir/* ln -sft /srcdest /srcdest_host/* ln -sft /startdir /startdir_host/* -- cgit v1.2.3-70-g09d2 From c8300c3ff1afc667aa53f1782846902752687357 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 18:39:40 -0500 Subject: makechrootpkg: move_products: Mimic `makepkg` and symlink products into PWD. --- makechrootpkg.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/makechrootpkg.in b/makechrootpkg.in index d40bb88..878c663 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -427,6 +427,9 @@ move_products() { for pkgfile in "$copydir"/pkgdest/*; do chown "$src_owner" "$pkgfile" mv "$pkgfile" "$PKGDEST" + if [[ $PKGDEST != $PWD ]]; then + ln -sf "$PKGDEST/${pkgfile##*/}" . + fi done local l -- cgit v1.2.3-70-g09d2 From 22da1ef5087e7065439e23187f0984148a905fff Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 14:40:06 -0500 Subject: makechrootpkg, arch-nspawn: Force-enable local '/repo/' repository. The change in arch-nspawn is subtle: This was the source of "infamous" "it fails every other time" bug that took me over a year to solve. By having a repository of local packages (rather than simply running `pacman -U`), we are inviting pacman to cache them in `/var/cache/pacman/pkg`. Besides being needless disk writes, this actually causes a real issue. If the package gets rebuilt, pacman will balk, as the file no longer matches the cached signature. So, how do we prevent pacman from caching these local packages? Simple: include the directory they are already in in the pacman.conf:CacheDir list. This will prevent pacman from copying the files to one of the other cache directories. --- arch-nspawn.in | 1 + makechrootpkg.in | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/arch-nspawn.in b/arch-nspawn.in index ea6e5ea..85af8c5 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -106,6 +106,7 @@ elif [[ $(cat "$working_dir/.arch-chroot") != $CHROOT_VERSION ]]; then fi build_mount_args +cache_dirs+=('/repo/') copy_hostconf eval $(grep '^CARCH=' "$working_dir/etc/makepkg.conf") diff --git a/makechrootpkg.in b/makechrootpkg.in index 878c663..3f4e009 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -308,6 +308,15 @@ EOF chmod 440 "$copydir/etc/sudoers.d/builduser-pacman" fi + if ! grep -q '^\[repo\]' "$copydir/etc/pacman.conf"; then + local line=$(grep -n '^\[' "$copydir/etc/pacman.conf" |grep -Fv ':[options]'|sed 's/:.*//;1q') + local ins='[repo] +SigLevel = Optional TrustAll +Server = file:///repo +' + sed -i "${line}i${ins//$'\n'/\\n}" "$copydir/etc/pacman.conf" + fi + # This is a little gross, but this way the script is recreated every time in the # working copy { @@ -399,6 +408,8 @@ _chrootprepare() { exit 1 fi + # Sync deps now, as networking may be disabled during _chrootbuild + cp /repo/repo.db /var/lib/pacman/sync/repo.db sudo -u builduser makepkg "$@" --nobuild } -- cgit v1.2.3-70-g09d2 From 90fe539365baf28be143e3ab500bf654ef3b98d5 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 15:25:22 -0500 Subject: makechrootpkg: Adjust to have the functions work with `set -u`. Even though main() doesn't call `set -u`; this way the functions will continue to work if copied into an environment with `set -u`, or so that we are ready if we ever want to start using `set -u`. --- makechrootpkg.in | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index 3f4e009..afd14f6 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -31,7 +31,7 @@ bindmounts_ro=() bindmounts_rw=() copy=$USER -[[ -n $SUDO_USER ]] && copy=$SUDO_USER +[[ -n ${SUDO_USER:-} ]] && copy=$SUDO_USER [[ -z "$copy" || $copy = root ]] && copy=copy src_owner=${SUDO_USER:-$USER} @@ -84,7 +84,7 @@ load_vars() { [[ -f $makepkg_conf ]] || return 1 for var in {SRC,SRCPKG,PKG,LOG}DEST MAKEFLAGS PACKAGER; do - [[ -z ${!var} ]] && eval $(grep "^${var}=" "$makepkg_conf") + [[ -z ${!var:-} ]] && eval $(grep "^${var}=" "$makepkg_conf") done return 0 @@ -290,12 +290,12 @@ prepare_chroot() { printf 'builduser:x:%d:100:builduser:/build:/bin/bash\n' "$builduser_uid" >>"$copydir/etc/passwd" chown -R "$builduser_uid" "$copydir"/{build,pkgdest,srcpkgdest,logdest,srcdest,startdir} - if [[ -n $MAKEFLAGS ]]; then + if [[ -n ${MAKEFLAGS:-} ]]; then sed -i '/^MAKEFLAGS=/d' "$copydir/etc/makepkg.conf" echo "MAKEFLAGS='${MAKEFLAGS}'" >> "$copydir/etc/makepkg.conf" fi - if [[ -n $PACKAGER ]]; then + if [[ -n ${PACKAGER:-} ]]; then sed -i '/^PACKAGER=/d' "$copydir/etc/makepkg.conf" echo "PACKAGER='${PACKAGER}'" >> "$copydir/etc/makepkg.conf" fi @@ -530,7 +530,7 @@ $update_first && arch-nspawn "$copydir" \ "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ pacman -Syu --noconfirm -if [[ -n ${install_pkgs[*]} ]]; then +if [[ -n ${install_pkgs[*]:-} ]]; then install_packages "$copydir" "${install_pkgs[@]}" ret=$? # If there is no PKGBUILD we have done -- cgit v1.2.3-70-g09d2 From 880ae81d3c485a54c744cb75f3faa4adf8cea802 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 15:27:51 -0500 Subject: makechrootpkg: Avoid having code floating around outside of a function. This means wrapping variable initialization in init_variables(), and the main program routine in main(). I did NOT put `shopt -s nullglob` in to a function. --- makechrootpkg.in | 238 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 123 insertions(+), 115 deletions(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index afd14f6..7ff2fd7 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -14,26 +14,28 @@ m4_include(lib/common.sh) shopt -s nullglob -default_makepkg_args=(-s --noconfirm -L --holdver) -makepkg_args=("${default_makepkg_args[@]}") -repack=false -update_first=false -clean_first=false -install_pkg= -run_namcap=false -temp_chroot=false -chrootdir= -passeddir= -declare -a install_pkgs -declare -i ret=0 - -bindmounts_ro=() -bindmounts_rw=() - -copy=$USER -[[ -n ${SUDO_USER:-} ]] && copy=$SUDO_USER -[[ -z "$copy" || $copy = root ]] && copy=copy -src_owner=${SUDO_USER:-$USER} +init_variables() { + default_makepkg_args=(-s --noconfirm -L --holdver) + makepkg_args=("${default_makepkg_args[@]}") + repack=false + update_first=false + clean_first=false + install_pkg= + run_namcap=false + temp_chroot=false + chrootdir= + passeddir= + declare -a install_pkgs + declare -i ret=0 + + bindmounts_ro=() + bindmounts_rw=() + + copy=$USER + [[ -n ${SUDO_USER:-} ]] && copy=$SUDO_USER + [[ -z "$copy" || $copy = root ]] && copy=copy + src_owner=${SUDO_USER:-$USER} +} usage() { echo "Usage: ${0##*/} [options] -r [--] [makepkg args]" @@ -457,114 +459,120 @@ move_products() { } # }}} -orig_argv=("$@") - -while getopts 'hcur:I:l:nTD:d:' arg; do - case "$arg" in - c) clean_first=true ;; - D) bindmounts_ro+=(--bind-ro="$OPTARG") ;; - d) bindmounts_rw+=(--bind="$OPTARG") ;; - u) update_first=true ;; - r) passeddir="$OPTARG" ;; - I) install_pkgs+=("$OPTARG") ;; - l) copy="$OPTARG" ;; - n) run_namcap=true; makepkg_args+=(-i) ;; - T) temp_chroot=true; copy+="-$$" ;; - h|*) usage ;; - esac -done +main() { + init_variables + + orig_argv=("$@") + + while getopts 'hcur:I:l:nTD:d:' arg; do + case "$arg" in + c) clean_first=true ;; + D) bindmounts_ro+=(--bind-ro="$OPTARG") ;; + d) bindmounts_rw+=(--bind="$OPTARG") ;; + u) update_first=true ;; + r) passeddir="$OPTARG" ;; + I) install_pkgs+=("$OPTARG") ;; + l) copy="$OPTARG" ;; + n) run_namcap=true; makepkg_args+=(-i) ;; + T) temp_chroot=true; copy+="-$$" ;; + h|*) usage ;; + esac + done -[[ ! -f PKGBUILD && -z "${install_pkgs[*]}" ]] && die 'This must be run in a directory containing a PKGBUILD.' + [[ ! -f PKGBUILD && -z "${install_pkgs[*]}" ]] && die 'This must be run in a directory containing a PKGBUILD.' -check_root "$0" "${orig_argv[@]}" + check_root "$0" "${orig_argv[@]}" -# Canonicalize chrootdir, getting rid of trailing / -chrootdir=$(readlink -e "$passeddir") -[[ ! -d $chrootdir ]] && die "No chroot dir defined, or invalid path '%s'" "$passeddir" -[[ ! -d $chrootdir/root ]] && die "Missing chroot dir root directory. Try using: mkarchroot %s/root base-devel" "$chrootdir" + # Canonicalize chrootdir, getting rid of trailing / + chrootdir=$(readlink -e "$passeddir") + [[ ! -d $chrootdir ]] && die "No chroot dir defined, or invalid path '%s'" "$passeddir" + [[ ! -d $chrootdir/root ]] && die "Missing chroot dir root directory. Try using: mkarchroot %s/root base-devel" "$chrootdir" -if [[ ${copy:0:1} = / ]]; then - copydir=$copy -else - copydir="$chrootdir/$copy" -fi + if [[ ${copy:0:1} = / ]]; then + copydir=$copy + else + copydir="$chrootdir/$copy" + fi -# Pass all arguments after -- right to makepkg -makepkg_args+=("${@:$OPTIND}") + # Pass all arguments after -- right to makepkg + makepkg_args+=("${@:$OPTIND}") + + # See if -R was passed to makepkg + for arg in "${@:OPTIND}"; do + case ${arg%%=*} in + -*R*|--repackage) + repack=true + break 2 + ;; + esac + done -# See if -R was passed to makepkg -for arg in "${@:OPTIND}"; do - case ${arg%%=*} in - -*R*|--repackage) - repack=true - break 2 - ;; - esac -done + if [[ -n $SUDO_USER ]]; then + eval "USER_HOME=~$SUDO_USER" + else + USER_HOME=$HOME + fi -if [[ -n $SUDO_USER ]]; then - eval "USER_HOME=~$SUDO_USER" -else - USER_HOME=$HOME -fi + umask 0022 -umask 0022 + load_vars "$USER_HOME/.makepkg.conf" + load_vars /etc/makepkg.conf -load_vars "$USER_HOME/.makepkg.conf" -load_vars /etc/makepkg.conf + # Use PKGBUILD directory if these don't exist + [[ -d $PKGDEST ]] || PKGDEST=$PWD + [[ -d $SRCDEST ]] || SRCDEST=$PWD + [[ -d $SRCPKGDEST ]] || SRCPKGDEST=$PWD + [[ -d $LOGDEST ]] || LOGDEST=$PWD -# Use PKGBUILD directory if these don't exist -[[ -d $PKGDEST ]] || PKGDEST=$PWD -[[ -d $SRCDEST ]] || SRCDEST=$PWD -[[ -d $SRCPKGDEST ]] || SRCPKGDEST=$PWD -[[ -d $LOGDEST ]] || LOGDEST=$PWD + # Lock the chroot we want to use. We'll keep this lock until we exit. + lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy" -# Lock the chroot we want to use. We'll keep this lock until we exit. -lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy" + if [[ ! -d $copydir ]] || $clean_first; then + sync_chroot "$chrootdir" "$copy" + fi + + $update_first && arch-nspawn "$copydir" \ + "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ + pacman -Syu --noconfirm -if [[ ! -d $copydir ]] || $clean_first; then - sync_chroot "$chrootdir" "$copy" -fi + if [[ -n ${install_pkgs[*]:-} ]]; then + install_packages "$copydir" "${install_pkgs[@]}" + ret=$? + # If there is no PKGBUILD we have done + [[ -f PKGBUILD ]] || return $ret + fi -$update_first && arch-nspawn "$copydir" \ + download_sources "$copydir" "$src_owner" + + prepare_chroot "$copydir" "$USER_HOME" "$repack" + + if arch-nspawn "$copydir" \ + --bind-ro="$PWD:/startdir_host" \ + --bind-ro="$SRCDEST:/srcdest_host" \ + "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ + /chrootprepare "${makepkg_args[@]}" && + arch-nspawn "$copydir" \ + --bind-ro="$PWD:/startdir_host" \ + --bind-ro="$SRCDEST:/srcdest_host" \ "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ - pacman -Syu --noconfirm - -if [[ -n ${install_pkgs[*]:-} ]]; then - install_packages "$copydir" "${install_pkgs[@]}" - ret=$? - # If there is no PKGBUILD we have done - [[ -f PKGBUILD ]] || return $ret -fi - -download_sources "$copydir" "$src_owner" - -prepare_chroot "$copydir" "$USER_HOME" "$repack" - -if arch-nspawn "$copydir" \ - --bind-ro="$PWD:/startdir_host" \ - --bind-ro="$SRCDEST:/srcdest_host" \ - "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ - /chrootprepare "${makepkg_args[@]}" && - arch-nspawn "$copydir" \ - --bind-ro="$PWD:/startdir_host" \ - --bind-ro="$SRCDEST:/srcdest_host" \ - "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ - /chrootbuild "${makepkg_args[@]}" -then - move_products "$copydir" "$src_owner" -else - (( ret += 1 )) -fi - -$temp_chroot && delete_chroot "$copydir" - -if (( ret != 0 )); then - if $temp_chroot; then - die "Build failed" + /chrootbuild "${makepkg_args[@]}" + then + move_products "$copydir" "$src_owner" else - die "Build failed, check %s/build" "$copydir" + (( ret += 1 )) fi -else - true -fi + + $temp_chroot && delete_chroot "$copydir" + + if (( ret != 0 )); then + if $temp_chroot; then + die "Build failed" + else + die "Build failed, check %s/build" "$copydir" + fi + else + true + fi +} + +main "$@" -- cgit v1.2.3-70-g09d2 From 10820f2701f1fe43ea32d72c88b6a70dace09b76 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 14:03:57 -0500 Subject: lib/common.sh: Internationalize. --- lib/common.sh | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/common.sh b/lib/common.sh index 33f9552..89cd257 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -6,8 +6,18 @@ [[ -z ${_INCLUDE_COMMON_SH:-} ]] || return 0 _INCLUDE_COMMON_SH=true -# Avoid any encoding problems -export LANG=C +[[ -n ${TEXTDOMAIN:-} ]] || export TEXTDOMAIN='libretools' +[[ -n ${TEXTDOMAINDIR:-} ]] || export TEXTDOMAINDIR='/usr/share/locale' + +if type gettext &>/dev/null; then + _() { gettext "$@"; } +else + _() { echo "$@"; } +fi + +_l() { + TEXTDOMAIN='librelib' TEXTDOMAINDIR='/usr/share/locale' "$@" +} shopt -s extglob @@ -34,37 +44,37 @@ fi readonly ALL_OFF BOLD BLUE GREEN RED YELLOW plain() { - local mesg=$1; shift + local mesg="$(_ "$1")"; shift printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } msg() { - local mesg=$1; shift + local mesg="$(_ "$1")"; shift printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } msg2() { - local mesg=$1; shift + local mesg="$(_ "$1")"; shift printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } warning() { - local mesg=$1; shift - printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 + local mesg="$(_ "$1")"; shift + printf "${YELLOW}==> $(_l _ "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } error() { - local mesg=$1; shift - printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 + local mesg="$(_ "$1")"; shift + printf "${RED}==> $(_l _ "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } stat_busy() { - local mesg=$1; shift + local mesg="$(_ "$1")"; shift printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}...${ALL_OFF}" "$@" >&2 } stat_done() { - printf "${BOLD}$(gettext "done")${ALL_OFF}\n" >&2 + printf "${BOLD}$(_l _ "done")${ALL_OFF}\n" >&2 } _setup_workdir=false @@ -83,7 +93,7 @@ cleanup() { } abort() { - error 'Aborting...' + _l error 'Aborting...' cleanup 255 } @@ -261,7 +271,7 @@ find_cached_package() { return 0 ;; *) - error 'Multiple packages found:' + _l error 'Multiple packages found:' printf '\t%s\n' "${results[@]}" >&2 return 1 esac -- cgit v1.2.3-70-g09d2 From e5d65f09ed2421c5e68e3a6fa91bb51773734e26 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 14:42:06 -0500 Subject: checkpkg, find-libdeps, finddeps, lddd: Use libremessages to add help text. --- checkpkg.in | 27 +++++++++++++++++++++++++-- find-libdeps.in | 28 ++++++++++++++++++++++++---- finddeps.in | 18 ++++++++++++------ lddd.in | 18 +++++++++++++++++- 4 files changed, 78 insertions(+), 13 deletions(-) diff --git a/checkpkg.in b/checkpkg.in index fbd30d3..6904e32 100644 --- a/checkpkg.in +++ b/checkpkg.in @@ -3,7 +3,28 @@ shopt -s extglob -m4_include(lib/common.sh) +. "$(librelib messages)" + +usage() { + print 'Usage: %s [-h]' "${0##*/}" + print 'Compare a locally built a package with the one in the repositories.' + echo + prose 'This should be run from a directory containing a + PKGBUILD. It searches for a locally built package + corresponding to the PKGBUILD, and downloads the last + version of that package from the pacman repositories. + It then compares the list of .so files provided by each + version of the package. It does this for each part of + a split package.' +} + +if [[ $1 = '-h' ]]; then + usage + exit 0 +elif [[ $# -gt 0 ]]; then + usage >&2 + exit 1 +fi # Source makepkg.conf; fail if it is not found if [[ -r '/etc/makepkg.conf' ]]; then @@ -18,7 +39,9 @@ if [[ -r ~/.makepkg.conf ]]; then fi if [[ ! -f PKGBUILD ]]; then - die 'This must be run in the directory of a built package.' + error 'This must be run in the directory of a built package.' + usage >&2 + exit 1 fi . ./PKGBUILD diff --git a/find-libdeps.in b/find-libdeps.in index 5c350a9..794a2cd 100644 --- a/find-libdeps.in +++ b/find-libdeps.in @@ -1,7 +1,7 @@ #!/bin/bash # License: Unspecified -m4_include(lib/common.sh) +. "$(librelib messages)" set -e shopt -s extglob @@ -20,12 +20,32 @@ case $script_mode in *) die "Unknown mode %s" "$script_mode" ;; esac +usage() { + print "Usage: find-lib(deps|provides) [options] " + print "Find library dependencies or provides of a package." + echo + prose 'Prints a list of library dependencies in the format:' + echo + print ' =-' + echo + prose 'Where is the shared library version, or + repeated if there is no version attached; and + is the architecture of the library (either `32` + or `64`, based on the ELF Class).' + echo + print "Options:" + flag "--ignore-internal" "Ignore internal libraries; libraries + without a version attached" + flag "-h" "Show this message" +} if [[ -z $1 ]]; then - echo "${0##*/} [options] " - echo "Options:" - echo " --ignore-internal ignore internal libraries" + usage >&2 exit 1 fi +if [[ $1 = '-h' ]]; then + usage + exit 0 +fi if [[ -d $1 ]]; then pushd $1 >/dev/null diff --git a/finddeps.in b/finddeps.in index 89ccc41..cc1ffab 100644 --- a/finddeps.in +++ b/finddeps.in @@ -4,18 +4,24 @@ # # License: Unspecified -m4_include(lib/common.sh) +. "$(librelib messages)" match=$1 +usage() { + print 'Usage: %s ' "${0##*/}" + print 'Find packages that depend on a given depname.' + echo + prose 'Run this script from the top-level directory of your ABS tree.' +} if [[ -z $match ]]; then - echo 'Usage: finddeps ' - echo '' - echo 'Find packages that depend on a given depname.' - echo 'Run this script from the top-level directory of your ABS tree.' - echo '' + usage >&2 exit 1 fi +if [[ $match = '-h' ]]; then + usage + exit 0 +fi find . -type d | while read d; do if [[ -f "$d/PKGBUILD" ]]; then diff --git a/lddd.in b/lddd.in index f01ebf9..09e0d07 100644 --- a/lddd.in +++ b/lddd.in @@ -4,7 +4,23 @@ # # License: Unspecified -m4_include(lib/common.sh) +. "$(librelib messages)" + +usage() { + print "Usage: %s [-h]" "${0##*/}" + print "Find broken library links on your machine." + echo + prose 'Scans $PATH and library directories for ELF files with + references to missing shared libraries.' +} + +if [[ $1 = '-h' ]]; then + usage + exit 0 +elif [[ $# -gt 0 ]]; then + usage >&2 + exit 1 +fi ifs=$IFS IFS="${IFS}:" -- cgit v1.2.3-70-g09d2 From 2e2bebf2e674b8ab0003aafa0c27477fbadcd96e Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 18:50:04 -0500 Subject: lib/common.sh: Discourage use in favor of libremessages. --- lib/common.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/common.sh b/lib/common.sh index 89cd257..b8bab9b 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -1,6 +1,9 @@ #!/hint/bash # This may be included with or without `set -euE` +# This file is included by libremessages. +# You should probably use libremessages instead of this. + # License: Unspecified [[ -z ${_INCLUDE_COMMON_SH:-} ]] || return 0 -- cgit v1.2.3-70-g09d2 From f7a12367bf457ec3591fab1927e41de07d7c2d84 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 15 Feb 2017 18:50:27 -0500 Subject: mkarchroot: Use librelib rather than PATH to find arch-nspawn. --- mkarchroot.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkarchroot.in b/mkarchroot.in index 4ebafa6..f86ae35 100644 --- a/mkarchroot.in +++ b/mkarchroot.in @@ -95,7 +95,7 @@ echo "$CHROOT_VERSION" > "$working_dir/.arch-chroot" systemd-machine-id-setup --root="$working_dir" -exec arch-nspawn \ +exec "$(librelib chroot/arch-nspawn)" \ ${nosetarch:+-s} \ ${pac_conf:+-C "$pac_conf"} \ ${makepkg_conf:+-M "$makepkg_conf"} \ -- cgit v1.2.3-70-g09d2 From 687b00c814ce84321f7972504d1da574bf4e6e2c Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 19 Feb 2017 16:27:55 -0500 Subject: makechrootpkg: re-indent --- makechrootpkg.in | 276 +++++++++++++++++++++++++++---------------------------- 1 file changed, 138 insertions(+), 138 deletions(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index 35a1286..5c2086e 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -15,26 +15,26 @@ m4_include(lib/common.sh) shopt -s nullglob init_variables() { -default_makepkg_args=(-s --noconfirm -L --holdver) -makepkg_args=("${default_makepkg_args[@]}") -repack=false -update_first=false -clean_first=false -install_pkg= -run_namcap=false -temp_chroot=false -chrootdir= -passeddir= -declare -a install_pkgs -declare -i ret=0 - -bindmounts_ro=() -bindmounts_rw=() - -copy=$USER -[[ -n ${SUDO_USER:-} ]] && copy=$SUDO_USER -[[ -z "$copy" || $copy = root ]] && copy=copy -src_owner=${SUDO_USER:-$USER} + default_makepkg_args=(-s --noconfirm -L --holdver) + makepkg_args=("${default_makepkg_args[@]}") + repack=false + update_first=false + clean_first=false + install_pkg= + run_namcap=false + temp_chroot=false + chrootdir= + passeddir= + declare -a install_pkgs + declare -i ret=0 + + bindmounts_ro=() + bindmounts_rw=() + + copy=$USER + [[ -n ${SUDO_USER:-} ]] && copy=$SUDO_USER + [[ -z "$copy" || $copy = root ]] && copy=copy + src_owner=${SUDO_USER:-$USER} } usage() { @@ -166,27 +166,27 @@ sync_chroot() { # Detect chrootdir filesystem type local chroottype=$(stat -f -c %T "$chrootdir") - # Get a read lock on the root chroot to make - # sure we don't clone a half-updated chroot - slock 8 "$chrootdir/root.lock" \ - "Locking clean chroot [%s]" "$chrootdir/root" - - stat_busy "Synchronizing chroot copy [%s] -> [%s]" "$chrootdir/root" "$copydir" - if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then - if [[ -d $copydir ]]; then - btrfs_subvolume_delete "$copydir" >/dev/null || - die "Unable to delete subvolume %s" "$copydir" - fi - btrfs subvolume snapshot "$chrootdir/root" "$copydir" >/dev/null || - die "Unable to create subvolume %s" "$copydir" - else - mkdir -p "$copydir" - rsync -a --delete -q -W -x "$chrootdir/root/" "$copydir" + # Get a read lock on the root chroot to make + # sure we don't clone a half-updated chroot + slock 8 "$chrootdir/root.lock" \ + "Locking clean chroot [%s]" "$chrootdir/root" + + stat_busy "Synchronizing chroot copy [%s] -> [%s]" "$chrootdir/root" "$copydir" + if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then + if [[ -d $copydir ]]; then + btrfs_subvolume_delete "$copydir" >/dev/null || + die "Unable to delete subvolume %s" "$copydir" fi - stat_done + btrfs subvolume snapshot "$chrootdir/root" "$copydir" >/dev/null || + die "Unable to create subvolume %s" "$copydir" + else + mkdir -p "$copydir" + rsync -a --delete -q -W -x "$chrootdir/root/" "$copydir" + fi + stat_done - # Drop the read lock again - lock_close 8 + # Drop the read lock again + lock_close 8 # Update mtime touch "$copydir" @@ -459,120 +459,120 @@ move_products() { # }}} main() { -init_variables - -orig_argv=("$@") - -while getopts 'hcur:I:l:nTD:d:' arg; do - case "$arg" in - c) clean_first=true ;; - D) bindmounts_ro+=(--bind-ro="$OPTARG") ;; - d) bindmounts_rw+=(--bind="$OPTARG") ;; - u) update_first=true ;; - r) passeddir="$OPTARG" ;; - I) install_pkgs+=("$OPTARG") ;; - l) copy="$OPTARG" ;; - n) run_namcap=true; makepkg_args+=(-i) ;; - T) temp_chroot=true; copy+="-$$" ;; - h|*) usage ;; - esac -done + init_variables + + orig_argv=("$@") + + while getopts 'hcur:I:l:nTD:d:' arg; do + case "$arg" in + c) clean_first=true ;; + D) bindmounts_ro+=(--bind-ro="$OPTARG") ;; + d) bindmounts_rw+=(--bind="$OPTARG") ;; + u) update_first=true ;; + r) passeddir="$OPTARG" ;; + I) install_pkgs+=("$OPTARG") ;; + l) copy="$OPTARG" ;; + n) run_namcap=true; makepkg_args+=(-i) ;; + T) temp_chroot=true; copy+="-$$" ;; + h|*) usage ;; + esac + done + + [[ ! -f PKGBUILD && -z "${install_pkgs[*]}" ]] && die 'This must be run in a directory containing a PKGBUILD.' + + check_root "$0" "${orig_argv[@]}" -[[ ! -f PKGBUILD && -z "${install_pkgs[*]}" ]] && die 'This must be run in a directory containing a PKGBUILD.' + # Canonicalize chrootdir, getting rid of trailing / + chrootdir=$(readlink -e "$passeddir") + [[ ! -d $chrootdir ]] && die "No chroot dir defined, or invalid path '%s'" "$passeddir" + [[ ! -d $chrootdir/root ]] && die "Missing chroot dir root directory. Try using: mkarchroot %s/root base-devel" "$chrootdir" -check_root "$0" "${orig_argv[@]}" + # Detect chrootdir filesystem type + chroottype=$(stat -f -c %T "$chrootdir") + + if [[ ${copy:0:1} = / ]]; then + copydir=$copy + else + copydir="$chrootdir/$copy" + fi -# Canonicalize chrootdir, getting rid of trailing / -chrootdir=$(readlink -e "$passeddir") -[[ ! -d $chrootdir ]] && die "No chroot dir defined, or invalid path '%s'" "$passeddir" -[[ ! -d $chrootdir/root ]] && die "Missing chroot dir root directory. Try using: mkarchroot %s/root base-devel" "$chrootdir" + # Pass all arguments after -- right to makepkg + makepkg_args+=("${@:$OPTIND}") + + # See if -R was passed to makepkg + for arg in "${@:OPTIND}"; do + case ${arg%%=*} in + -*R*|--repackage) + repack=true + break 2 + ;; + esac + done -# Detect chrootdir filesystem type -chroottype=$(stat -f -c %T "$chrootdir") + if [[ -n $SUDO_USER ]]; then + eval "USER_HOME=~$SUDO_USER" + else + USER_HOME=$HOME + fi -if [[ ${copy:0:1} = / ]]; then - copydir=$copy -else - copydir="$chrootdir/$copy" -fi + umask 0022 -# Pass all arguments after -- right to makepkg -makepkg_args+=("${@:$OPTIND}") + load_vars "$USER_HOME/.makepkg.conf" + load_vars /etc/makepkg.conf -# See if -R was passed to makepkg -for arg in "${@:OPTIND}"; do - case ${arg%%=*} in - -*R*|--repackage) - repack=true - break 2 - ;; - esac -done + # Use PKGBUILD directory if these don't exist + [[ -d $PKGDEST ]] || PKGDEST=$PWD + [[ -d $SRCDEST ]] || SRCDEST=$PWD + [[ -d $SRCPKGDEST ]] || SRCPKGDEST=$PWD + [[ -d $LOGDEST ]] || LOGDEST=$PWD -if [[ -n $SUDO_USER ]]; then - eval "USER_HOME=~$SUDO_USER" -else - USER_HOME=$HOME -fi + # Lock the chroot we want to use. We'll keep this lock until we exit. + lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy" -umask 0022 + if [[ ! -d $copydir ]] || $clean_first; then + sync_chroot "$chrootdir" "$copy" + fi -load_vars "$USER_HOME/.makepkg.conf" -load_vars /etc/makepkg.conf + $update_first && arch-nspawn "$copydir" \ + "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ + pacman -Syu --noconfirm -# Use PKGBUILD directory if these don't exist -[[ -d $PKGDEST ]] || PKGDEST=$PWD -[[ -d $SRCDEST ]] || SRCDEST=$PWD -[[ -d $SRCPKGDEST ]] || SRCPKGDEST=$PWD -[[ -d $LOGDEST ]] || LOGDEST=$PWD + if [[ -n ${install_pkgs[*]:-} ]]; then + install_packages "$copydir" "${install_pkgs[@]}" + ret=$? + # If there is no PKGBUILD we have done + [[ -f PKGBUILD ]] || exit $ret + fi -# Lock the chroot we want to use. We'll keep this lock until we exit. -lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy" + download_sources "$copydir" "$src_owner" -if [[ ! -d $copydir ]] || $clean_first; then - sync_chroot "$chrootdir" "$copy" -fi + prepare_chroot "$copydir" "$USER_HOME" "$repack" -$update_first && arch-nspawn "$copydir" \ + if arch-nspawn "$copydir" \ + --bind-ro="$PWD:/startdir_host" \ + --bind-ro="$SRCDEST:/srcdest_host" \ + "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ + /chrootprepare "${makepkg_args[@]}" && + arch-nspawn "$copydir" \ + --bind-ro="$PWD:/startdir_host" \ + --bind-ro="$SRCDEST:/srcdest_host" \ "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ - pacman -Syu --noconfirm - -if [[ -n ${install_pkgs[*]:-} ]]; then - install_packages "$copydir" "${install_pkgs[@]}" - ret=$? - # If there is no PKGBUILD we have done - [[ -f PKGBUILD ]] || exit $ret -fi - -download_sources "$copydir" "$src_owner" - -prepare_chroot "$copydir" "$USER_HOME" "$repack" - -if arch-nspawn "$copydir" \ - --bind-ro="$PWD:/startdir_host" \ - --bind-ro="$SRCDEST:/srcdest_host" \ - "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ - /chrootprepare "${makepkg_args[@]}" && - arch-nspawn "$copydir" \ - --bind-ro="$PWD:/startdir_host" \ - --bind-ro="$SRCDEST:/srcdest_host" \ - "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ - /chrootbuild "${makepkg_args[@]}" -then - move_products "$copydir" "$src_owner" -else - (( ret += 1 )) -fi - -$temp_chroot && delete_chroot "$copydir" - -if (( ret != 0 )); then - if $temp_chroot; then - die "Build failed" + /chrootbuild "${makepkg_args[@]}" + then + move_products "$copydir" "$src_owner" + else + (( ret += 1 )) + fi + + $temp_chroot && delete_chroot "$copydir" + + if (( ret != 0 )); then + if $temp_chroot; then + die "Build failed" + else + die "Build failed, check %s/build" "$copydir" + fi else - die "Build failed, check %s/build" "$copydir" + true fi -else - true -fi } -- cgit v1.2.3-70-g09d2 From 24e24de8a5a81442128a056f9f75881c06cb4b05 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 19 Feb 2017 16:29:02 -0500 Subject: makechrootpkg: tidy --- makechrootpkg.in | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/makechrootpkg.in b/makechrootpkg.in index 5c2086e..463d28b 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -348,6 +348,7 @@ EOF # Usage: download_sources $copydir $src_owner # Globals: # - SRCDEST +# - USER download_sources() { local copydir=$1 local src_owner=$2 @@ -487,9 +488,6 @@ main() { [[ ! -d $chrootdir ]] && die "No chroot dir defined, or invalid path '%s'" "$passeddir" [[ ! -d $chrootdir/root ]] && die "Missing chroot dir root directory. Try using: mkarchroot %s/root base-devel" "$chrootdir" - # Detect chrootdir filesystem type - chroottype=$(stat -f -c %T "$chrootdir") - if [[ ${copy:0:1} = / ]]; then copydir=$copy else @@ -541,7 +539,7 @@ main() { install_packages "$copydir" "${install_pkgs[@]}" ret=$? # If there is no PKGBUILD we have done - [[ -f PKGBUILD ]] || exit $ret + [[ -f PKGBUILD ]] || return $ret fi download_sources "$copydir" "$src_owner" -- cgit v1.2.3-70-g09d2 From d0a8e61719b35f3f7d25a515bafc11729e41a41c Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 19 Feb 2017 16:29:15 -0500 Subject: makechrootpkg: re-add "main" call --- makechrootpkg.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/makechrootpkg.in b/makechrootpkg.in index 463d28b..7ff2fd7 100644 --- a/makechrootpkg.in +++ b/makechrootpkg.in @@ -574,3 +574,5 @@ main() { true fi } + +main "$@" -- cgit v1.2.3-70-g09d2 From 64a5849178787af70a2ac1b583d5f2a6b72d983b Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 19 Feb 2017 16:29:43 -0500 Subject: lib/common.sh: simplify include-guard --- lib/common.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/common.sh b/lib/common.sh index bb46f6c..9ea9681 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -6,9 +6,7 @@ # License: Unspecified -shopt -s extglob - -if [[ -z ${_INCLUDE_COMMON_SH:-} ]]; then +[[ -z ${_INCLUDE_COMMON_SH:-} ]] || return 0 _INCLUDE_COMMON_SH=true [[ -n ${TEXTDOMAIN:-} ]] || export TEXTDOMAIN='libretools' @@ -295,5 +293,3 @@ check_root() { exec su root -c "$(printf ' %q' "$@")" fi } - -fi -- cgit v1.2.3-70-g09d2 From 7c55e79a64fcf46d0ee5329953dc83768e0cd1db Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 19 Feb 2017 16:29:56 -0500 Subject: lib/common.sh: Tidy formatting. --- lib/common.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/common.sh b/lib/common.sh index 9ea9681..b8bab9b 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -161,8 +161,7 @@ get_full_version() { ## # usage : lock( $fd, $file, $message, [ $message_arguments... ] ) ## -lock() -{ +lock() { local fd=$1 local file=$2 local mesg=("${@:3}") @@ -183,8 +182,7 @@ lock() ## # usage : slock( $fd, $file, $message, [ $message_arguments... ] ) ## -slock() -{ +slock() { local fd=$1 local file=$2 local mesg=("${@:3}") -- cgit v1.2.3-70-g09d2