From patchwork Fri Oct 7 05:31:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 6245 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 809B627BBE9; Fri, 7 Oct 2022 06:33:29 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 4E0AD27BBEA for ; Fri, 7 Oct 2022 06:33:25 +0100 (BST) Received: from localhost ([::1]:56922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ogfzA-0005Qs-Fw for patchwork@mira.cbaines.net; Fri, 07 Oct 2022 01:33:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44288) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogfyo-0005O6-HU for guix-patches@gnu.org; Fri, 07 Oct 2022 01:33:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:34950) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ogfyo-0001Dt-9B for guix-patches@gnu.org; Fri, 07 Oct 2022 01:33:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ogfyo-0001z6-4b for guix-patches@gnu.org; Fri, 07 Oct 2022 01:33:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#58345] [PATCH 1/3] guix-install.sh: Improve prompt_yes_no procedure. References: <20221007052738.20637-1-maxim.cournoyer@gmail.com> In-Reply-To: <20221007052738.20637-1-maxim.cournoyer@gmail.com> Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 07 Oct 2022 05:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58345 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 58345@debbugs.gnu.org Cc: Maxim Cournoyer Received: via spool by 58345-submit@debbugs.gnu.org id=B58345.16651207407566 (code B ref 58345); Fri, 07 Oct 2022 05:33:02 +0000 Received: (at 58345) by debbugs.gnu.org; 7 Oct 2022 05:32:20 +0000 Received: from localhost ([127.0.0.1]:34025 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ogfy4-0001xs-60 for submit@debbugs.gnu.org; Fri, 07 Oct 2022 01:32:19 -0400 Received: from mail-qt1-f179.google.com ([209.85.160.179]:37570) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ogfxy-0001xG-31 for 58345@debbugs.gnu.org; Fri, 07 Oct 2022 01:32:13 -0400 Received: by mail-qt1-f179.google.com with SMTP id l27so2269573qtv.4 for <58345@debbugs.gnu.org>; Thu, 06 Oct 2022 22:32:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=rWhULu6LKnURKBcVWW85jL0NDjjMvJLC8Ae3SIK7RQ8=; b=KSkB+OyjXSQg6Y7XDc5QiORLa7rUGO8PYC9DR8z8Hq5f6iBkdMcX6z6lOd3b1+qOMn YcrtcbpB7KIQx0aPe924V5WtVm3IwHLYigA45Z8S1bTz9RBw4YdJlY+lFULINoDuB8N2 PtlOEAXjVR5HJsJIcuhURyEaKjn57fMO+aPA0dsSA7Yls3fAIiC5wz4DmQzRaM3pSgiV zhSvG54gyhBt5xFKLDI51vasly4jYpFAZnPEXAJM7QOh7TvCPAvuuHv1rW6d9YbxfNy1 uAmtbHlZD2hh230H1RzI1bAA8wEvJG9GINcw66xM3rSzz6o5iube5wBlXlb6uDUm6ORR 34kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rWhULu6LKnURKBcVWW85jL0NDjjMvJLC8Ae3SIK7RQ8=; b=nnK18Mv6YpOv+ZtrS3kScn9h7uLfmsI+hm2Z3AVuf8/vsVKZDPXdJo+LBjkRQLJ0Df YtBNOKsiVBawCki8WDfk1KmDqakCW3EAWYVwFsKx9Imq7BOUG+9EeKrYZhai193Z/Qyh ZccN1KRYU1+s9rzuEhTT4CwAajJrjcqZfHgv9Vod8/Z2HBNa5TaMdQCeeOwj0cM7ay6w wcnVfn0UZkCxLKq08yU4m1MYLTpZhXqFeg7+zIhq29G4ZP/cPiKxOMHh/IxuRTBKBBtb 1WGUXLFEAeQ8ZfOtPXJnr7/rZvQCTINjiCicaX0sl8eQoFx7x0lJ30SjLzNeLOezUmKO kJHg== X-Gm-Message-State: ACrzQf1W64SxF+1e0aOPZuseBCxpoI1HjQcQBhruAMfJYSn6fizrDl05 rbGnZeFf9sRmv2cuP2CstTV909O/NiE= X-Google-Smtp-Source: AMsMyM69M5Irde1k0F8QQZGgKhxa+HH6Qd57P9ZaJL9lr2hX2EABJXLB2wkKucmabduN2Ml8VZ/QIw== X-Received: by 2002:a05:622a:1181:b0:35b:b57d:fb14 with SMTP id m1-20020a05622a118100b0035bb57dfb14mr2974524qtk.605.1665120724402; Thu, 06 Oct 2022 22:32:04 -0700 (PDT) Received: from localhost.localdomain ([2607:fad8:4:3::1005]) by smtp.gmail.com with ESMTPSA id ff13-20020a05622a4d8d00b0035d420c4ba7sm1367801qtb.54.2022.10.06.22.32.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 22:32:03 -0700 (PDT) From: Maxim Cournoyer Date: Fri, 7 Oct 2022 01:31:58 -0400 Message-Id: <20221007053200.21177-1-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * etc/guix-install.sh (_flush): New function. (prompt_yes_no): Clear input, then only read the first character, silently. Add the [Yes/no] string to the message. When a newline is entered by the user, treat it as the default value, which is "yes". (chk_gpg_keyring): Remove "(yes/no)" from the prompt message. (configure_substitute_discovery): Likewise. (sys_authorize_build_farms): Likewise. --- etc/guix-install.sh | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/etc/guix-install.sh b/etc/guix-install.sh index 300681e111..8c05d19657 100755 --- a/etc/guix-install.sh +++ b/etc/guix-install.sh @@ -9,7 +9,7 @@ # Copyright © 2020 Daniel Brooks # Copyright © 2021 Jakub Kądziołka # Copyright © 2021 Chris Marusich -# Copyright © 2021 Maxim Cournoyer +# Copyright © 2021, 2022 Maxim Cournoyer # # This file is part of GNU Guix. # @@ -92,15 +92,25 @@ _debug() fi } -# Return true if user answered yes, false otherwise. +_flush() +{ + while read -t0; do + read -N1 + done +} + +# Return true if user answered yes, false otherwise. It defaults to "yes" +# when a single newline character is input. # $1: The prompt question. prompt_yes_no() { while true; do - read -rp "$1 " yn + _flush + read -N1 -rsp "$1 [Y/n]" yn case $yn in - [Yy]*) return 0;; - [Nn]*) return 1;; - *) _msg "Please answer yes or no." + $'\n') echo && return 0;; + [Yy]*) echo && return 0;; + [Nn]*) echo && return 1;; + *) echo && _msg "Please answer yes or no." esac done } @@ -137,7 +147,7 @@ chk_gpg_keyring() if ! gpg --dry-run --list-keys "$gpg_key_id" >/dev/null 2>&1; then if prompt_yes_no "${INF}The following OpenPGP public key is \ required to verify the Guix binary signature: $gpg_key_id. -Would you like me to fetch it for you? (yes/no)"; then +Would you like me to fetch it for you?"; then wget "https://sv.gnu.org/people/viewgpg.php?user_id=$user_id" \ --no-verbose -O- | gpg --import - else @@ -254,7 +264,7 @@ chk_sys_nscd() configure_substitute_discovery() { if grep -q -- '--discover=no' "$1" && \ prompt_yes_no "Would you like the Guix daemon to automatically \ -discover substitute servers on the local network? (yes/no)"; then +discover substitute servers on the local network?"; then sed -i 's/--discover=no/--discover=yes/' "$1" fi } @@ -490,7 +500,7 @@ sys_enable_guix_daemon() sys_authorize_build_farms() { # authorize the public key of the build farm if prompt_yes_no "Permit downloading pre-built package binaries from the \ -project's build farm? (yes/no)"; then +project's build farm?"; then guix archive --authorize \ < ~root/.config/guix/current/share/guix/ci.guix.gnu.org.pub \ && _msg "${PAS}Authorized public key for ci.guix.gnu.org"