[arch-projects] [devtools] [PATCH 1/2] arch-nspawn: avoid escaping mount_args
eval is no longer involved in the execution of systemd-nspawn, so we no longer need a layer of escaping on the arguments. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- arch-nspawn.in | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index a05ca1c..6c6f1e3 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -56,20 +56,16 @@ host_mirror=$(pacman -Sddp extra/devtools 2>/dev/null | sed -r 's#(.*/)extra/os/ # {{{ functions build_mount_args() { - local p declare -g mount_args=() if [[ -n $host_mirror_path ]]; then - printf -v p '%q' "$host_mirror_path" - mount_args+=(--bind-ro="$p") + mount_args+=(--bind-ro="$host_mirror_path") fi - printf -v p '%q' "${cache_dirs[0]}" - mount_args+=(--bind="$p") + mount_args+=(--bind="${cache_dirs[0]}") for cache_dir in ${cache_dirs[@]:1}; do - printf -v p '%q' "$cache_dir" - mount_args+=(--bind-ro="$p") + mount_args+=(--bind-ro="$cache_dir") done } -- 1.8.3.4
This fixes various errors one might encounter when trying to use a build root or cachedir with whitespace in it. Note that the cachedir fix is not a complete one, as pacman's output is unreliable (and not meant for parsing here). Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- arch-nspawn.in | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index 6c6f1e3..6900382 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -40,15 +40,15 @@ shift $(($OPTIND - 1)) (( $EUID != 0 )) && die 'This script must be run as root.' (( $# < 1 )) && die 'You must specify a directory.' -working_dir="$(readlink -f $1)" +working_dir=$(readlink -f "$1") shift 1 [[ -z $working_dir ]] && die 'Please specify a working directory.' if [[ -z $cache_dir ]]; then - cache_dirs=($(pacman -v $cache_conf 2>&1 | grep '^Cache Dirs:' | sed 's/Cache Dirs:\s*//g')) + cache_dirs=($(pacman -v 2>&1 | grep '^Cache Dirs:' | sed 's/Cache Dirs:\s*//g')) else - cache_dirs=(${cache_dir}) + cache_dirs=("$cache_dir") fi host_mirror=$(pacman -Sddp extra/devtools 2>/dev/null | sed -r 's#(.*/)extra/os/.*#\1$repo/os/$arch#') @@ -71,12 +71,12 @@ build_mount_args() { copy_hostconf () { cp -a /etc/pacman.d/gnupg "$working_dir/etc/pacman.d" - echo "Server = $host_mirror" > $working_dir/etc/pacman.d/mirrorlist + echo "Server = $host_mirror" >"$working_dir/etc/pacman.d/mirrorlist" - [[ -n $pac_conf ]] && cp $pac_conf $working_dir/etc/pacman.conf - [[ -n $makepkg_conf ]] && cp $makepkg_conf $working_dir/etc/makepkg.conf + [[ -n $pac_conf ]] && cp $pac_conf "$working_dir/etc/pacman.conf" + [[ -n $makepkg_conf ]] && cp $makepkg_conf "$working_dir/etc/makepkg.conf" - sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${cache_dirs[@]})|g" -i $working_dir/etc/pacman.conf + sed -r "s|^#?\\s*CacheDir.+|CacheDir = $(echo -n ${cache_dirs[@]})|g" -i "$working_dir/etc/pacman.conf" } # }}} @@ -94,7 +94,7 @@ copy_hostconf eval $(grep '^CARCH=' "$working_dir/etc/makepkg.conf") -machine_name="${working_dir//\//-}" +machine_name="${working_dir//[![:alnum:]_-]/-}" machine_name="${machine_name#-}" exec ${CARCH:+setarch "$CARCH"} systemd-nspawn 2>/dev/null \ -- 1.8.3.4
Am 10.08.2013 03:33, schrieb Dave Reisner:
This fixes various errors one might encounter when trying to use a build root or cachedir with whitespace in it.
Note that the cachedir fix is not a complete one, as pacman's output is unreliable (and not meant for parsing here).
What do you mean by unreliable? And well, it would be best if pacman would provide some kind of CLI API to get these kind of config options. We do a similar hack to get the users mirror for example. -- Pierre Schmitz, https://pierre-schmitz.com
On Aug 10, 2013 1:29 PM, "Pierre Schmitz" <pierre@archlinux.de> wrote:
Am 10.08.2013 03:33, schrieb Dave Reisner:
This fixes various errors one might encounter when trying to use a build root or cachedir with whitespace in it.
Note that the cachedir fix is not a complete one, as pacman's output is unreliable (and not meant for parsing here).
What do you mean by unreliable? And well, it would be best if pacman would provide some kind of CLI API to get these kind of config options. We do a similar hack to get the users mirror for example.
The cache dir listing in pacman's output delimits with whitespace, so you're sort of boned if you have a cache dir with whitespace in it. Yeah, there needs to be a better way...
-- Pierre Schmitz, https://pierre-schmitz.com
participants (3)
-
Dave Reisner
-
Dave Reisner
-
Pierre Schmitz