From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id rrjFFAQgkmDrCgEAgWs5BA (envelope-from ) for ; Wed, 05 May 2021 06:33:08 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id uMzoDwQgkmBOFQAA1q6Kng (envelope-from ) for ; Wed, 05 May 2021 04:33:08 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id C44312438F for ; Wed, 5 May 2021 06:33:07 +0200 (CEST) Received: from localhost ([::1]:49088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1le9De-00082m-Vt for larch@yhetil.org; Wed, 05 May 2021 00:33:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1le9Da-000826-2G for guix-patches@gnu.org; Wed, 05 May 2021 00:33:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:45902) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1le9DZ-0002ti-QX for guix-patches@gnu.org; Wed, 05 May 2021 00:33:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1le9DZ-0006lb-O4 for guix-patches@gnu.org; Wed, 05 May 2021 00:33:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#48233] [PATCH 1/3] guix-install.sh: Please the shellcheck linter. References: <87czu5lspv.fsf@gmail.com> In-Reply-To: <87czu5lspv.fsf@gmail.com> Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 05 May 2021 04:33:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48233 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 48233@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 48233-submit@debbugs.gnu.org id=B48233.162018914725986 (code B ref 48233); Wed, 05 May 2021 04:33:01 +0000 Received: (at 48233) by debbugs.gnu.org; 5 May 2021 04:32:27 +0000 Received: from localhost ([127.0.0.1]:57442 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1le9Cv-0006l2-PG for submit@debbugs.gnu.org; Wed, 05 May 2021 00:32:27 -0400 Received: from mail-qv1-f46.google.com ([209.85.219.46]:41942) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1le9Cq-0006kg-Qz for 48233@debbugs.gnu.org; Wed, 05 May 2021 00:32:20 -0400 Received: by mail-qv1-f46.google.com with SMTP id l19so624205qvu.8 for <48233@debbugs.gnu.org>; Tue, 04 May 2021 21:32:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/S7Ka7E16PV/VR5vThVHFJ7XXACY5XQkVsoo+wY8kGQ=; b=faZmRzEcBfXxvrIEGEl7yg6xujRQq67QSi5W9mNQsUFsiXVu/nC3sZP0npvjv2kvLp V1FytLtQIdUIFw1d3LkZ2OfD/pBrFe2A1NYWNt9Lz5Ui0hI0oXEqraeYUiTLzUEsGI5/ Xa+0K4Don0F20yOTyAjQLRVvcNr/mrabEvoygnnvUdHSPSIgNtsv+qXo7qtAmimHPlZw zi3FNwRjVAj3FFt8xMfQ/SzHEwT4gU6Zh0dtndDzQLsLsIUNyR2BbCSOqb7v9ggyNLNE vapqv9/MfZHa8DILXCz7Z0HmiGsYVfzMN7g9/9yw3IvnAXN5EGd7cxGnFYn4rHFxovqc meBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/S7Ka7E16PV/VR5vThVHFJ7XXACY5XQkVsoo+wY8kGQ=; b=UyQymBr3KK4peXHrFHGqD92I4+j7A8Mcc39wI0Nrmbai5xOBjLy77qGwOAcgpC2Lp4 PM4bisjmrpbA+l5TsG4/+LIOKimSHKd24IbNonWqC/kikWhx2eH5UQzk8rZ5JY74+7Pe s6XVr8Vwk+G0SXg3iEWR8se0BHaUGyzd7s4U3iwxTqdff7LBNylJrPdBajZl9GouZYY0 rjWxbA7HPnagFqQD5YQYghnTdV7TB0ZHVsChd6zSh4o0fCrDn6zByHxT4WfXUHiOOOx0 JjZuC+4777czbDTwiiJtrNsBrJ/Imy1gEFoqxM4RlwQILBBFgKYELgSGmkY0v20qFDQV 5lcg== X-Gm-Message-State: AOAM531A34ntWpsFwMxWNlNCP8Fg5G2rSDZz/BFnwz3Wty7cbmHE3MEQ r0veZHYbY/scxsBUs8Rj1YR9fuLn/bPrZAND X-Google-Smtp-Source: ABdhPJxGA8MpmeH+3mXfuEh9QngCGK+RgfusBvUPoa/NgcT9z9AT40JAohQ08NI5rIvjw1BPWQdylA== X-Received: by 2002:a0c:9e5e:: with SMTP id z30mr29691227qve.61.1620189130884; Tue, 04 May 2021 21:32:10 -0700 (PDT) Received: from localhost.localdomain (mtl.savoirfairelinux.net. [208.88.110.46]) by smtp.gmail.com with ESMTPSA id l71sm12702122qke.27.2021.05.04.21.32.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 May 2021 21:32:10 -0700 (PDT) From: Maxim Cournoyer Date: Wed, 5 May 2021 00:32:00 -0400 Message-Id: <20210505043202.24636-1-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1620189188; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=/S7Ka7E16PV/VR5vThVHFJ7XXACY5XQkVsoo+wY8kGQ=; b=VCX/1qt79B/VWgbLCSImea2ISsdxEF6AiNBmWtC1C2EYs4r72mmYk5n3G6iIQ9reZIQW+I Sa0wk+HrAGZhyWDp/43fESoZgW95yUBs/d65/gKZQ08HYEWmKE3V5okbhJdsMq3vIfqY5q 3rvCO4DKLTUDOrUX1u63bKgrTHTTVzDaR8nHX55L7Aic2vWQGFDmHio+xUZ4FjFmDFoIGv 3fvkIe+88CY9meL74QkxRkjgS3doIIOC/iCTDeONizYBYIkg31ex5MnwH8wqgSGU8eQ2NM wrm8BVMpfEtKc95A8DUsWzO4ByBy2ZpjJvLOq+j57dGngvknE495Vc4cYaYINQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1620189188; a=rsa-sha256; cv=none; b=tHVuuShdME5QJupyRcyr1Hm3n/G8eR6OhUse/g/GAbJLtKKmKa8CDUQmjDoFP33dkhxo1U mvxR1HH4HkyGFs3u8nObnNBG1r6yy9S4foP2CIWhFaM84p0GpfBk9ZNeUfMBTLhAvBtTn3 KCMfZJx4mPtP+sqX8B4gooenCW9Se1tBlRjYFaCOURuivD3t0jopLrsdCdT0V8JuhfTjHu dvTNQeonDjzohzr6itKO/TM2rxs7jxbl1Z3l0KKpn3frRhcEdU+3dvQ3FZCPd9jPrBIvB4 73m9zraOukbHPKE3V54AEFZCet51seCJJ3uMCe7Jp6Hsa0HoAcRInEzTu+8qVA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20161025 header.b=faZmRzEc; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -1.36 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20161025 header.b=faZmRzEc; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: C44312438F X-Spam-Score: -1.36 X-Migadu-Scanner: scn0.migadu.com X-TUID: PXd3D7bkLY4Q * etc/guix-install.sh : Explicitly refer to the first item of the FUNCNAME array. (ROOT_HOME): Replace variable by ~root directly; manually expanding it via echo was not necessary. (chk_gpg_keyring): Use an if branch for the exit to avoid a warning about expression precedence. (chk_term) : Remove unused variable. (guix_get_bin) : Test the commands directly. (sys_create_store): Disable SC1090 for the source command, as we don't care about following the sourced script. <_msg>: Reuse the GUIX_PROFILE variable in the message. (sys_create_build_user) : Test the command directly. --- etc/guix-install.sh | 74 +++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 40 deletions(-) diff --git a/etc/guix-install.sh b/etc/guix-install.sh index 06a3edd1a6..11836f2c33 100755 --- a/etc/guix-install.sh +++ b/etc/guix-install.sh @@ -9,6 +9,7 @@ # Copyright © 2020 Daniel Brooks # Copyright © 2021 Jakub Kądziołka # Copyright © 2021 Chris Marusich +# Copyright © 2021 Maxim Cournoyer # # This file is part of GNU Guix. # @@ -71,11 +72,6 @@ declare -A GPG_SIGNING_KEYS GPG_SIGNING_KEYS[15145]=3CE464558A84FDC69DB40CFB090B11993D9AEBB5 # ludo GPG_SIGNING_KEYS[127547]=27D586A4F8900854329FF09F1260E46482E63562 # maxim -# This script needs to know where root's home directory is. However, we -# cannot simply use the HOME environment variable, since there is no guarantee -# that it points to root's home directory. -ROOT_HOME="$(echo ~root)" - # ------------------------------------------------------------------------------ #+UTILITIES @@ -102,7 +98,7 @@ chk_require() declare -a warn local c - _debug "--- [ $FUNCNAME ] ---" + _debug "--- [ ${FUNCNAME[0]} ] ---" for c in "$@"; do command -v "$c" &>/dev/null || warn+=("$c") @@ -117,7 +113,7 @@ chk_require() chk_gpg_keyring() { # Check whether the Guix release signing public key is present. - _debug "--- [ $FUNCNAME ] ---" + _debug "--- [ ${FUNCNAME[0]} ] ---" local user_id local gpg_key_id local exit_flag @@ -132,21 +128,19 @@ chk_gpg_keyring() exit_flag=yes fi done - test "$exit_flag" = yes && exit 1 || true + if [ "$exit_flag" = yes ]; then + exit 1 + fi } chk_term() { # Check for ANSI terminal for color printing. - local ansi_term - if [ -t 2 ]; then if [ "${TERM+set}" = 'set' ]; then case "$TERM" in xterm*|rxvt*|urxvt*|linux*|vt*|eterm*|screen*) - ansi_term=true ;; *) - ansi_term=false ERR="[ FAIL ] " PAS="[ PASS ] " ;; @@ -243,7 +237,7 @@ guix_get_bin_list() local latest_ver local default_ver - _debug "--- [ $FUNCNAME ] ---" + _debug "--- [ ${FUNCNAME[0]} ] ---" # Filter only version and architecture bin_ver_ls=("$(wget -qO- "$gnu_url" \ @@ -273,24 +267,23 @@ guix_get_bin() local bin_ver="$2" local dl_path="$3" - _debug "--- [ $FUNCNAME ] ---" + _debug "--- [ ${FUNCNAME[0]} ] ---" _msg "${INF}Downloading Guix release archive" wget --help | grep -q '\--show-progress' && \ _PROGRESS_OPT="-q --show-progress" || _PROGRESS_OPT="" - wget $_PROGRESS_OPT -P "$dl_path" "${url}/${bin_ver}.tar.xz" "${url}/${bin_ver}.tar.xz.sig" - if [[ "$?" -eq 0 ]]; then - _msg "${PAS}download completed." + if wget "$_PROGRESS_OPT" -P "$dl_path" \ + "${url}/${bin_ver}.tar.xz" "${url}/${bin_ver}.tar.xz.sig"; then + _msg "${PAS}download completed." else _err "${ERR}could not download ${url}/${bin_ver}.tar.xz." exit 1 fi pushd "${dl_path}" >/dev/null - gpg --verify "${bin_ver}.tar.xz.sig" >/dev/null 2>&1 - if [[ "$?" -eq 0 ]]; then + if gpg --verify "${bin_ver}.tar.xz.sig" >/dev/null 2>&1; then _msg "${PAS}Signature is valid." popd >/dev/null else @@ -304,7 +297,7 @@ sys_create_store() local pkg="$1" local tmp_path="$2" - _debug "--- [ $FUNCNAME ] ---" + _debug "--- [ ${FUNCNAME[0]} ] ---" cd "$tmp_path" tar --extract \ @@ -321,28 +314,29 @@ sys_create_store() fi _msg "${INF}Linking the root user's profile" - mkdir -p "${ROOT_HOME}/.config/guix" + mkdir -p "~root/.config/guix" ln -sf /var/guix/profiles/per-user/root/current-guix \ - "${ROOT_HOME}/.config/guix/current" + "~root/.config/guix/current" - GUIX_PROFILE="${ROOT_HOME}/.config/guix/current" + GUIX_PROFILE="~root/.config/guix/current" + # shellcheck disable=SC1090 source "${GUIX_PROFILE}/etc/profile" - _msg "${PAS}activated root profile at ${ROOT_HOME}/.config/guix/current" + _msg "${PAS}activated root profile at ${GUIX_PROFILE}" } sys_create_build_user() { # Create the group and user accounts for build users. - _debug "--- [ $FUNCNAME ] ---" + _debug "--- [ ${FUNCNAME[0]} ] ---" - if [ $(getent group guixbuild) ]; then + if getent group guixbuild > /dev/null; then _msg "${INF}group guixbuild exists" else groupadd --system guixbuild _msg "${PAS}group created" fi - if [ $(getent group kvm) ]; then + if getent group kvm > /dev/null; then _msg "${INF}group kvm exists and build users will be added to it" local KVMGROUP=,kvm fi @@ -371,7 +365,7 @@ sys_enable_guix_daemon() local local_bin local var_guix - _debug "--- [ $FUNCNAME ] ---" + _debug "--- [ ${FUNCNAME[0]} ] ---" info_path="/usr/local/share/info" local_bin="/usr/local/bin" @@ -380,7 +374,7 @@ sys_enable_guix_daemon() case "$INIT_SYS" in upstart) { initctl reload-configuration; - cp "${ROOT_HOME}/.config/guix/current/lib/upstart/system/guix-daemon.conf" \ + cp "~root/.config/guix/current/lib/upstart/system/guix-daemon.conf" \ /etc/init/ && start guix-daemon; } && _msg "${PAS}enabled Guix daemon via upstart" @@ -389,15 +383,15 @@ sys_enable_guix_daemon() { # systemd .mount units must be named after the target directory. # Here we assume a hard-coded name of /gnu/store. # XXX Work around until next release. - if [ -f "${ROOT_HOME}/.config/guix/current/lib/systemd/system/gnu-store.mount" ]; then - cp "${ROOT_HOME}/.config/guix/current/lib/systemd/system/gnu-store.mount" \ + if [ -f "~root/.config/guix/current/lib/systemd/system/gnu-store.mount" ]; then + cp "~root/.config/guix/current/lib/systemd/system/gnu-store.mount" \ /etc/systemd/system/; chmod 664 /etc/systemd/system/gnu-store.mount; systemctl daemon-reload && systemctl enable gnu-store.mount; fi - cp "${ROOT_HOME}/.config/guix/current/lib/systemd/system/guix-daemon.service" \ + cp "~root/.config/guix/current/lib/systemd/system/guix-daemon.service" \ /etc/systemd/system/; chmod 664 /etc/systemd/system/guix-daemon.service; @@ -418,7 +412,7 @@ sys_enable_guix_daemon() ;; sysv-init) { mkdir -p /etc/init.d; - cp "${ROOT_HOME}/.config/guix/current/etc/init.d/guix-daemon" \ + cp "~root/.config/guix/current/etc/init.d/guix-daemon" \ /etc/init.d/guix-daemon; chmod 775 /etc/init.d/guix-daemon; @@ -429,7 +423,7 @@ sys_enable_guix_daemon() ;; openrc) { mkdir -p /etc/init.d; - cp "${ROOT_HOME}/.config/guix/current/etc/openrc/guix-daemon" \ + cp "~root/.config/guix/current/etc/openrc/guix-daemon" \ /etc/init.d/guix-daemon; chmod 775 /etc/init.d/guix-daemon; @@ -439,7 +433,7 @@ sys_enable_guix_daemon() ;; NA|*) _msg "${ERR}unsupported init system; run the daemon manually:" - echo " ${ROOT_HOME}/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild" + echo " ~root/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild" ;; esac @@ -457,9 +451,9 @@ sys_enable_guix_daemon() sys_authorize_build_farms() { # authorize the public key of the build farm while true; do - read -p "Permit downloading pre-built package binaries from the project's build farm? (yes/no) " yn + read -rp "Permit downloading pre-built package binaries from the project's build farm? (yes/no) " yn case $yn in - [Yy]*) guix archive --authorize < "${ROOT_HOME}/.config/guix/current/share/guix/ci.guix.gnu.org.pub" && + [Yy]*) guix archive --authorize < "~root/.config/guix/current/share/guix/ci.guix.gnu.org.pub" && _msg "${PAS}Authorized public key for ci.guix.gnu.org"; break;; [Nn]*) _msg "${INF}Skipped authorizing build farm public keys" @@ -470,7 +464,7 @@ sys_authorize_build_farms() } sys_create_init_profile() -{ # Create /etc/profile.d/guix.sh for better desktop integration +{ # Define for better desktop integration # This will not take effect until the next shell or desktop session! [ -d "/etc/profile.d" ] || mkdir /etc/profile.d # Just in case cat <<"EOF" > /etc/profile.d/guix.sh @@ -544,7 +538,7 @@ This script installs GNU Guix on your system https://www.gnu.org/software/guix/ EOF echo -n "Press return to continue..." - read -r ANSWER + read -r } main() @@ -574,7 +568,7 @@ main() if ! [[ $GUIX_BINARY_FILE_NAME =~ $ARCH_OS ]]; then _err "$ARCH_OS not in ${GUIX_BINARY_FILE_NAME}; aborting" fi - _msg "Using manually provided binary ${GUIX_BINARY_FILE_NAME}" + _msg "${INF}Using manually provided binary ${GUIX_BINARY_FILE_NAME}" GUIX_BINARY_FILE_NAME=$(realpath "$GUIX_BINARY_FILE_NAME") fi -- 2.31.1