From 2b62ac660d258858f7a7795a113a7056d0d2c79d Mon Sep 17 00:00:00 2001 From: "Frédéric Pierret (fepitre)" Date: Sun, 4 Feb 2024 12:03:50 +0100 Subject: feat(mkarchroot): allow to specify file destination inside chroot Co-authored-by: Christian Heusel --- contrib/completion/bash/devtools.in | 2 ++ contrib/completion/zsh/_devtools.in | 1 + doc/man/arch-nspawn.1.asciidoc | 5 +++-- doc/man/mkarchroot.1.asciidoc | 3 ++- src/arch-nspawn.in | 19 +++++++++++-------- src/mkarchroot.in | 21 ++++++++++++--------- 6 files changed, 31 insertions(+), 20 deletions(-) diff --git a/contrib/completion/bash/devtools.in b/contrib/completion/bash/devtools.in index 136beef..4073efe 100644 --- a/contrib/completion/bash/devtools.in +++ b/contrib/completion/bash/devtools.in @@ -61,12 +61,14 @@ _mkarchroot_args=( -C -M -c + -f -h ) _mkarchroot_args_U_opts() { _filedir '*.pkg.tar.*'; } _mkarchroot_args_C_opts() { _filedir '*.conf'; } _mkarchroot_args_M_opts() { _filedir '*.conf'; } _mkarchroot_args_c_opts() { _filedir -d; } +_mkarchroot_args_f_opts() { _filedir -d; } _mkarchroot_opts() { local args args=$(__pkgctl_word_count_after_subcommand) diff --git a/contrib/completion/zsh/_devtools.in b/contrib/completion/zsh/_devtools.in index 65d7895..d38733f 100644 --- a/contrib/completion/zsh/_devtools.in +++ b/contrib/completion/zsh/_devtools.in @@ -237,6 +237,7 @@ _mkarchroot_args=( '-C[Location of a pacman config file]:pacman_config:_files -g "*.conf(.)"' '-M[Location of a makepkg config file]:makepkg_config:_files -g "*.conf(.)"' '-c[Set pacman cache]:pacman_cache:_files -/' + '-f[Copy src file from the host to the chroot]:target:_files -/' '-h[Display usage]' '1:working_dir:_files -/' '*:packages:_devtools_completions_all_packages' diff --git a/doc/man/arch-nspawn.1.asciidoc b/doc/man/arch-nspawn.1.asciidoc index a3e8ec1..ae6532b 100644 --- a/doc/man/arch-nspawn.1.asciidoc +++ b/doc/man/arch-nspawn.1.asciidoc @@ -28,8 +28,9 @@ Options *-c* :: Set pacman cache, if no directory is specified the passed pacman.conf's cachedir is used with a fallback to '/etc/pacman.conf' -*-f* :: - Copy file from the host to the chroot +*-f* [:]:: + Copy file from the host to the chroot. + If 'dst' is not provided, it defaults to 'src' inside of the chroot. *-s*:: Do not run setarch diff --git a/doc/man/mkarchroot.1.asciidoc b/doc/man/mkarchroot.1.asciidoc index 99905c8..edbb17e 100644 --- a/doc/man/mkarchroot.1.asciidoc +++ b/doc/man/mkarchroot.1.asciidoc @@ -32,8 +32,9 @@ Options *-c* :: Set pacman cache. -*-f* :: +*-f* [:]:: Copy file from the host to the chroot. + If 'dst' is not provided, it defaults to 'src' inside of the chroot. *-s*:: Do not run setarch. diff --git a/src/arch-nspawn.in b/src/arch-nspawn.in index a4504a1..bd99adc 100644 --- a/src/arch-nspawn.in +++ b/src/arch-nspawn.in @@ -22,12 +22,13 @@ usage() { echo "A wrapper around systemd-nspawn. Provides support for pacman." echo 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' + echo ' -C Location of a pacman config file' + echo ' -M Location of a makepkg config file' + echo ' -c Set pacman cache' + echo ' -f [:] Copy src file from the host to the chroot.' + echo ' If dst file is not provided, it defaults to src' + echo ' -s Do not run setarch' + echo ' -h This message' exit 1 } @@ -114,8 +115,10 @@ copy_hostconf () { local file for file in "${files[@]}"; do - mkdir -p "$(dirname "$working_dir$file")" - cp -T "$file" "$working_dir$file" + src="${file%%:*}" + dst="${file#*:}" + mkdir -p "$(dirname "$working_dir$dst")" + cp -T "$src" "$working_dir$dst" done sed -r "s|^#?\\s*CacheDir.+|CacheDir = ${cache_dirs[*]}|g" -i "$working_dir/etc/pacman.conf" diff --git a/src/mkarchroot.in b/src/mkarchroot.in index fc60b4e..06cf5d2 100644 --- a/src/mkarchroot.in +++ b/src/mkarchroot.in @@ -22,13 +22,14 @@ nspawn_args=() usage() { echo "Usage: ${0##*/} [options] working-dir package-list..." echo ' options:' - echo ' -U Use pacman -U to install packages' - 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' + echo ' -U Use pacman -U to install packages' + echo ' -C Location of a pacman config file' + echo ' -M Location of a makepkg config file' + echo ' -c Set pacman cache' + echo ' -f [:] Copy src file from the host to the chroot.' + echo ' If dst file is not provided, it defaults to src' + echo ' -s Do not run setarch' + echo ' -h This message' exit 1 } @@ -84,8 +85,10 @@ if is_btrfs "$working_dir"; then fi for file in "${files[@]}"; do - mkdir -p "$(dirname "$working_dir$file")" - cp "$file" "$working_dir$file" + src="${file%%:*}" + dst="${file#*:}" + mkdir -p "$(dirname "$working_dir$dst")" + cp "$src" "$working_dir$dst" done unshare --mount pacstrap -${umode}Mc ${pac_conf:+-C "$pac_conf"} "$working_dir" \ -- cgit v1.2.3-70-g09d2