From patchwork Thu Feb 6 04:25:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Liam Hupfer X-Patchwork-Id: 38309 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 F28E027BBE2; Thu, 6 Feb 2025 04:27:55 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL, RCVD_IN_VALIDITY_SAFE,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham 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 18EB827BBEA for ; Thu, 6 Feb 2025 04:27:55 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tftU1-0000Uf-5X; Wed, 05 Feb 2025 23:27:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tftTp-0000Qg-JN for guix-patches@gnu.org; Wed, 05 Feb 2025 23:27:10 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tftTn-000193-Cd; Wed, 05 Feb 2025 23:27:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=7CTPVy6CW1o1JoPPQ2/JPV47f0kTyuwunrDqSGq91i8=; b=aa5oc95AvutrHCAi/XT/Z5VBZQqPggEaFGRmN5dcMaso6n8tLXhuxShFJBFiX/R6DaFDZItP/ptK3M4Ukmy1NBf5CyGEl8ktEGScg5vAV2i7J1tohEupw53RTAeVDoeJoy8Yyog/FEeGXx/wEIl6f9yt/sjPlVFbMY6JGTW7b32a1Cw8Uzv3zDZU6PeucOVxTKRIA87LbxE9qYmVf+6ALJcFwRIsfrvtscaNaGld4ZgMjsaUnh3ckf0+K8bbhe2CK95WORyibYfixTFqtg/pwh1Ir7IXPshbix3iI9yfXBn5JTMEoc5A5+soSF1i8+Lc9kl7HMFhThtwagNMeLVqBg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tftTk-0002Xw-Lp; Wed, 05 Feb 2025 23:27:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#76082] [PATCH 8/9] guix-install.sh: Add msg helpers and use stderr consistently. Resent-From: Liam Hupfer Original-Sender: "Debbugs-submit" Resent-CC: andrew@trop.in, janneke@gnu.org, ludo@gnu.org, tanguy@bioneland.org, vagrant@debian.org, guix-patches@gnu.org Resent-Date: Thu, 06 Feb 2025 04:27:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 76082 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 76082@debbugs.gnu.org Cc: Liam Hupfer , Andrew Tropin , Janneke Nieuwenhuizen , Ludovic =?utf-8?q?Court=C3=A8s?= , Tanguy Le Carrour , Vagrant Cascadian X-Debbugs-Original-Xcc: Andrew Tropin , Janneke Nieuwenhuizen , Ludovic =?utf-8?q?Court=C3=A8s?= , Tanguy Le Carrour , Vagrant Cascadian Received: via spool by 76082-submit@debbugs.gnu.org id=B76082.17388160029677 (code B ref 76082); Thu, 06 Feb 2025 04:27:04 +0000 Received: (at 76082) by debbugs.gnu.org; 6 Feb 2025 04:26:42 +0000 Received: from localhost ([127.0.0.1]:53634 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tftTJ-0002Vn-BC for submit@debbugs.gnu.org; Wed, 05 Feb 2025 23:26:42 -0500 Received: from out-181.mta1.migadu.com ([2001:41d0:203:375::b5]:42811) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tftTF-0002V8-Pi for 76082@debbugs.gnu.org; Wed, 05 Feb 2025 23:26:35 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpfr.net; s=key1; t=1738815987; h=from:from: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: in-reply-to:in-reply-to:references:references; bh=7CTPVy6CW1o1JoPPQ2/JPV47f0kTyuwunrDqSGq91i8=; b=rnQtlxxAQIlZEonaNpIttw2smkS7dDSC8IoLWzDKAvb6QOHHYpgy3Ay9tBoi3JCJZKJznQ YIZAB0x/1/CdAAznNtOSQt8NbNdS0a73zmplonp531tL3oG5EyLygbCzLg2Iuyq8bksvna qO8bOHRjPnOb3ba3MQfzkwF2V2ja7+ndH8pqMqmIB3DsYVjvkOplgo4ThTP5/pCOuOiwiW JowwZAKSYkru0LO7EHYsHb/DvwS475tZJkDf7mhmfTF9reqm210W7tKfEBh3pQv/WSM5Th IqDftTUnil0//kyeJ8+KCZqLaPuO8R+lKSH0EJzfCuUCtK2PPTM8F+ZaOL/YWQ== From: Liam Hupfer Date: Wed, 5 Feb 2025 22:25:04 -0600 Message-ID: <15ab3b91f03b6d46fc1014b073576a4006da3de3.1738815703.git.liam@hpfr.net> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Add helpers to avoid repeated manual concatenation. _err and _msg "$ERR are used interchangeably with their only difference being output stream; convert all errors to use _err. * etc/guix-install.sh: Add msg helpers and consolidate errors to stderr. Change-Id: I06e97ccc50d108ed9e279ae80c6b2386d7b8c36b --- etc/guix-install.sh | 149 ++++++++++++++++++++++++-------------------- 1 file changed, 82 insertions(+), 67 deletions(-) diff --git a/etc/guix-install.sh b/etc/guix-install.sh index 340c3a394f..7a731962b3 100755 --- a/etc/guix-install.sh +++ b/etc/guix-install.sh @@ -110,7 +110,7 @@ GPG_SIGNING_KEYS[127547]=27D586A4F8900854329FF09F1260E46482E63562 # maxim _err() { # All errors go to stderr. - printf "[%s]: %s\n" "$(date +%s.%3N)" "$1" + printf "[%s]: ${ERR}%s\n" "$(date +%s.%3N)" "$1" } _msg() @@ -118,6 +118,21 @@ _msg() printf "[%s]: %s\n" "$(date +%s.%3N)" "$1" } +_msg_pass() +{ + _msg "$PAS$1" +} + +_msg_warn() +{ + _msg "$WAR$1" +} + +_msg_info() +{ + _msg "$INF$1" +} + _debug() { if [ "${DEBUG}" = '1' ]; then @@ -127,7 +142,7 @@ _debug() die() { - _err "${ERR}$*" + _err "$*" exit 1 } @@ -154,7 +169,7 @@ chk_require() [ "${#warn}" -ne 0 ] && die "Missing commands: ${warn[*]}." - _msg "${PAS}verification of required commands completed" + _msg_pass "verification of required commands completed" } add_init_sys_require() @@ -195,7 +210,7 @@ Would you like me to fetch it for you?"; then fi # If we reach this point, the key is (still) missing. Report further # missing keys, if any, but then abort the installation. - _err "${ERR}Missing OpenPGP public key ($gpg_key_id). + _err "Missing OpenPGP public key ($gpg_key_id). Fetch it with this command: wget \"https://sv.gnu.org/people/viewgpg.php?user_id=$user_id\" -O - | \ @@ -227,24 +242,24 @@ chk_term() chk_init_sys() { # Return init system type name. if [[ $(/sbin/init --version 2>/dev/null) =~ upstart ]]; then - _msg "${INF}init system is: upstart" + _msg_info "init system is: upstart" INIT_SYS="upstart" return 0 elif [[ $(systemctl 2>/dev/null) =~ -\.mount ]]; then - _msg "${INF}init system is: systemd" + _msg_info "init system is: systemd" INIT_SYS="systemd" return 0 elif [[ -f /etc/init.d/cron && ! -h /etc/init.d/cron ]]; then - _msg "${INF}init system is: sysv-init" + _msg_info "init system is: sysv-init" INIT_SYS="sysv-init" return 0 elif [[ $(openrc --version 2>/dev/null) =~ \(OpenRC ]]; then - _msg "${INF}init system is: OpenRC" + _msg_info "init system is: OpenRC" INIT_SYS="openrc" return 0 else INIT_SYS="NA" - _err "${ERR}Init system could not be detected." + _err "Init system could not be detected." fi } @@ -291,12 +306,12 @@ chk_sys_nscd() { # Check if nscd is up and suggest to start it or install it if [ "$(type -P pidof)" ]; then if [ ! "$(pidof nscd)" ]; then - _msg "${WAR}We recommend installing and/or starting your distribution 'nscd' service" - _msg "${WAR}Please read 'info guix \"Application Setup\"' about \"Name Service Switch\"" + _msg_warn "We recommend installing and/or starting your distribution 'nscd' service" + _msg_warn "Please read 'info guix \"Application Setup\"' about \"Name Service Switch\"" fi else - _msg "${INF}We cannot determine if your distribution 'nscd' service is running" - _msg "${INF}Please read 'info guix \"Application Setup\"' about \"Name Service Switch\"" + _msg_info "We cannot determine if your distribution 'nscd' service is running" + _msg_info "Please read 'info guix \"Application Setup\"' about \"Name Service Switch\"" fi } @@ -334,7 +349,7 @@ guix_get_bin_list() default_ver="guix-binary-${latest_ver}.${ARCH_OS}" if [[ "${#bin_ver_ls}" -ne "0" ]]; then - _msg "${PAS}Release for your system: ${default_ver}" + _msg_pass "Release for your system: ${default_ver}" else die "Could not obtain list of Guix releases." fi @@ -352,21 +367,21 @@ guix_get_bin() _debug "--- [ ${FUNCNAME[0]} ] ---" - _msg "${INF}Downloading Guix release archive" + _msg_info "Downloading Guix release archive" wget --help | grep -q '\--show-progress' \ && wget_args=("--no-verbose" "--show-progress") if wget "${wget_args[@]}" -P "$dl_path" \ "${url}/${bin_ver}.tar.xz" "${url}/${bin_ver}.tar.xz.sig"; then - _msg "${PAS}download completed." + _msg_pass "download completed." else die "could not download ${url}/${bin_ver}.tar.xz." fi pushd "${dl_path}" >/dev/null if gpg --verify "${bin_ver}.tar.xz.sig" >/dev/null 2>&1; then - _msg "${PAS}Signature is valid." + _msg_pass "Signature is valid." popd >/dev/null else die "could not verify the signature." @@ -382,18 +397,18 @@ sys_create_store() if [[ -e /var/guix && -e /gnu ]]; then if [ -n "$GUIX_ALLOW_OVERWRITE" ]; then - _msg "${WAR}Overwriting existing installation!" + _msg_warn "Overwriting existing installation!" else die "A previous Guix installation was found. Refusing to overwrite." fi fi cd "$tmp_path" - _msg "${INF}Installing /var/guix and /gnu..." + _msg_info "Installing /var/guix and /gnu..." # Strip (skip) the leading ‘.’ component, which fails on read-only ‘/’. tar --extract --strip-components=1 --file "$pkg" -C / - _msg "${INF}Linking the root user's profile" + _msg_info "Linking the root user's profile" mkdir -p ~root/.config/guix ln -sf /var/guix/profiles/per-user/root/current-guix \ ~root/.config/guix/current @@ -403,18 +418,18 @@ sys_create_store() # effective linting. # shellcheck disable=SC1091 source "${GUIX_PROFILE}/etc/profile" - _msg "${PAS}activated root profile at ${GUIX_PROFILE}" + _msg_pass "activated root profile at ${GUIX_PROFILE}" } sys_delete_store() { - _msg "${INF}removing /var/guix" + _msg_info "removing /var/guix" rm -rf /var/guix - _msg "${INF}removing /gnu" + _msg_info "removing /gnu" rm -rf /gnu - _msg "${INF}removing ~root/.config/guix" + _msg_info "removing ~root/.config/guix" rm -rf ~root/.config/guix } @@ -424,20 +439,20 @@ sys_create_build_user() _debug "--- [ ${FUNCNAME[0]} ] ---" if getent group guixbuild > /dev/null; then - _msg "${INF}group guixbuild exists" + _msg_info "group guixbuild exists" else groupadd --system guixbuild - _msg "${PAS}group created" + _msg_pass "group created" fi if getent group kvm > /dev/null; then - _msg "${INF}group kvm exists and build users will be added to it" + _msg_info "group kvm exists and build users will be added to it" local KVMGROUP=,kvm fi for i in $(seq -w 1 10); do if id "guixbuilder${i}" &>/dev/null; then - _msg "${INF}user is already in the system, reset" + _msg_info "user is already in the system, reset" usermod -g guixbuild -G guixbuild"$KVMGROUP" \ -d /var/empty -s "$(which nologin)" \ -c "Guix build user $i" \ @@ -447,7 +462,7 @@ sys_create_build_user() -d /var/empty -s "$(which nologin)" \ -c "Guix build user $i" --system \ "guixbuilder${i}"; - _msg "${PAS}user added " + _msg_pass "user added " fi done } @@ -460,7 +475,7 @@ sys_delete_build_user() fi done - _msg "${INF}delete group guixbuild" + _msg_info "delete group guixbuild" if getent group guixbuild &>/dev/null; then groupdel -f guixbuild fi @@ -486,7 +501,7 @@ sys_enable_guix_daemon() /etc/init/ && configure_substitute_discovery /etc/init/guix-daemon.conf && start guix-daemon; } && - _msg "${PAS}enabled Guix daemon via upstart" + _msg_pass "enabled Guix daemon via upstart" ;; systemd) { install_unit() @@ -511,7 +526,7 @@ sys_enable_guix_daemon() systemctl daemon-reload && systemctl start guix-daemon; } && - _msg "${PAS}enabled Guix daemon via systemd" + _msg_pass "enabled Guix daemon via systemd" ;; sysv-init) { mkdir -p /etc/init.d; @@ -524,7 +539,7 @@ sys_enable_guix_daemon() update-rc.d guix-daemon defaults && update-rc.d guix-daemon enable && service guix-daemon start; } && - _msg "${PAS}enabled Guix daemon via sysv" + _msg_pass "enabled Guix daemon via sysv" ;; openrc) { mkdir -p /etc/init.d; @@ -536,15 +551,15 @@ sys_enable_guix_daemon() rc-update add guix-daemon default && rc-service guix-daemon start; } && - _msg "${PAS}enabled Guix daemon via OpenRC" + _msg_pass "enabled Guix daemon via OpenRC" ;; NA|*) - _msg "${ERR}unsupported init system; run the daemon manually:" + _err "unsupported init system; run the daemon manually:" echo " ~root/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild" ;; esac - _msg "${INF}making the guix command available to other users" + _msg_info "making the guix command available to other users" [ -e "$local_bin" ] || mkdir -p "$local_bin" ln -sf "${var_guix}/bin/guix" "$local_bin" @@ -570,28 +585,28 @@ sys_delete_guix_daemon() case "$INIT_SYS" in upstart) - _msg "${INF}stopping guix-daemon" + _msg_info "stopping guix-daemon" stop guix-daemon - _msg "${INF}removing guix-daemon" + _msg_info "removing guix-daemon" rm /etc/init/guix-daemon.conf ;; systemd) if [ -f /etc/systemd/system/guix-daemon.service ]; then - _msg "${INF}disabling guix-daemon" + _msg_info "disabling guix-daemon" systemctl disable guix-daemon - _msg "${INF}stopping guix-daemon" + _msg_info "stopping guix-daemon" systemctl stop guix-daemon - _msg "${INF}removing guix-daemon" + _msg_info "removing guix-daemon" rm -f /etc/systemd/system/guix-daemon.service fi if [ -f /etc/systemd/system/gnu-store.mount ]; then - _msg "${INF}disabling gnu-store.mount" + _msg_info "disabling gnu-store.mount" systemctl disable gnu-store.mount - _msg "${INF}stopping gnu-store.mount" + _msg_info "stopping gnu-store.mount" systemctl stop gnu-store.mount - _msg "${INF}removing gnu-store.mount" + _msg_info "removing gnu-store.mount" rm -f /etc/systemd/system/gnu-store.mount fi systemctl daemon-reload @@ -603,16 +618,16 @@ sys_delete_guix_daemon() rm -rf /etc/init.d/guix-daemon ;; NA|*) - _msg "${ERR}unsupported init system; disable, stop and remove the daemon manually:" + _err "unsupported init system; disable, stop and remove the daemon manually:" echo " ~root/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild" ;; esac - _msg "${INF}removing $local_bin/guix" + _msg_info "removing $local_bin/guix" rm -f "$local_bin"/guix - _msg "${INF}removing $info_path/guix*" + _msg_info "removing $info_path/guix*" rm -f "$info_path"/guix* } @@ -629,10 +644,10 @@ project's build farms?"; then local key=~root/.config/guix/current/share/guix/$host.pub [ -f "$key" ] \ && guix archive --authorize < "$key" \ - && _msg "${PAS}Authorized public key for $host" + && _msg_pass "Authorized public key for $host" done else - _msg "${INF}Skipped authorizing build farm public keys" + _msg_info "Skipped authorizing build farm public keys" fi } @@ -715,7 +730,7 @@ sys_create_shell_completion() ln -sf ${var_guix}/etc/bash_completion.d/guix-daemon "$bash_completion"; ln -sf ${var_guix}/share/zsh/site-functions/_guix "$zsh_completion"; ln -sf ${var_guix}/share/fish/vendor_completions.d/guix.fish "$fish_completion"; } && - _msg "${PAS}installed shell completion" + _msg_pass "installed shell completion" } sys_delete_shell_completion() @@ -726,7 +741,7 @@ sys_delete_shell_completion() zsh_completion=/usr/share/zsh/site-functions fish_completion=/usr/share/fish/vendor_completions.d - _msg "${INF}removing shell completion" + _msg_info "removing shell completion" rm -f "$bash_completion"/guix; rm -f "$bash_completion"/guix-daemon; @@ -753,7 +768,7 @@ if [ -n "$GUIX_ENVIRONMENT" ]; then fi ' >> "$bashrc" done - _msg "${PAS}Bash shell prompt successfully customized for Guix" + _msg_pass "Bash shell prompt successfully customized for Guix" } sys_maybe_setup_selinux() @@ -782,17 +797,17 @@ sys_maybe_setup_selinux() sys_delete_init_profile() { - _msg "${INF}removing /etc/profile.d/guix.sh" + _msg_info "removing /etc/profile.d/guix.sh" rm -f /etc/profile.d/guix.sh } sys_delete_user_profiles() { - _msg "${INF}removing ~root/.guix-profile" + _msg_info "removing ~root/.guix-profile" rm -f ~root/.guix-profile rm -rf ~root/.cache/guix - _msg "${INF}removing .guix-profile, .cache/guix and .config/guix of all /home users" + _msg_info "removing .guix-profile, .cache/guix and .config/guix of all /home users" rm -rf /home/*/{.guix-profile,{.cache,.config}/guix} } @@ -841,8 +856,8 @@ EOF if [ "$char" ]; then echo echo "...that ($char) was not a return!" - _msg "${WAR}Use newlines to automate installation, e.g.: yes '' | ${0##*/}" - _msg "${WAR}Any other method is unsupported and likely to break in future." + _msg_warn "Use newlines to automate installation, e.g.: yes '' | ${0##*/}" + _msg_warn "Any other method is unsupported and likely to break in future." fi } @@ -861,7 +876,7 @@ main_install() chk_sys_arch chk_sys_nscd - _msg "${INF}system is ${ARCH_OS}" + _msg_info "system is ${ARCH_OS}" umask 0022 tmp_path="$(mktemp -t -d guix.XXXXXX)" @@ -874,7 +889,7 @@ main_install() if ! [[ $GUIX_BINARY_FILE_NAME =~ $ARCH_OS ]]; then _err "$ARCH_OS not in ${GUIX_BINARY_FILE_NAME}; aborting" fi - _msg "${INF}Using manually provided binary ${GUIX_BINARY_FILE_NAME}" + _msg_info "Using manually provided binary ${GUIX_BINARY_FILE_NAME}" GUIX_BINARY_FILE_NAME=$(realpath "$GUIX_BINARY_FILE_NAME") fi @@ -887,14 +902,14 @@ main_install() sys_create_shell_completion sys_customize_bashrc - _msg "${INF}cleaning up ${tmp_path}" + _msg_info "cleaning up ${tmp_path}" rm -r "${tmp_path}" - _msg "${PAS}Guix has successfully been installed!" - _msg "${INF}Run 'info guix' to read the manual." + _msg_pass "Guix has successfully been installed!" + _msg_info "Run 'info guix' to read the manual." # Required to source /etc/profile in desktop environments. - _msg "${INF}Please log out and back in to complete the installation." + _msg_info "Please log out and back in to complete the installation." } main_uninstall() @@ -908,7 +923,7 @@ main_uninstall() chk_init_sys chk_sys_arch - _msg "${INF}system is ${ARCH_OS}" + _msg_info "system is ${ARCH_OS}" # stop the build, package system. sys_delete_guix_daemon @@ -922,12 +937,12 @@ main_uninstall() sys_delete_shell_completion # these directories are created on the fly during usage. - _msg "${INF}removing /etc/guix" + _msg_info "removing /etc/guix" rm -rf /etc/guix - _msg "${INF}removing /var/log/guix" + _msg_info "removing /var/log/guix" rm -rf /var/log/guix - _msg "${PAS}Guix has successfully been uninstalled!" + _msg_pass "Guix has successfully been uninstalled!" } main()