diff mbox series

[bug#40601,16/28] non-interactive mode, usage

Message ID 20200517171725.732-16-vincent.legoll@gmail.com
State Under Review
Delegated to: Christopher Baines
Headers show
Series [bug#40601,01/28] nix/local.mk: Add missing comment to sysvinit section. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch fail View Laminar job

Commit Message

Vincent Legoll May 17, 2020, 5:17 p.m. UTC
---
 etc/guix-install.sh | 68 +++++++++++++++++++++++++++++++++------------
 1 file changed, 51 insertions(+), 17 deletions(-)
diff mbox series

Patch

diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 1c22ae95ee..7fb9332e97 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -48,7 +48,6 @@  REQUIRE=(
     "chmod"
     "uname"
     "tail"
-    "realpath"
     "tar"
     "xz"
 )
@@ -454,17 +453,23 @@  sys_make_guix_available()
 
 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
-        case $yn in
-            [Yy]*) guix archive --authorize < "${ROOT_HOME}/.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"
-                   break;;
-            *) _msg "Please answer yes or no.";
-        esac
-    done
+    _AUTHORIZE_BUILD_FARM=1
+    if [ "$1" -eq 1 ]; then
+        while true; do
+            read -p "Permit downloading pre-built package binaries from the project's build farm? (yes/no) " yn
+            case "$yn" in
+                [Yy]*) _AUTHORIZE_BUILD_FARM=1; break;;
+                [Nn]*) _AUTHORIZE_BUILD_FARM=0; break;;
+                *) _msg "Please answer yes or no.";;
+            esac
+        done
+    fi
+    if [ "$_AUTHORIZE_BUILD_FARM" -eq 1 ]; then
+        guix archive --authorize < "${ROOT_HOME}/.config/guix/current/share/guix/ci.guix.gnu.org.pub" &&
+            _msg "${PAS}Authorized public key for ci.guix.gnu.org";
+    else
+        _msg "${INF}Skipped authorizing build farm public keys"
+    fi
 }
 
 sys_create_init_profile()
@@ -526,10 +531,41 @@  EOF
     read -r  ANSWER
 }
 
+# Do not change the tabs in the HERE-DOCUMENT
+usage()
+{
+    cat <<-EOF
+	$0: Wrong arguments:
+	$0 [-h|--help] [-n|--non-interactive] [LOCAL_GUIX_BIN_TARBALL]
+
+	-h|--help            Show this help
+	-n|--non-interactive Avoid asing interactive question, run unattended
+	                     automatically allow substitutes from guix build farm
+
+	LOCAL_GUIX_BIN_TARBALL Use the given guix binary tarball file instead of
+	                       downloading latest released one
+EOF
+}
+
+handle_args()
+{
+    _INTERACTIVE=1
+    while [ "$#" -gt 0 ]; do
+        case "$1" in
+            -h|--help) usage; exit 0;;
+            -n|--non-interactive) _INTERACTIVE=0; shift 1;;
+
+            -*) echo "unknown option: $1" >&2; echo; usage; exit 1;;
+            *) TARBALL="$1"; shift 1;;
+        esac
+    done
+}
+
 main()
 {
     local tmp_path
-    welcome
+    handle_args "$@"
+    [ "${_INTERACTIVE}" -eq 1 ] && welcome
 
     _msg "Starting installation ($(date))"
 
@@ -544,19 +580,17 @@  main()
     umask 0022
     tmp_path="$(mktemp -t -d guix.XXXXXX)"
 
-    if [ -z "$1" ]; then
+    if [ -z "${TARBALL}" ]; then
         guix_get_bin_list "${GNU_URL}"
         guix_get_bin "${GNU_URL}" "${BIN_VER}" "${tmp_path}"
         TARBALL="${BIN_VER}.tar.xz"
-    else
-        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
-    sys_authorize_build_farms
+    sys_authorize_build_farms "${_INTERACTIVE}"
     sys_create_init_profile
 
     _msg "${INF}cleaning up ${tmp_path}"