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>
7 # This file is part of GNU Guix.
9 # GNU Guix is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or (at
12 # your option) any later version.
14 # GNU Guix is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22 # We require Bash but for portability we'd rather not use /bin/bash or
23 # /usr/bin/env in the shebang, hence this hack.
24 if [ "x$BASH_VERSION" = "x" ]
31 [ "$UID" -eq 0 ] ||
{ echo "This script must be run as root."; exit 1; }
52 PAS
=$
'[ \033[32;1mPASS\033[0m ] '
53 ERR
=$
'[ \033[31;1mFAIL\033[0m ] '
57 GNU_URL
="https://ftp.gnu.org/gnu/guix/"
58 OPENPGP_SIGNING_KEY_ID
="3CE464558A84FDC69DB40CFB090B11993D9AEBB5"
60 # This script needs to know where root's home directory is. However, we
61 # cannot simply use the HOME environment variable, since there is no guarantee
62 # that it points to root's home directory.
63 ROOT_HOME
="$(echo ~root)"
65 # ------------------------------------------------------------------------------
69 { # All errors go to stderr.
70 printf "[%s]: %s\n" "$(date +%s.%3N)" "$1"
74 { # Default message to stdout.
75 printf "[%s]: %s\n" "$(date +%s.%3N)" "$1"
80 if [ "${DEBUG}" = '1' ]; then
81 printf "[%s]: %s\n" "$(date +%s.%3N)" "$1"
87 { # Check that every required command is available.
93 _debug
"--- [ $FUNCNAME ] ---"
95 for c
in ${cmds[@]}; do
96 command -v "$c" &>/dev
/null || warn
+=("$c")
99 [ "${#warn}" -ne 0 ] &&
100 { _err
"${ERR}Missing commands: ${warn[*]}.";
103 _msg
"${PAS}verification of required commands completed"
105 gpg
--list-keys ${OPENPGP_SIGNING_KEY_ID} >/dev
/null
2>&1 ||
(
106 _err
"${ERR}Missing OpenPGP public key. Fetch it with this command:"
107 echo " gpg --keyserver pool.sks-keyservers.net --recv-keys ${OPENPGP_SIGNING_KEY_ID}"
113 { # Check for ANSI terminal for color printing.
117 if [ "${TERM+set}" = 'set' ]; then
119 xterm
*|rxvt
*|urxvt
*|linux
*|vt
*|eterm
*|screen
*)
133 { # Return init system type name.
134 if [[ $
(/sbin
/init
--version 2>/dev
/null
) =~ upstart
]]; then
135 _msg
"${INF}init system is: upstart"
138 elif [[ $
(systemctl
) =~
-\.mount
]]; then
139 _msg
"${INF}init system is: systemd"
142 elif [[ -f /etc
/init.d
/cron
&& ! -h /etc
/init.d
/cron
]]; then
143 _msg
"${INF}init system is: sysv-init"
148 _err
"${ERR}Init system could not be detected."
153 { # Check for operating system and architecture type.
161 i386 | i486 | i686 | i786 | x86
)
164 x86_64 | x86-64 | x64 | amd64
)
174 _err
"${ERR}Unsupported CPU type: ${arch}"
183 _err
"${ERR}Your operation system (${os}) is not supported."
187 ARCH_OS
="${arch}-${os}"
190 # ------------------------------------------------------------------------------
194 { # Scan GNU archive and save list of binaries
200 _debug
"--- [ $FUNCNAME ] ---"
202 # Filter only version and architecture
203 bin_ver_ls
=("$(wget -qO- "$gnu_url" \
204 | sed -n -e 's/.*guix-binary-\([0-9.]*\)\..*.tar.xz.*/\1/p' \
207 latest_ver
="$(echo "$bin_ver_ls" \
208 | grep -oP "([0-9]{1,2}\.
){2}[0-9]{1,2}" \
211 default_ver
="guix-binary-${latest_ver}.${ARCH_OS}"
213 if [[ "${#bin_ver_ls}" -ne "0" ]]; then
214 _msg
"${PAS}Release for your system: ${default_ver}"
216 _err
"${ERR}Could not obtain list of Guix releases."
220 # Use default to download according to the list and local ARCH_OS.
221 BIN_VER
="$default_ver"
225 { # Download and verify binary package.
230 _debug
"--- [ $FUNCNAME ] ---"
232 _msg
"${INF}Downloading Guix release archive"
234 wget
--help |
grep -q '\--show-progress' && \
235 _PROGRESS_OPT
="-q --show-progress" || _PROGRESS_OPT
=""
236 wget
$_PROGRESS_OPT -P "$dl_path" "${url}/${bin_ver}.tar.xz" "${url}/${bin_ver}.tar.xz.sig"
238 if [[ "$?" -eq 0 ]]; then
239 _msg
"${PAS}download completed."
241 _err
"${ERR}could not download ${url}/${bin_ver}.tar.xz."
245 pushd $dl_path >/dev
/null
246 gpg
--verify "${bin_ver}.tar.xz.sig" >/dev
/null
2>&1
247 if [[ "$?" -eq 0 ]]; then
248 _msg
"${PAS}Signature is valid."
251 _err
"${ERR}could not verify the signature."
257 { # Unpack and install /gnu/store and /var/guix
261 _debug
"--- [ $FUNCNAME ] ---"
264 tar --warning=no-timestamp \
267 _msg
"${PAS}unpacked archive"
269 if [[ -e "/var/guix" ||
-e "/gnu" ]]; then
270 _err
"${ERR}A previous Guix installation was found. Refusing to overwrite."
273 _msg
"${INF}Installing /var/guix and /gnu..."
274 mv "${tmp_path}/var/guix" /var
/
275 mv "${tmp_path}/gnu" /
278 _msg
"${INF}Linking the root user's profile"
279 mkdir
-p "${ROOT_HOME}/.config/guix"
280 ln -sf /var
/guix
/profiles
/per-user
/root
/current-guix \
281 "${ROOT_HOME}/.config/guix/current"
283 GUIX_PROFILE
="${ROOT_HOME}/.config/guix/current"
284 source "${GUIX_PROFILE}/etc/profile"
285 _msg
"${PAS}activated root profile at ${ROOT_HOME}/.config/guix/current"
288 sys_create_build_user
()
289 { # Create the group and user accounts for build users.
291 _debug
"--- [ $FUNCNAME ] ---"
293 if [ $
(getent group guixbuild
) ]; then
294 _msg
"${INF}group guixbuild exists"
296 groupadd
--system guixbuild
297 _msg
"${PAS}group <guixbuild> created"
300 for i
in $
(seq -w 1 10); do
301 if id
"guixbuilder${i}" &>/dev
/null
; then
302 _msg
"${INF}user is already in the system, reset"
303 usermod
-g guixbuild
-G guixbuild \
304 -d /var
/empty
-s "$(which nologin)" \
305 -c "Guix build user $i" \
308 useradd
-g guixbuild
-G guixbuild \
309 -d /var
/empty
-s "$(which nologin)" \
310 -c "Guix build user $i" --system \
312 _msg
"${PAS}user added <guixbuilder${i}>"
317 sys_enable_guix_daemon
()
318 { # Run the daemon, and set it to automatically start on boot.
324 _debug
"--- [ $FUNCNAME ] ---"
326 info_path
="/usr/local/share/info"
327 local_bin
="/usr/local/bin"
328 var_guix
="/var/guix/profiles/per-user/root/current-guix"
332 { initctl reload-configuration
;
333 cp "${ROOT_HOME}/.config/guix/current/lib/upstart/system/guix-daemon.conf" \
335 start guix-daemon
; } &&
336 _msg
"${PAS}enabled Guix daemon via upstart"
339 { cp "${ROOT_HOME}/.config/guix/current/lib/systemd/system/guix-daemon.service" \
340 /etc
/systemd
/system
/;
341 chmod 664 /etc
/systemd
/system
/guix-daemon.service
;
342 systemctl daemon-reload
&&
343 systemctl start guix-daemon
&&
344 systemctl
enable guix-daemon
; } &&
345 _msg
"${PAS}enabled Guix daemon via systemd"
348 _msg
"${ERR}unsupported init system; run the daemon manually:"
349 echo " ${ROOT_HOME}/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild"
353 _msg
"${INF}making the guix command available to other users"
355 [ -e "$local_bin" ] || mkdir
-p "$local_bin"
356 ln -sf "${var_guix}/bin/guix" "$local_bin"
358 [ -e "$info_path" ] || mkdir
-p "$info_path"
359 for i
in ${var_guix}/share
/info
/*; do
360 ln -sf "$i" "$info_path"
364 sys_authorize_build_farms
()
365 { # authorize the public keys of the two build farms
367 read -p "Permit downloading pre-built package binaries from the project's build farms? (yes/no) " yn
369 [Yy
]*) guix archive
--authorize < "${ROOT_HOME}/.config/guix/current/share/guix/hydra.gnu.org.pub" &&
370 _msg
"${PAS}Authorized public key for hydra.gnu.org";
371 guix archive
--authorize < "${ROOT_HOME}/.config/guix/current/share/guix/ci.guix.info.pub" &&
372 _msg
"${PAS}Authorized public key for ci.guix.info";
374 [Nn
]*) _msg
"${INF}Skipped authorizing build farm public keys"
376 *) _msg
"Please answer yes or no.";
385 ░░▒▒░░░░░░░░░ ░░░░░░░░░▒▒░░
386 ░░▒▒▒▒▒░░░░░░░ ░░░░░░░▒▒▒▒▒░
387 ░▒▒▒░░▒▒▒▒▒ ░░░░░░░▒▒░
397 _____ _ _ _ _ _____ _
398 / ____| \ | | | | | / ____| (_)
399 | | __| \| | | | | | | __ _ _ ___ __
400 | | |_ | . ' | | | | | | |_ | | | | \ \/ /
401 | |__| | |\ | |__| | | |__| | |_| | |> <
402 \_____|_| \_|\____/ \_____|\__,_|_/_/\_\
404 This script installs GNU Guix on your system
406 https://www.gnu.org/software/guix/
408 echo -n "Press return to continue..."
417 _msg "Starting installation ($(date))"
420 chk_require "${REQUIRE[*]}"
424 _msg "${INF}system is ${ARCH_OS}"
426 tmp_path="$(mktemp -t -d guix.XXX)"
428 guix_get_bin_list "${GNU_URL}"
429 guix_get_bin "${GNU_URL}" "${BIN_VER}" "$tmp_path"
431 sys_create_store "${BIN_VER}.tar.xz" "${tmp_path}"
432 sys_create_build_user
433 sys_enable_guix_daemon
434 sys_authorize_build_farms
436 _msg "${INF}cleaning up ${tmp_path}"
439 _msg "${PAS}Guix has successfully been installed!"
440 _msg "${INF}Run 'info guix' to read the manual."