From patchwork Tue Nov 5 23:40:45 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: 1348 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 4AE6F14ED05DA for ; Tue, 5 Nov 2019 23:41:24 +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:41:24 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id D2CD216662C606; Tue, 5 Nov 2019 23:41:12 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (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 61BB216662C5DC; Tue, 5 Nov 2019 23:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1572997270; bh=lBuJv2C+uGZKrA6iab+hDwpZ2EuynjMJ9J9z+WBvACs=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc; b=oInoQBjPI1tyNi+JJR5XHJFmlB3GVqMBVH1Yio1V6qAd+ReWU+7HvKh+3UoUxGg9G 4MXWXtf6c20tVon4Fj6+PuKYCkKZefid0Bed+xzQ2vRErXezIhzXFKNBB+gAI0/nlt MYQbmtw5Crh5p+vrj9Bhye2se8p2+VslExBKrVzR/2/mB+fLMIVbLTEPzU3w6IKV6G iNZKWbWp4b2SflIeSTgCmZnC3OPWpGCa6sSo6RxvqjNXuWP/sn0uoV6Aw1cCQd4V21 OnGYnY29y/JnI2gEaKoZiNyW4CqKOSeuafe4vK2Yqme2Nv1HQn5HAeA5YS/93f9Not SJWmgOYVIBDui19F0eelOInvPg0/PzEUIABRyj1b1/Zv0z2+vzSxPqUx+RRSToJuCX PQ+uXIwtk0uaoh34RLuCjIHvBOXcDIq/a8S3Gp0MqrkYCNlVXvFwFr57V5WUr1Qs4o J0qPrPLWZoO7rYuGA/mdP+Zhl8PJ1L8FyeouAoeXeFd4kvt/HmxlbCYGycBN1x5oo3 IbkjKagea6YBgYgGAJSD2Fy3oP1WcIXgwHp5Js6YxX4R1kNwounYV4mhgLAebRRtE4 MOL1krLTy29VY+Wc8HbjpISdEGAuMuETGDjj9EF7wgLoP+r021Rua8Mgr2+8VCkotM 7XUK0VRyA1ndx0mLbDw274QU= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 2AFD12077B; Tue, 5 Nov 2019 23:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=luna2; t=1572997270; bh=lBuJv2C+uGZKrA6iab+hDwpZ2EuynjMJ9J9z+WBvACs=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc; b=Dy96kwzpiOziSWrcQMJ4jHVmMxa/IMBKIzVEebU1mkf9BSiuZsDzzZ+alXOggk/ky 5YoLE4EIbpwu10HJM5xXbvsPJiImwgp2++kbrtxIiGGrvgNoYe5TBrsAYFrg0b6xti DyyYDxP89m3QQtUwOc6EaZMY2AXKXvhW8ZnJQ58KGKM7wYO1wXE6KFNVVaR/LFbehL 3Y9M1fBfSf+AKw0EGd4tC8wgbVFVsr5EHu9NvVU6OOPJinGlJi75nASPcN+Bf6PKPA +H+paxsALdLS27ecS0nTI9Uk28V1gptLV+h1jcBGUNH2/AHKAXVqf8kbzHGweyO3zz mgVBn5TqAg8/YaHRSp6awT42sG7UnQMtV8jkk3cgm25VjEpQ53ct6h4F/t68KaWS/M keJaIRw03ptPHOqrgvpRVm32sqRiACJgaJ/x4c+D6AFtxBMe2jBT7wHwTwe0H7uAWU mxQh29VDrF7OYOJ5yzxGS0dffsu6i45nnz7KeRNpmoRax74Q8GFE6DTsT8ZH1gwhNx BRMwIF31gwluo6qu0LqghRBfbaDfJd7PpvwiJLWf3M7vzL6XDPW9xkHPTbrkjNPVN0 6ubpa8OxDwEZtsJFeQCDM0smnFyXxlufZxDJuYBfeEEMKftDOLqdGtO7ZLE8kNF3ZC AZvPNcXxGrUnx702h5gwIpUY= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 670252076B for ; Tue, 5 Nov 2019 23:41:07 +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:41:07 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 8209016662C5CA; Tue, 5 Nov 2019 23:41:06 +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 E747916662C5C7; Tue, 5 Nov 2019 23:41:05 +0000 (UTC) To: arch-projects@archlinux.org Date: Tue, 5 Nov 2019 18:40:45 -0500 Message-Id: <20191105234047.1842520-2-eschwartz@archlinux.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191105234047.1842520-1-eschwartz@archlinux.org> References: <20191105234047.1842520-1-eschwartz@archlinux.org> MIME-Version: 1.0 Subject: [arch-projects] [devtools] [PATCH 2/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")"