2 # GNU Guix --- Functional package management for GNU
3 # Copyright © 2017 sharlatan <sharlatanus@gmail.com>
4 # Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
5 # Copyright © 2018 Efraim Flashner <efraim@flashner.co.il>
6 # Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
8 # This file is part of GNU Guix.
10 # GNU Guix is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or (at
13 # your option) any later version.
15 # GNU Guix is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
23 # We require Bash but for portability we'd rather not use /bin/bash or
24 # /usr/bin/env in the shebang, hence this hack.
25 if [ "x$BASH_VERSION" = "x" ]
32 [ "$UID" -eq 0 ] ||
{ echo "This script must be run as root."; exit 1; }
53 PAS
=$
'[ \033[32;1mPASS\033[0m ] '
54 ERR
=$
'[ \033[31;1mFAIL\033[0m ] '
58 GNU_URL
="https://ftp.gnu.org/gnu/guix/"
59 OPENPGP_SIGNING_KEY_ID
="3CE464558A84FDC69DB40CFB090B11993D9AEBB5"
61 # This script needs to know where root's home directory is. However, we
62 # cannot simply use the HOME environment variable, since there is no guarantee
63 # that it points to root's home directory.
64 ROOT_HOME
="$(echo ~root)"
66 # ------------------------------------------------------------------------------
70 { # All errors go to stderr.
71 printf "[%s]: %s\n" "$(date +%s.%3N)" "$1"
75 { # Default message to stdout.
76 printf "[%s]: %s\n" "$(date +%s.%3N)" "$1"
81 if [ "${DEBUG}" = '1' ]; then
82 printf "[%s]: %s\n" "$(date +%s.%3N)" "$1"
88 { # Check that every required command is available.
92 _debug
"--- [ $FUNCNAME ] ---"
95 command -v "$c" &>/dev
/null || warn
+=("$c")
98 [ "${#warn}" -ne 0 ] &&
99 { _err
"${ERR}Missing commands: ${warn[*]}.";
102 _msg
"${PAS}verification of required commands completed"
106 { # Check whether the Guix release signing public key is present.
107 _debug
"--- [ $FUNCNAME ] ---"
109 # Without --dry-run this command will create a ~/.gnupg owned by root on
110 # systems where gpg has never been used, causing errors and confusion.
111 gpg
--dry-run --list-keys ${OPENPGP_SIGNING_KEY_ID} >/dev
/null
2>&1 ||
(
112 _err
"${ERR}Missing OpenPGP public key. Fetch it with this command:"
113 echo " wget https://sv.gnu.org/people/viewgpg.php?user_id=15145 -qO - | gpg --import -"
119 { # Check for ANSI terminal for color printing.
123 if [ "${TERM+set}" = 'set' ]; then
125 xterm
*|rxvt
*|urxvt
*|linux
*|vt
*|eterm
*|screen
*)
139 { # Return init system type name.
140 if [[ $
(/sbin
/init
--version 2>/dev
/null
) =~ upstart
]]; then
141 _msg
"${INF}init system is: upstart"
144 elif [[ $
(systemctl
) =~
-\.mount
]]; then
145 _msg
"${INF}init system is: systemd"
148 elif [[ -f /etc
/init.d
/cron
&& ! -h /etc
/init.d
/cron
]]; then
149 _msg
"${INF}init system is: sysv-init"
154 _err
"${ERR}Init system could not be detected."
159 { # Check for operating system and architecture type.
167 i386 | i486 | i686 | i786 | x86
)
170 x86_64 | x86-64 | x64 | amd64
)
180 _err
"${ERR}Unsupported CPU type: ${arch}"
189 _err
"${ERR}Your operation system (${os}) is not supported."
193 ARCH_OS
="${arch}-${os}"
196 # ------------------------------------------------------------------------------
200 { # Scan GNU archive and save list of binaries
206 _debug
"--- [ $FUNCNAME ] ---"
208 # Filter only version and architecture
209 bin_ver_ls
=("$(wget -qO- "$gnu_url" \
210 | sed -n -e 's/.*guix-binary-\([0-9.]*\)\..*.tar.xz.*/\1/p' \
213 latest_ver
="$(echo "$bin_ver_ls" \
214 | grep -oP "([0-9]{1,2}\.
){2}[0-9]{1,2}" \
217 default_ver
="guix-binary-${latest_ver}.${ARCH_OS}"
219 if [[ "${#bin_ver_ls}" -ne "0" ]]; then
220 _msg
"${PAS}Release for your system: ${default_ver}"
222 _err
"${ERR}Could not obtain list of Guix releases."
226 # Use default to download according to the list and local ARCH_OS.
227 BIN_VER
="$default_ver"
231 { # Download and verify binary package.
236 _debug
"--- [ $FUNCNAME ] ---"
238 _msg
"${INF}Downloading Guix release archive"
240 wget
--help |
grep -q '\--show-progress' && \
241 _PROGRESS_OPT
="-q --show-progress" || _PROGRESS_OPT
=""
242 wget
$_PROGRESS_OPT -P "$dl_path" "${url}/${bin_ver}.tar.xz" "${url}/${bin_ver}.tar.xz.sig"
244 if [[ "$?" -eq 0 ]]; then
245 _msg
"${PAS}download completed."
247 _err
"${ERR}could not download ${url}/${bin_ver}.tar.xz."
251 pushd $dl_path >/dev
/null
252 gpg
--verify "${bin_ver}.tar.xz.sig" >/dev
/null
2>&1
253 if [[ "$?" -eq 0 ]]; then
254 _msg
"${PAS}Signature is valid."
257 _err
"${ERR}could not verify the signature."
263 { # Unpack and install /gnu/store and /var/guix
267 _debug
"--- [ $FUNCNAME ] ---"
270 tar --warning=no-timestamp \
273 _msg
"${PAS}unpacked archive"
275 if [[ -e "/var/guix" ||
-e "/gnu" ]]; then
276 _err
"${ERR}A previous Guix installation was found. Refusing to overwrite."
279 _msg
"${INF}Installing /var/guix and /gnu..."
280 mv "${tmp_path}/var/guix" /var
/
281 mv "${tmp_path}/gnu" /
284 _msg
"${INF}Linking the root user's profile"
285 mkdir
-p "${ROOT_HOME}/.config/guix"
286 ln -sf /var
/guix
/profiles
/per-user
/root
/current-guix \
287 "${ROOT_HOME}/.config/guix/current"
289 GUIX_PROFILE
="${ROOT_HOME}/.config/guix/current"
290 source "${GUIX_PROFILE}/etc/profile"
291 _msg
"${PAS}activated root profile at ${ROOT_HOME}/.config/guix/current"
294 sys_create_build_user
()
295 { # Create the group and user accounts for build users.
297 _debug
"--- [ $FUNCNAME ] ---"
299 if [ $
(getent group guixbuild
) ]; then
300 _msg
"${INF}group guixbuild exists"
302 groupadd
--system guixbuild
303 _msg
"${PAS}group <guixbuild> created"
306 for i
in $
(seq -w 1 10); do
307 if id
"guixbuilder${i}" &>/dev
/null
; then
308 _msg
"${INF}user is already in the system, reset"
309 usermod
-g guixbuild
-G guixbuild \
310 -d /var
/empty
-s "$(which nologin)" \
311 -c "Guix build user $i" \
314 useradd
-g guixbuild
-G guixbuild \
315 -d /var
/empty
-s "$(which nologin)" \
316 -c "Guix build user $i" --system \
318 _msg
"${PAS}user added <guixbuilder${i}>"
323 sys_enable_guix_daemon
()
324 { # Run the daemon, and set it to automatically start on boot.
330 _debug
"--- [ $FUNCNAME ] ---"
332 info_path
="/usr/local/share/info"
333 local_bin
="/usr/local/bin"
334 var_guix
="/var/guix/profiles/per-user/root/current-guix"
338 { initctl reload-configuration
;
339 cp "${ROOT_HOME}/.config/guix/current/lib/upstart/system/guix-daemon.conf" \
341 start guix-daemon
; } &&
342 _msg
"${PAS}enabled Guix daemon via upstart"
345 { cp "${ROOT_HOME}/.config/guix/current/lib/systemd/system/guix-daemon.service" \
346 /etc
/systemd
/system
/;
347 chmod 664 /etc
/systemd
/system
/guix-daemon.service
;
348 systemctl daemon-reload
&&
349 systemctl start guix-daemon
&&
350 systemctl
enable guix-daemon
; } &&
351 _msg
"${PAS}enabled Guix daemon via systemd"
354 _msg
"${ERR}unsupported init system; run the daemon manually:"
355 echo " ${ROOT_HOME}/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild"
359 _msg
"${INF}making the guix command available to other users"
361 [ -e "$local_bin" ] || mkdir
-p "$local_bin"
362 ln -sf "${var_guix}/bin/guix" "$local_bin"
364 [ -e "$info_path" ] || mkdir
-p "$info_path"
365 for i
in ${var_guix}/share
/info
/*; do
366 ln -sf "$i" "$info_path"
370 sys_authorize_build_farms
()
371 { # authorize the public key of the build farm
373 read -p "Permit downloading pre-built package binaries from the project's build farm? (yes/no) " yn
375 [Yy
]*) guix archive
--authorize < "${ROOT_HOME}/.config/guix/current/share/guix/ci.guix.gnu.org.pub" &&
376 _msg
"${PAS}Authorized public key for ci.guix.gnu.org";
378 [Nn
]*) _msg
"${INF}Skipped authorizing build farm public keys"
380 *) _msg
"Please answer yes or no.";
389 ░░▒▒░░░░░░░░░ ░░░░░░░░░▒▒░░
390 ░░▒▒▒▒▒░░░░░░░ ░░░░░░░▒▒▒▒▒░
391 ░▒▒▒░░▒▒▒▒▒ ░░░░░░░▒▒░
401 _____ _ _ _ _ _____ _
402 / ____| \ | | | | | / ____| (_)
403 | | __| \| | | | | | | __ _ _ ___ __
404 | | |_ | . ' | | | | | | |_ | | | | \ \/ /
405 | |__| | |\ | |__| | | |__| | |_| | |> <
406 \_____|_| \_|\____/ \_____|\__,_|_/_/\_\
408 This script installs GNU Guix on your system
410 https://www.gnu.org/software/guix/
412 echo -n "Press return to continue..."
421 _msg "Starting installation ($(date))"
424 chk_require "${REQUIRE[@]}"
429 _msg "${INF}system is ${ARCH_OS}"
431 tmp_path="$(mktemp -t -d guix.XXX)"
433 guix_get_bin_list "${GNU_URL}"
434 guix_get_bin "${GNU_URL}" "${BIN_VER}" "$tmp_path"
436 sys_create_store "${BIN_VER}.tar.xz" "${tmp_path}"
437 sys_create_build_user
438 sys_enable_guix_daemon
439 sys_authorize_build_farms
441 _msg "${INF}cleaning up ${tmp_path}"
444 _msg "${PAS}Guix has successfully been installed!"
445 _msg "${INF}Run 'info guix' to read the manual."