diff options
| author | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2021-05-04 17:05:43 -0400 |
|---|---|---|
| committer | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2021-05-05 11:01:06 -0400 |
| commit | e61fe664a4a3fd9ae09ff1890cc1dc3285ab3634 (patch) | |
| tree | 86b7bbd54e93ec5a5cdff89b32b0be4ea49bcf17 /etc | |
| parent | af66a9510fdbe9a7cb3ad2a1acdf190553727704 (diff) | |
guix-install.sh: Please the shellcheck linter.
* etc/guix-install.sh <FUNCNAME>: 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) <ansi_term>: Remove unused variable.
(guix_get_bin) <wget, gpg>: Test the commands directly. Use an array for the
wget arguments, which can then be properly expanded.
(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) <getent>: Test the command directly.
Diffstat (limited to 'etc')
| -rwxr-xr-x | etc/guix-install.sh | 79 |
1 files changed, 37 insertions, 42 deletions
diff --git a/etc/guix-install.sh b/etc/guix-install.sh index 06a3edd1a68..6a8f7a20c1d 100755 --- a/etc/guix-install.sh +++ b/etc/guix-install.sh | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | # Copyright © 2020 Daniel Brooks <db48x@db48x.net> | 9 | # Copyright © 2020 Daniel Brooks <db48x@db48x.net> |
| 10 | # Copyright © 2021 Jakub Kądziołka <kuba@kadziolka.net> | 10 | # Copyright © 2021 Jakub Kądziołka <kuba@kadziolka.net> |
| 11 | # Copyright © 2021 Chris Marusich <cmmarusich@gmail.com> | 11 | # Copyright © 2021 Chris Marusich <cmmarusich@gmail.com> |
| 12 | # Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com> | ||
| 12 | # | 13 | # |
| 13 | # This file is part of GNU Guix. | 14 | # This file is part of GNU Guix. |
| 14 | # | 15 | # |
| @@ -71,11 +72,6 @@ declare -A GPG_SIGNING_KEYS | |||
| 71 | GPG_SIGNING_KEYS[15145]=3CE464558A84FDC69DB40CFB090B11993D9AEBB5 # ludo | 72 | GPG_SIGNING_KEYS[15145]=3CE464558A84FDC69DB40CFB090B11993D9AEBB5 # ludo |
| 72 | GPG_SIGNING_KEYS[127547]=27D586A4F8900854329FF09F1260E46482E63562 # maxim | 73 | GPG_SIGNING_KEYS[127547]=27D586A4F8900854329FF09F1260E46482E63562 # maxim |
| 73 | 74 | ||
| 74 | # This script needs to know where root's home directory is. However, we | ||
| 75 | # cannot simply use the HOME environment variable, since there is no guarantee | ||
| 76 | # that it points to root's home directory. | ||
| 77 | ROOT_HOME="$(echo ~root)" | ||
| 78 | |||
| 79 | # ------------------------------------------------------------------------------ | 75 | # ------------------------------------------------------------------------------ |
| 80 | #+UTILITIES | 76 | #+UTILITIES |
| 81 | 77 | ||
| @@ -102,7 +98,7 @@ chk_require() | |||
| 102 | declare -a warn | 98 | declare -a warn |
| 103 | local c | 99 | local c |
| 104 | 100 | ||
| 105 | _debug "--- [ $FUNCNAME ] ---" | 101 | _debug "--- [ ${FUNCNAME[0]} ] ---" |
| 106 | 102 | ||
| 107 | for c in "$@"; do | 103 | for c in "$@"; do |
| 108 | command -v "$c" &>/dev/null || warn+=("$c") | 104 | command -v "$c" &>/dev/null || warn+=("$c") |
| @@ -117,7 +113,7 @@ chk_require() | |||
| 117 | 113 | ||
| 118 | chk_gpg_keyring() | 114 | chk_gpg_keyring() |
| 119 | { # Check whether the Guix release signing public key is present. | 115 | { # Check whether the Guix release signing public key is present. |
| 120 | _debug "--- [ $FUNCNAME ] ---" | 116 | _debug "--- [ ${FUNCNAME[0]} ] ---" |
| 121 | local user_id | 117 | local user_id |
| 122 | local gpg_key_id | 118 | local gpg_key_id |
| 123 | local exit_flag | 119 | local exit_flag |
| @@ -132,21 +128,19 @@ chk_gpg_keyring() | |||
| 132 | exit_flag=yes | 128 | exit_flag=yes |
| 133 | fi | 129 | fi |
| 134 | done | 130 | done |
| 135 | test "$exit_flag" = yes && exit 1 || true | 131 | if [ "$exit_flag" = yes ]; then |
| 132 | exit 1 | ||
| 133 | fi | ||
| 136 | } | 134 | } |
| 137 | 135 | ||
| 138 | chk_term() | 136 | chk_term() |
| 139 | { # Check for ANSI terminal for color printing. | 137 | { # Check for ANSI terminal for color printing. |
| 140 | local ansi_term | ||
| 141 | |||
| 142 | if [ -t 2 ]; then | 138 | if [ -t 2 ]; then |
| 143 | if [ "${TERM+set}" = 'set' ]; then | 139 | if [ "${TERM+set}" = 'set' ]; then |
| 144 | case "$TERM" in | 140 | case "$TERM" in |
| 145 | xterm*|rxvt*|urxvt*|linux*|vt*|eterm*|screen*) | 141 | xterm*|rxvt*|urxvt*|linux*|vt*|eterm*|screen*) |
| 146 | ansi_term=true | ||
| 147 | ;; | 142 | ;; |
| 148 | *) | 143 | *) |
| 149 | ansi_term=false | ||
| 150 | ERR="[ FAIL ] " | 144 | ERR="[ FAIL ] " |
| 151 | PAS="[ PASS ] " | 145 | PAS="[ PASS ] " |
| 152 | ;; | 146 | ;; |
| @@ -243,7 +237,7 @@ guix_get_bin_list() | |||
| 243 | local latest_ver | 237 | local latest_ver |
| 244 | local default_ver | 238 | local default_ver |
| 245 | 239 | ||
| 246 | _debug "--- [ $FUNCNAME ] ---" | 240 | _debug "--- [ ${FUNCNAME[0]} ] ---" |
| 247 | 241 | ||
| 248 | # Filter only version and architecture | 242 | # Filter only version and architecture |
| 249 | bin_ver_ls=("$(wget -qO- "$gnu_url" \ | 243 | bin_ver_ls=("$(wget -qO- "$gnu_url" \ |
| @@ -272,25 +266,25 @@ guix_get_bin() | |||
| 272 | local url="$1" | 266 | local url="$1" |
| 273 | local bin_ver="$2" | 267 | local bin_ver="$2" |
| 274 | local dl_path="$3" | 268 | local dl_path="$3" |
| 269 | local wget_args=() | ||
| 275 | 270 | ||
| 276 | _debug "--- [ $FUNCNAME ] ---" | 271 | _debug "--- [ ${FUNCNAME[0]} ] ---" |
| 277 | 272 | ||
| 278 | _msg "${INF}Downloading Guix release archive" | 273 | _msg "${INF}Downloading Guix release archive" |
| 279 | 274 | ||
| 280 | wget --help | grep -q '\--show-progress' && \ | 275 | wget --help | grep -q '\--show-progress' \ |
| 281 | _PROGRESS_OPT="-q --show-progress" || _PROGRESS_OPT="" | 276 | && wget_args=("-q" "--show-progress") |
| 282 | wget $_PROGRESS_OPT -P "$dl_path" "${url}/${bin_ver}.tar.xz" "${url}/${bin_ver}.tar.xz.sig" | ||
| 283 | 277 | ||
| 284 | if [[ "$?" -eq 0 ]]; then | 278 | if wget "${wget_args[@]}" -P "$dl_path" \ |
| 285 | _msg "${PAS}download completed." | 279 | "${url}/${bin_ver}.tar.xz" "${url}/${bin_ver}.tar.xz.sig"; then |
| 280 | _msg "${PAS}download completed." | ||
| 286 | else | 281 | else |
| 287 | _err "${ERR}could not download ${url}/${bin_ver}.tar.xz." | 282 | _err "${ERR}could not download ${url}/${bin_ver}.tar.xz." |
| 288 | exit 1 | 283 | exit 1 |
| 289 | fi | 284 | fi |
| 290 | 285 | ||
| 291 | pushd "${dl_path}" >/dev/null | 286 | pushd "${dl_path}" >/dev/null |
| 292 | gpg --verify "${bin_ver}.tar.xz.sig" >/dev/null 2>&1 | 287 | if gpg --verify "${bin_ver}.tar.xz.sig" >/dev/null 2>&1; then |
| 293 | if [[ "$?" -eq 0 ]]; then | ||
| 294 | _msg "${PAS}Signature is valid." | 288 | _msg "${PAS}Signature is valid." |
| 295 | popd >/dev/null | 289 | popd >/dev/null |
| 296 | else | 290 | else |
| @@ -304,7 +298,7 @@ sys_create_store() | |||
| 304 | local pkg="$1" | 298 | local pkg="$1" |
| 305 | local tmp_path="$2" | 299 | local tmp_path="$2" |
| 306 | 300 | ||
| 307 | _debug "--- [ $FUNCNAME ] ---" | 301 | _debug "--- [ ${FUNCNAME[0]} ] ---" |
| 308 | 302 | ||
| 309 | cd "$tmp_path" | 303 | cd "$tmp_path" |
| 310 | tar --extract \ | 304 | tar --extract \ |
| @@ -321,28 +315,29 @@ sys_create_store() | |||
| 321 | fi | 315 | fi |
| 322 | 316 | ||
| 323 | _msg "${INF}Linking the root user's profile" | 317 | _msg "${INF}Linking the root user's profile" |
| 324 | mkdir -p "${ROOT_HOME}/.config/guix" | 318 | mkdir -p "~root/.config/guix" |
| 325 | ln -sf /var/guix/profiles/per-user/root/current-guix \ | 319 | ln -sf /var/guix/profiles/per-user/root/current-guix \ |
| 326 | "${ROOT_HOME}/.config/guix/current" | 320 | "~root/.config/guix/current" |
| 327 | 321 | ||
| 328 | GUIX_PROFILE="${ROOT_HOME}/.config/guix/current" | 322 | GUIX_PROFILE="~root/.config/guix/current" |
| 323 | # shellcheck disable=SC1090 | ||
| 329 | source "${GUIX_PROFILE}/etc/profile" | 324 | source "${GUIX_PROFILE}/etc/profile" |
| 330 | _msg "${PAS}activated root profile at ${ROOT_HOME}/.config/guix/current" | 325 | _msg "${PAS}activated root profile at ${GUIX_PROFILE}" |
| 331 | } | 326 | } |
| 332 | 327 | ||
| 333 | sys_create_build_user() | 328 | sys_create_build_user() |
| 334 | { # Create the group and user accounts for build users. | 329 | { # Create the group and user accounts for build users. |
| 335 | 330 | ||
| 336 | _debug "--- [ $FUNCNAME ] ---" | 331 | _debug "--- [ ${FUNCNAME[0]} ] ---" |
| 337 | 332 | ||
| 338 | if [ $(getent group guixbuild) ]; then | 333 | if getent group guixbuild > /dev/null; then |
| 339 | _msg "${INF}group guixbuild exists" | 334 | _msg "${INF}group guixbuild exists" |
| 340 | else | 335 | else |
| 341 | groupadd --system guixbuild | 336 | groupadd --system guixbuild |
| 342 | _msg "${PAS}group <guixbuild> created" | 337 | _msg "${PAS}group <guixbuild> created" |
| 343 | fi | 338 | fi |
| 344 | 339 | ||
| 345 | if [ $(getent group kvm) ]; then | 340 | if getent group kvm > /dev/null; then |
| 346 | _msg "${INF}group kvm exists and build users will be added to it" | 341 | _msg "${INF}group kvm exists and build users will be added to it" |
| 347 | local KVMGROUP=,kvm | 342 | local KVMGROUP=,kvm |
| 348 | fi | 343 | fi |
| @@ -371,7 +366,7 @@ sys_enable_guix_daemon() | |||
| 371 | local local_bin | 366 | local local_bin |
| 372 | local var_guix | 367 | local var_guix |
| 373 | 368 | ||
| 374 | _debug "--- [ $FUNCNAME ] ---" | 369 | _debug "--- [ ${FUNCNAME[0]} ] ---" |
| 375 | 370 | ||
| 376 | info_path="/usr/local/share/info" | 371 | info_path="/usr/local/share/info" |
| 377 | local_bin="/usr/local/bin" | 372 | local_bin="/usr/local/bin" |
| @@ -380,7 +375,7 @@ sys_enable_guix_daemon() | |||
| 380 | case "$INIT_SYS" in | 375 | case "$INIT_SYS" in |
| 381 | upstart) | 376 | upstart) |
| 382 | { initctl reload-configuration; | 377 | { initctl reload-configuration; |
| 383 | cp "${ROOT_HOME}/.config/guix/current/lib/upstart/system/guix-daemon.conf" \ | 378 | cp "~root/.config/guix/current/lib/upstart/system/guix-daemon.conf" \ |
| 384 | /etc/init/ && | 379 | /etc/init/ && |
| 385 | start guix-daemon; } && | 380 | start guix-daemon; } && |
| 386 | _msg "${PAS}enabled Guix daemon via upstart" | 381 | _msg "${PAS}enabled Guix daemon via upstart" |
| @@ -389,15 +384,15 @@ sys_enable_guix_daemon() | |||
| 389 | { # systemd .mount units must be named after the target directory. | 384 | { # systemd .mount units must be named after the target directory. |
| 390 | # Here we assume a hard-coded name of /gnu/store. | 385 | # Here we assume a hard-coded name of /gnu/store. |
| 391 | # XXX Work around <https://issues.guix.gnu.org/41356> until next release. | 386 | # XXX Work around <https://issues.guix.gnu.org/41356> until next release. |
| 392 | if [ -f "${ROOT_HOME}/.config/guix/current/lib/systemd/system/gnu-store.mount" ]; then | 387 | if [ -f "~root/.config/guix/current/lib/systemd/system/gnu-store.mount" ]; then |
| 393 | cp "${ROOT_HOME}/.config/guix/current/lib/systemd/system/gnu-store.mount" \ | 388 | cp "~root/.config/guix/current/lib/systemd/system/gnu-store.mount" \ |
| 394 | /etc/systemd/system/; | 389 | /etc/systemd/system/; |
| 395 | chmod 664 /etc/systemd/system/gnu-store.mount; | 390 | chmod 664 /etc/systemd/system/gnu-store.mount; |
| 396 | systemctl daemon-reload && | 391 | systemctl daemon-reload && |
| 397 | systemctl enable gnu-store.mount; | 392 | systemctl enable gnu-store.mount; |
| 398 | fi | 393 | fi |
| 399 | 394 | ||
| 400 | cp "${ROOT_HOME}/.config/guix/current/lib/systemd/system/guix-daemon.service" \ | 395 | cp "~root/.config/guix/current/lib/systemd/system/guix-daemon.service" \ |
| 401 | /etc/systemd/system/; | 396 | /etc/systemd/system/; |
| 402 | chmod 664 /etc/systemd/system/guix-daemon.service; | 397 | chmod 664 /etc/systemd/system/guix-daemon.service; |
| 403 | 398 | ||
| @@ -418,7 +413,7 @@ sys_enable_guix_daemon() | |||
| 418 | ;; | 413 | ;; |
| 419 | sysv-init) | 414 | sysv-init) |
| 420 | { mkdir -p /etc/init.d; | 415 | { mkdir -p /etc/init.d; |
| 421 | cp "${ROOT_HOME}/.config/guix/current/etc/init.d/guix-daemon" \ | 416 | cp "~root/.config/guix/current/etc/init.d/guix-daemon" \ |
| 422 | /etc/init.d/guix-daemon; | 417 | /etc/init.d/guix-daemon; |
| 423 | chmod 775 /etc/init.d/guix-daemon; | 418 | chmod 775 /etc/init.d/guix-daemon; |
| 424 | 419 | ||
| @@ -429,7 +424,7 @@ sys_enable_guix_daemon() | |||
| 429 | ;; | 424 | ;; |
| 430 | openrc) | 425 | openrc) |
| 431 | { mkdir -p /etc/init.d; | 426 | { mkdir -p /etc/init.d; |
| 432 | cp "${ROOT_HOME}/.config/guix/current/etc/openrc/guix-daemon" \ | 427 | cp "~root/.config/guix/current/etc/openrc/guix-daemon" \ |
| 433 | /etc/init.d/guix-daemon; | 428 | /etc/init.d/guix-daemon; |
| 434 | chmod 775 /etc/init.d/guix-daemon; | 429 | chmod 775 /etc/init.d/guix-daemon; |
| 435 | 430 | ||
| @@ -439,7 +434,7 @@ sys_enable_guix_daemon() | |||
| 439 | ;; | 434 | ;; |
| 440 | NA|*) | 435 | NA|*) |
| 441 | _msg "${ERR}unsupported init system; run the daemon manually:" | 436 | _msg "${ERR}unsupported init system; run the daemon manually:" |
| 442 | echo " ${ROOT_HOME}/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild" | 437 | echo " ~root/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild" |
| 443 | ;; | 438 | ;; |
| 444 | esac | 439 | esac |
| 445 | 440 | ||
| @@ -457,9 +452,9 @@ sys_enable_guix_daemon() | |||
| 457 | sys_authorize_build_farms() | 452 | sys_authorize_build_farms() |
| 458 | { # authorize the public key of the build farm | 453 | { # authorize the public key of the build farm |
| 459 | while true; do | 454 | while true; do |
| 460 | read -p "Permit downloading pre-built package binaries from the project's build farm? (yes/no) " yn | 455 | read -rp "Permit downloading pre-built package binaries from the project's build farm? (yes/no) " yn |
| 461 | case $yn in | 456 | case $yn in |
| 462 | [Yy]*) guix archive --authorize < "${ROOT_HOME}/.config/guix/current/share/guix/ci.guix.gnu.org.pub" && | 457 | [Yy]*) guix archive --authorize < "~root/.config/guix/current/share/guix/ci.guix.gnu.org.pub" && |
| 463 | _msg "${PAS}Authorized public key for ci.guix.gnu.org"; | 458 | _msg "${PAS}Authorized public key for ci.guix.gnu.org"; |
| 464 | break;; | 459 | break;; |
| 465 | [Nn]*) _msg "${INF}Skipped authorizing build farm public keys" | 460 | [Nn]*) _msg "${INF}Skipped authorizing build farm public keys" |
| @@ -470,7 +465,7 @@ sys_authorize_build_farms() | |||
| 470 | } | 465 | } |
| 471 | 466 | ||
| 472 | sys_create_init_profile() | 467 | sys_create_init_profile() |
| 473 | { # Create /etc/profile.d/guix.sh for better desktop integration | 468 | { # Define for better desktop integration |
| 474 | # This will not take effect until the next shell or desktop session! | 469 | # This will not take effect until the next shell or desktop session! |
| 475 | [ -d "/etc/profile.d" ] || mkdir /etc/profile.d # Just in case | 470 | [ -d "/etc/profile.d" ] || mkdir /etc/profile.d # Just in case |
| 476 | cat <<"EOF" > /etc/profile.d/guix.sh | 471 | cat <<"EOF" > /etc/profile.d/guix.sh |
| @@ -544,7 +539,7 @@ This script installs GNU Guix on your system | |||
| 544 | https://www.gnu.org/software/guix/ | 539 | https://www.gnu.org/software/guix/ |
| 545 | EOF | 540 | EOF |
| 546 | echo -n "Press return to continue..." | 541 | echo -n "Press return to continue..." |
| 547 | read -r ANSWER | 542 | read -r |
| 548 | } | 543 | } |
| 549 | 544 | ||
| 550 | main() | 545 | main() |
| @@ -574,7 +569,7 @@ main() | |||
| 574 | if ! [[ $GUIX_BINARY_FILE_NAME =~ $ARCH_OS ]]; then | 569 | if ! [[ $GUIX_BINARY_FILE_NAME =~ $ARCH_OS ]]; then |
| 575 | _err "$ARCH_OS not in ${GUIX_BINARY_FILE_NAME}; aborting" | 570 | _err "$ARCH_OS not in ${GUIX_BINARY_FILE_NAME}; aborting" |
| 576 | fi | 571 | fi |
| 577 | _msg "Using manually provided binary ${GUIX_BINARY_FILE_NAME}" | 572 | _msg "${INF}Using manually provided binary ${GUIX_BINARY_FILE_NAME}" |
| 578 | GUIX_BINARY_FILE_NAME=$(realpath "$GUIX_BINARY_FILE_NAME") | 573 | GUIX_BINARY_FILE_NAME=$(realpath "$GUIX_BINARY_FILE_NAME") |
| 579 | fi | 574 | fi |
| 580 | 575 | ||
