From patchwork Tue Nov 5 23:38:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via arch-projects X-Patchwork-Id: 1345 Return-Path: Delivered-To: patchwork@archlinux.org Received: from apollo.archlinux.org (localhost [127.0.0.1]) by apollo.archlinux.org (Postfix) with ESMTP id E5DEF14ED03D6 for ; Tue, 5 Nov 2019 23:39:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on apollo X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1, LOCAL_FAKEBUSINESS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,T_DMARC_POLICY_NONE=0.01 autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-BL-Results: [127.0.9.2] Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Tue, 5 Nov 2019 23:39:40 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 1F426166625E36; Tue, 5 Nov 2019 23:39:21 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [5.9.250.164]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: luna) by orion.archlinux.org (Postfix) with ESMTPSA id 5D8DD166625E08; Tue, 5 Nov 2019 23:39:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1572997158; bh=lBuJv2C+uGZKrA6iab+hDwpZ2EuynjMJ9J9z+WBvACs=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc; b=yAFTL9kfPvpWByfs1r6wbYdIei0tQ9JDM/BLHU24lf0wdMmmhPQrhXamyYvqU9YEG m8whzoc+ZOG0uzx5DmjA48RMt21Se54cv4ZJ+BHvGoIZquut29TP99kgvu5q1bz65g 54eUXgAi26nmdOHDUpDAr4VYAIwjHJQjhi1tKhqW/bfQvI+N2D4Wn698fYVPmg9hOg WegukZWtHwaMXThqjLIK3FBflkR/su0f+bEYeP/nGt/NQ+1Lnt8a5N85yp38OG6U7z 45moxg+43qgV3K/0uRNtMdOpyzDzPDfnRzeX8uSv1/uCAe/Ovq+XuSb/+1D6hqbqQs sPEczQVC86s/3ir1PcM4tFOpUHSP3mAJiuUp3zBdHrhQvRya4km7V42dY0wbPb/dH0 sF+bupj7hdCAqTCLQz5J/3OcQ1TWm3w/awzXIdfHl/kQPfsjORLLCj+L2fCUFImK3N TZVr7cBO+3UGTyttJ6kdvRxvDzY1OE4jqS5r99LYgjitDa9a0Em6RuZSlWle05o6BZ vGTLpoo71VqmK858sAcnhH2VhZfM2uvM+sLRVWYTgBhaOU0zCNaYrUPcjj3WBz9L77 61c3PDGt8qk13fclNZawHVGi0kTSJfAqxPM5i9jIYYL/wKmJ0UPqvIE7uAgzpOa5t5 4Aoh+Cb3JFh8ZxG3FIpa8vyo= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 3C99F20774; Tue, 5 Nov 2019 23:39:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=luna2; t=1572997158; bh=lBuJv2C+uGZKrA6iab+hDwpZ2EuynjMJ9J9z+WBvACs=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc; b=Hkylg+ioNDYMRIX2SvjlIN8URiYCXp58clO45uI4X6o+Y1BDYbIDEXFUb126zOzKF 5z03WojllixkVH6s9ZKbYFHHlIyPLvaOYzQ7sOVhE8chOF6/yXncm8lY9J3RRP2+6M r2jyf1UzA03tiT0MA7+0O0E4QR+oGAo4NT5ZPqC3tm6SqlrYwEXTSwGy77Rso1ocQi jGZZwSFdOpesgZaS6idysht3kcqYhO0UWtqFPXGlAtJ4Uew+ONu9UvJVxIpBIvs6M1 Z9N1If3izhRyJfQyafOvy6ENibVfN4M3dkXc0wIAVz/owokGlttOn+BpM+8xSMtuTv UFXe0NjawSndbRji38aW/+7obazpPKyvOjnn6AUgyfNBFQmujLnWd18Lnnoqtqt+EX Pnet104NwJIfjmx63WOZdUvBMHPpSoquE+hkM2oEtIlpxZU+ECB+KDEAhI7FzBG1Ee t8UGU2tV1t/9mxNlZ42tlaIA1cQFjtoP7TIQ8fIW5AcQ+WRRgRrMw4YY1XTsy++WDw wUzTS/hguUMGnyyFioi+hIbyAvC33fBZW2AR+772xAtQbJovYLR0IZ9wQxWBomP5QB Ax5nugIasTl1ZRfmgam2YLIvwvA1ILKfE2YR+hvQFL0n3QyI9OuAJrebeyu0rejPhD hSIuuJXlFV/NExZq461o24Ao= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 7922220774 for ; Tue, 5 Nov 2019 23:39:15 +0000 (UTC) Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by luna.archlinux.org (Postfix) with ESMTPS for ; Tue, 5 Nov 2019 23:39:15 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 350C3166625DE2; Tue, 5 Nov 2019 23:39:10 +0000 (UTC) Received: from didactylos.attlocal.net (unknown [IPv6:2600:1700:57f0:ca20:763a:c795:fcf6:91ea]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: eschwartz) by orion.archlinux.org (Postfix) with ESMTPSA id A9247166625DE1; Tue, 5 Nov 2019 23:39:09 +0000 (UTC) To: arch-projects@archlinux.org Date: Tue, 5 Nov 2019 18:38:50 -0500 Message-Id: <20191105233853.1842304-1-eschwartz@archlinux.org> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 Subject: [arch-projects] [devtools] [PATCH 1/4] arch-nspawn: simplify cachedir/host_mirror parsing X-BeenThere: arch-projects@archlinux.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Arch Linux projects development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Eli Schwartz via arch-projects Reply-To: Arch Linux projects development discussion Cc: Eli Schwartz Errors-To: arch-projects-bounces@archlinux.org Sender: "arch-projects" consolidate logic flows in the same area for parsing and building arrays. Don't bother having a special function just to build the mount_args array, since we now use the same handling for adding any cachedir (including host mirrors) to the mount arguments, this becomes a trivial for loop -- and it really did not need to be delayed until after the sanity check, anyway. Signed-off-by: Eli Schwartz --- arch-nspawn.in | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/arch-nspawn.in b/arch-nspawn.in index 90fe967..7aa6fd6 100644 --- a/arch-nspawn.in +++ b/arch-nspawn.in @@ -20,6 +20,7 @@ umask 0022 working_dir='' files=() +mount_args=() usage() { echo "Usage: ${0##*/} [options] working-dir [systemd-nspawn arguments]" @@ -65,6 +66,13 @@ fi # shellcheck disable=2016 host_mirrors=($($pacconf_cmd --repo extra Server 2> /dev/null | sed -r 's#(.*/)extra/os/.*#\1$repo/os/$arch#')) +for host_mirror in "${host_mirrors[@]}"; do + if [[ $host_mirror == *file://* ]]; then + host_mirror=$(echo "$host_mirror" | sed -r 's#file://(/.*)/\$repo/os/\$arch#\1#g') + in_array "$host_mirror" "${cache_dirs[@]}" || cache_dirs+=("$host_mirror") + fi +done + while read -r line; do mapfile -t lines < <($pacconf_cmd --config "${pac_conf:-$working_dir/etc/pacman.conf}" \ --repo $line Server | sed -r 's#(.*/)[^/]+/os/.+#\1$repo/os/$arch#') @@ -78,35 +86,18 @@ while read -r line; do fi done < <($pacconf_cmd --config "${pac_conf:-$working_dir/etc/pacman.conf}" --repo-list) -# {{{ functions -build_mount_args() { - declare -g mount_args=() - - for host_mirror in "${host_mirrors[@]}"; do - if [[ $host_mirror == *file://* ]]; then - host_mirror_path=$(echo "$host_mirror" | sed -r 's#file://(/.*)/\$repo/os/\$arch#\1#g') - mount_args+=("--bind-ro=${host_mirror_path//:/\\:}") - fi - done - - mount_args+=("--bind=${cache_dirs[0]//:/\\:}") +mount_args+=("--bind=${cache_dirs[0]//:/\\:}") - for cache_dir in "${cache_dirs[@]:1}"; do - mount_args+=("--bind-ro=${cache_dir//:/\\:}") - done -} +for cache_dir in "${cache_dirs[@]:1}"; do + mount_args+=("--bind-ro=${cache_dir//:/\\:}") +done +# {{{ functions copy_hostconf () { unshare --fork --pid gpg --homedir "$working_dir"/etc/pacman.d/gnupg/ --no-permission-warning --quiet --batch --import --import-options import-local-sigs "$(pacman-conf GpgDir)"/pubring.gpg >/dev/null 2>&1 pacman-key --gpgdir "$working_dir"/etc/pacman.d/gnupg/ --import-trustdb "$(pacman-conf GpgDir)" >/dev/null 2>&1 printf 'Server = %s\n' "${host_mirrors[@]}" >"$working_dir/etc/pacman.d/mirrorlist" - for host_mirror in "${host_mirrors[@]}"; do - if [[ $host_mirror == *file://* ]]; then - host_mirror=$(echo "$host_mirror" | sed -r 's#file://(/.*)/\$repo/os/\$arch#\1#g') - in_array "$host_mirror" "${cache_dirs[@]}" || cache_dirs+=("$host_mirror") - fi - done [[ -n $pac_conf ]] && cp "$pac_conf" "$working_dir/etc/pacman.conf" [[ -n $makepkg_conf ]] && cp "$makepkg_conf" "$working_dir/etc/makepkg.conf" @@ -130,7 +121,6 @@ elif [[ $(cat "$working_dir/.arch-chroot") != "$CHROOT_VERSION" ]]; then die "chroot '%s' is not at version %s. Please rebuild." "$working_dir" "$CHROOT_VERSION" fi -build_mount_args copy_hostconf eval "$(grep -a '^CARCH=' "$working_dir/etc/makepkg.conf")"