X-Git-Url: https://git.hcoop.net/jackhill/guix/guix.git/blobdiff_plain/30484be05d9e318e89e12f40a55c65766cec700a..cabac732deffafc796537658a6c33c6c4aec821e:/etc/guix-install.sh diff --git a/etc/guix-install.sh b/etc/guix-install.sh index aa95cb4e20..eb7205a261 100755 --- a/etc/guix-install.sh +++ b/etc/guix-install.sh @@ -3,6 +3,8 @@ # Copyright © 2017 sharlatan # Copyright © 2018 Ricardo Wurmus # Copyright © 2018 Efraim Flashner +# Copyright © 2019, 2020 Tobias Geerinckx-Rice +# Copyright © 2020 Morgan Smith # # This file is part of GNU Guix. # @@ -47,6 +49,7 @@ REQUIRE=( "groupadd" "tail" "tr" + "xz" ) PAS=$'[ \033[32;1mPASS\033[0m ] ' @@ -85,14 +88,12 @@ _debug() chk_require() { # Check that every required command is available. - declare -a cmds declare -a warn - - cmds=(${1}) + local c _debug "--- [ $FUNCNAME ] ---" - for c in ${cmds[@]}; do + for c in "$@"; do command -v "$c" &>/dev/null || warn+=("$c") done @@ -101,10 +102,17 @@ chk_require() return 1; } _msg "${PAS}verification of required commands completed" +} - gpg --list-keys ${OPENPGP_SIGNING_KEY_ID} >/dev/null 2>&1 || ( +chk_gpg_keyring() +{ # Check whether the Guix release signing public key is present. + _debug "--- [ $FUNCNAME ] ---" + + # Without --dry-run this command will create a ~/.gnupg owned by root on + # systems where gpg has never been used, causing errors and confusion. + gpg --dry-run --list-keys ${OPENPGP_SIGNING_KEY_ID} >/dev/null 2>&1 || ( _err "${ERR}Missing OpenPGP public key. Fetch it with this command:" - echo " wget https://sv.gnu.org/people/viewgpg.php?user_id=15145 -qO - | gpg --import -" + echo " wget 'https://sv.gnu.org/people/viewgpg.php?user_id=15145' -qO - | sudo -i gpg --import -" exit 1 ) } @@ -135,7 +143,7 @@ chk_init_sys() _msg "${INF}init system is: upstart" INIT_SYS="upstart" return 0 - elif [[ $(systemctl) =~ -\.mount ]]; then + elif [[ $(systemctl 2>/dev/null) =~ -\.mount ]]; then _msg "${INF}init system is: systemd" INIT_SYS="systemd" return 0 @@ -143,6 +151,10 @@ chk_init_sys() _msg "${INF}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" + INIT_SYS="openrc" + return 0 else INIT_SYS="NA" _err "${ERR}Init system could not be detected." @@ -205,7 +217,7 @@ guix_get_bin_list() | sort -Vu)") latest_ver="$(echo "$bin_ver_ls" \ - | grep -oP "([0-9]{1,2}\.){2}[0-9]{1,2}" \ + | grep -oE "([0-9]{1,2}\.){2}[0-9]{1,2}" \ | tail -n1)" default_ver="guix-binary-${latest_ver}.${ARCH_OS}" @@ -261,8 +273,7 @@ sys_create_store() _debug "--- [ $FUNCNAME ] ---" cd "$tmp_path" - tar --warning=no-timestamp \ - --extract \ + tar --extract \ --file "$pkg" && _msg "${PAS}unpacked archive" @@ -336,14 +347,57 @@ sys_enable_guix_daemon() _msg "${PAS}enabled Guix daemon via upstart" ;; systemd) - { cp "${ROOT_HOME}/.config/guix/current/lib/systemd/system/guix-daemon.service" \ + { # systemd .mount units must be named after the target directory. + # Here we assume a hard-coded name of /gnu/store. + # XXX Work around until next release. + if [ -f "${ROOT_HOME}/.config/guix/current/lib/systemd/system/gnu-store.mount" ]; then + cp "${ROOT_HOME}/.config/guix/current/lib/systemd/system/gnu-store.mount" \ + /etc/systemd/system/; + chmod 664 /etc/systemd/system/gnu-store.mount; + systemctl daemon-reload && + systemctl enable gnu-store.mount; + fi + + cp "${ROOT_HOME}/.config/guix/current/lib/systemd/system/guix-daemon.service" \ /etc/systemd/system/; chmod 664 /etc/systemd/system/guix-daemon.service; + + # Work around , present in 1.0.1. + sed -i /etc/systemd/system/guix-daemon.service \ + -e "s/GUIX_LOCPATH='/'GUIX_LOCPATH=/"; + + # Work around , present in 1.0.1. + if ! grep en_US /etc/systemd/system/guix-daemon.service >/dev/null; + then sed -i /etc/systemd/system/guix-daemon.service \ + -e 's/^Environment=\(.*\)$/Environment=\1 LC_ALL=en_US.UTF-8'; + fi; + systemctl daemon-reload && - systemctl start guix-daemon && - systemctl enable guix-daemon; } && + systemctl enable guix-daemon && + systemctl start guix-daemon; } && _msg "${PAS}enabled Guix daemon via systemd" ;; + sysv-init) + { mkdir -p /etc/init.d; + cp "${ROOT_HOME}/.config/guix/current/etc/init.d/guix-daemon" \ + /etc/init.d/guix-daemon; + chmod 775 /etc/init.d/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" + ;; + openrc) + { mkdir -p /etc/init.d; + cp "${ROOT_HOME}/.config/guix/current/etc/openrc/guix-daemon" \ + /etc/init.d/guix-daemon; + chmod 775 /etc/init.d/guix-daemon; + + rc-update add guix-daemon default && + rc-service guix-daemon start; } && + _msg "${PAS}enabled Guix daemon via OpenRC" + ;; NA|*) _msg "${ERR}unsupported init system; run the daemon manually:" echo " ${ROOT_HOME}/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild" @@ -376,6 +430,35 @@ sys_authorize_build_farms() done } +sys_create_init_profile() +{ # Create /etc/profile.d/guix.sh for better desktop integration + # This will not take effect until the next shell or desktop session! + [ -d "/etc/profile.d" ] || mkdir /etc/profile.d # Just in case + cat <<"EOF" > /etc/profile.d/guix.sh +# _GUIX_PROFILE: `guix pull` profile +_GUIX_PROFILE="$HOME/.config/guix/current" +if [ -L $_GUIX_PROFILE ]; then + export PATH="$_GUIX_PROFILE/bin${PATH:+:}$PATH" + # Export INFOPATH so that the updated info pages can be found + # and read by both /usr/bin/info and/or $GUIX_PROFILE/bin/info + # When INFOPATH is unset, add a trailing colon so that Emacs + # searches 'Info-default-directory-list'. + export INFOPATH="$_GUIX_PROFILE/share/info:$INFOPATH" +fi + +# GUIX_PROFILE: User's default profile +GUIX_PROFILE="$HOME/.guix-profile" +[ -L $GUIX_PROFILE ] || return +GUIX_LOCPATH="$GUIX_PROFILE/lib/locale" +export GUIX_PROFILE GUIX_LOCPATH + +[ -f "$GUIX_PROFILE/etc/profile" ] && . "$GUIX_PROFILE/etc/profile" + +# set XDG_DATA_DIRS to include Guix installations +export XDG_DATA_DIRS="$GUIX_PROFILE/share:${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/}" +EOF +} + welcome() { cat<<"EOF" @@ -415,12 +498,14 @@ main() _msg "Starting installation ($(date))" chk_term - chk_require "${REQUIRE[*]}" + chk_require "${REQUIRE[@]}" + chk_gpg_keyring chk_init_sys chk_sys_arch _msg "${INF}system is ${ARCH_OS}" + umask 0022 tmp_path="$(mktemp -t -d guix.XXX)" guix_get_bin_list "${GNU_URL}" @@ -430,12 +515,16 @@ main() sys_create_build_user sys_enable_guix_daemon sys_authorize_build_farms + sys_create_init_profile _msg "${INF}cleaning up ${tmp_path}" rm -r "${tmp_path}" _msg "${PAS}Guix has successfully been installed!" _msg "${INF}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." } main "$@"