From patchwork Sun May 17 17:17:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Legoll X-Patchwork-Id: 22159 X-Patchwork-Delegate: mail@cbaines.net 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 CB11727BBE3; Sun, 17 May 2020 18:19:39 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 605F427BBE1 for ; Sun, 17 May 2020 18:19:39 +0100 (BST) Received: from localhost ([::1]:42152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jaMws-0000Z3-Sf for patchwork@mira.cbaines.net; Sun, 17 May 2020 13:19:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60332) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jaMwO-0008H0-PF for guix-patches@gnu.org; Sun, 17 May 2020 13:19:08 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:33081) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jaMwN-0004M3-H1 for guix-patches@gnu.org; Sun, 17 May 2020 13:19:08 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jaMwN-0007A3-Dd for guix-patches@gnu.org; Sun, 17 May 2020 13:19:07 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#40601] [PATCH 12/28] guix-install.sh: Rework user & group handling, adding busybox support. Resent-From: Vincent Legoll Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 17 May 2020 17:19:07 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40601 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 40601@debbugs.gnu.org Cc: Vincent Legoll Received: via spool by 40601-submit@debbugs.gnu.org id=B40601.158973591027337 (code B ref 40601); Sun, 17 May 2020 17:19:07 +0000 Received: (at 40601) by debbugs.gnu.org; 17 May 2020 17:18:30 +0000 Received: from localhost ([127.0.0.1]:44588 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jaMvY-00076P-0z for submit@debbugs.gnu.org; Sun, 17 May 2020 13:18:29 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:43464) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jaMvG-00071p-1M for 40601@debbugs.gnu.org; Sun, 17 May 2020 13:17:58 -0400 Received: by mail-wr1-f65.google.com with SMTP id i15so9040165wrx.10 for <40601@debbugs.gnu.org>; Sun, 17 May 2020 10:17:58 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=2izcnBu2ZDWO/kGThBJBoui+0alVNDMev/sMWrvHluo=; b=rpoS9d14/uNkiHssIHLUvxZEe9yr+96zfeABbw6rBxzqOdfVa5z39ObLnj0j4/J2GT ChQCFLWbAq/gzQRzpL7JZPDvUcJHxEl2iieIzV11dqb5JD92MnkbJp+qwhRwIJP8fAFu xQguwJzrlwMXhHxrph15hMc83BFTK7ath9/+dH3QNRMakTNO7CAlj365mBCXeznOBC7R eKROmRQrpq2dr1F4rN+3d9K7Ar+3x07CJoORqd9JX4UD9UrN0lIVETk/A6IKbZwhRorC B9cKLhUVZ+v5Ixawl0+UBTqE6LgwU5sfjQxStehvfR/2sIqBkU88LVGGPOj23XDQSbXQ I8kw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=2izcnBu2ZDWO/kGThBJBoui+0alVNDMev/sMWrvHluo=; b=SWlAYi8fQu/TyiTziCQtj5GMcGaQwfwg4mSxCW2D1zajecHgoLxRq+KdGTB8U6e4MS IlXf2Sp7Rc9SU8rmjp/vcLp+191QpMVspizvjwLjYlGA/EKDt4U9d06UwzbFcfyCdRRn joJFBKjg9eLYtvTXCqfcJVNywhLff7p5MPF+dGNRc1eGVIDg+Esu4hHoemEQ10f6fGPk nhG+nFC9kvG9lcAECP4hLSqVOyLiYBpxDiYjZ76Ke/KI2jeVAPV6RjTzIZ5nmw1fryIR PrzCwRuA+1NL0bDZWAKfzHKHMh4Q54j22UuahUr9BQFaxd92Ws8r/QoYRu/H/gL6nDp8 s6oA== X-Gm-Message-State: AOAM5305uxndsS2ONQuT0vrDWMSSmY1jghMmLtbYJZvLKHWh3+UBnlA2 TplshbEzM8gP30T56EJctNAtrV7k X-Google-Smtp-Source: ABdhPJz9TUyc+hP2IDG+tzFqnIjparv0j7nKds9p45nuY96kyc1WUTuN+FHiNlRspURNrSEcAqXo5w== X-Received: by 2002:adf:fdd0:: with SMTP id i16mr15156444wrs.389.1589735872187; Sun, 17 May 2020 10:17:52 -0700 (PDT) Received: from localhost.localdomain (se167-1-82-242-148-1.fbx.proxad.net. [82.242.148.1]) by smtp.gmail.com with ESMTPSA id v126sm13305048wma.9.2020.05.17.10.17.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2020 10:17:51 -0700 (PDT) From: Vincent Legoll Date: Sun, 17 May 2020 19:17:09 +0200 Message-Id: <20200517171725.732-12-vincent.legoll@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200517171725.732-1-vincent.legoll@gmail.com> References: <20200517171725.732-1-vincent.legoll@gmail.com> 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 (REQUIRE): Remove groupadd, add comment. (sys_create_build_user): Add adduser handling. (sys_create_build_group): New function, add addgroup handling... (main): ...call it here. --- etc/guix-install.sh | 57 +++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/etc/guix-install.sh b/etc/guix-install.sh index 043357d9c4..d6966f851a 100755 --- a/etc/guix-install.sh +++ b/etc/guix-install.sh @@ -32,6 +32,8 @@ set -e [ "$UID" -eq 0 ] || { echo "This script must be run as root."; exit 1; } +# groupadd, useradd, usermod, adduser, addgroup are handled in: +# sys_create_build_user & sys_create_build_group functions. REQUIRE=( "wget" "gpg" @@ -45,7 +47,6 @@ REQUIRE=( "rm" "chmod" "uname" - "groupadd" "tail" "realpath" "tar" @@ -298,31 +299,56 @@ sys_create_store() _msg "${PAS}activated root profile at ${ROOT_HOME}/.config/guix/current" } -sys_create_build_user() -{ # Create the group and user accounts for build users. +sys_create_build_group() +{ # Create the group for build users. _debug "--- [ $FUNCNAME ] ---" if getent group guixbuild >/dev/null 2>&1; then - _msg "${INF}group guixbuild exists" - else + _msg "${INF}group guixbuild already exists" + elif command -v groupadd &>/dev/null; then groupadd --system guixbuild _msg "${PAS}group created" + elif command -v addgroup &>/dev/null; then + addgroup -S guixbuild + _msg "${PAS}group created" + else + _err "${ERR}cannot add group for guix build users" + exit 1 fi +} + +sys_create_build_user() +{ # Create the user accounts for build users. + + _debug "--- [ $FUNCNAME ] ---" for i in $(seq -w 1 10); do if getent passwd "guixbuilder${i}" >/dev/null 2>&1; then - _msg "${INF}user is already in the system, reset" - usermod -g guixbuild -G guixbuild \ - -d /var/empty -s "$(which nologin)" \ - -c "Guix build user $i" \ - "guixbuilder${i}"; + if command -v usermod &>/dev/null; then + _msg "${INF}user is already in the system, resetting" + usermod -g guixbuild -G guixbuild \ + -d /var/empty -s "$(which nologin)" \ + -c "Guix build user $i" \ + "guixbuilder${i}" + else + _msg "${ERR}cannot reset user environment, doing nothing" + fi else - useradd -g guixbuild -G guixbuild \ - -d /var/empty -s "$(which nologin)" \ - -c "Guix build user $i" --system \ - "guixbuilder${i}"; - _msg "${PAS}user added " + if command -v useradd &>/dev/null; then + useradd -g guixbuild -G guixbuild \ + -d /var/empty -s "$(which nologin)" \ + -c "Guix build user $i" --system \ + "guixbuilder${i}" + _msg "${PAS}user added " + elif command -v adduser &>/dev/null; then + adduser -G guixbuild -h /var/empty -s "$(which nologin)" \ + -H -S "guixbuilder${i}" + _msg "${PAS}user added " + else + _msg "${ERR}cannot add user: " + exit 1 + fi fi done } @@ -509,6 +535,7 @@ main() TARBALL="$(realpath $1)" fi sys_create_store "${TARBALL}" "${tmp_path}" + sys_create_build_group sys_create_build_user sys_enable_guix_daemon sys_make_guix_available