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/>.
24 [ "$UID" -eq 0 ] ||
{ echo "This script must be run as root."; exit 1; }
45 PAS
=$
'[ \033[32;1mPASS\033[0m ] '
46 ERR
=$
'[ \033[31;1mFAIL\033[0m ] '
50 GNU_URL
="https://alpha.gnu.org/gnu/guix/"
51 OPENPGP_SIGNING_KEY_ID
="3CE464558A84FDC69DB40CFB090B11993D9AEBB5"
53 # ------------------------------------------------------------------------------
57 { # All errors go to stderr.
58 printf "[%s]: %s\n" "$(date +%s.%3N)" "$1"
62 { # Default message to stdout.
63 printf "[%s]: %s\n" "$(date +%s.%3N)" "$1"
68 if [ "${DEBUG}" = '1' ]; then
69 printf "[%s]: %s\n" "$(date +%s.%3N)" "$1"
75 { # Check that every required command is available.
81 _debug
"--- [ $FUNCNAME ] ---"
83 for c
in ${cmds[@]}; do
84 command -v "$c" &>/dev
/null
89 [ "${#warn}" -ne 0 ] &&
90 { _err
"${ERR}Missing commands: ${warn[*]}.";
93 _msg
"${PAS}verification of required commands completed"
95 gpg
--list-keys ${OPENPGP_SIGNING_KEY_ID} >/dev
/null
2>&1 ||
(
96 _err
"${ERR}Missing OpenPGP public key. Fetch it with this command:"
97 echo " gpg --keyserver pgp.mit.edu --recv-keys ${OPENPGP_SIGNING_KEY_ID}"
103 { # Check for ANSI terminal for color printing.
107 if [ "${TERM+set}" = 'set' ]; then
109 xterm
*|rxvt
*|urxvt
*|linux
*|vt
*|eterm
*|screen
*)
123 { # Return init system type name.
124 if [[ $
(/sbin
/init
--version 2>/dev
/null
) =~ upstart
]]; then
125 _msg
"${INF}init system is: upstart"
128 elif [[ $
(systemctl
) =~
-\.mount
]]; then
129 _msg
"${INF}init system is: systemd"
132 elif [[ -f /etc
/init.d
/cron
&& ! -h /etc
/init.d
/cron
]]; then
133 _msg
"${INF}init system is: sysv-init"
138 _err
"${ERR}Init system could not be detected."
143 { # Check for operating system and architecture type.
151 i386 | i486 | i686 | i786 | x86
)
154 x86_64 | x86-64 | x64 | amd64
)
161 _err
"${ERR}Unsupported CPU type: ${arch}"
170 _err
"${ERR}Your operation system (${os}) is not supported."
174 ARCH_OS
="${arch}-${os}"
177 # ------------------------------------------------------------------------------
181 { # Scan GNU archive and save list of binaries
187 _debug
"--- [ $FUNCNAME ] ---"
189 # Filter only version and architecture
190 bin_ver_ls
=("$(wget -qO- "$gnu_url" \
191 | sed -n -e 's/.*guix-binary-\([0-9.]*\)\..*.tar.xz.*/\1/p' \
194 latest_ver
="$(echo "$bin_ver_ls" \
195 | grep -oP "([0-9]{1,2}\.
){2}[0-9]{1,2}" \
198 default_ver
="guix-binary-${latest_ver}.${ARCH_OS}"
200 if [[ "${#bin_ver_ls}" -ne "0" ]]; then
201 _msg
"${PAS}Release for your system: ${default_ver}"
203 _err
"${ERR}Could not obtain list of Guix releases."
207 # Use default to download according to the list and local ARCH_OS.
208 BIN_VER
="$default_ver"
212 { # Download and verify binary package.
217 _debug
"--- [ $FUNCNAME ] ---"
219 _msg
"${INF}Downloading Guix release archive"
221 wget
--help |
grep -q '\--show-progress' && \
222 _PROGRESS_OPT
="-q --show-progress" || _PROGRESS_OPT
=""
223 wget
$_PROGRESS_OPT -P "$dl_path" "${url}/${bin_ver}.tar.xz" "${url}/${bin_ver}.tar.xz.sig"
225 if [[ "$?" -eq 0 ]]; then
226 _msg
"${PAS}download completed."
228 _err
"${ERR}could not download ${url}/${bin_ver}.tar.xz."
232 pushd $dl_path >/dev
/null
233 gpg
--verify "${bin_ver}.tar.xz.sig" >/dev
/null
2>&1
234 if [[ "$?" -eq 0 ]]; then
235 _msg
"${PAS}Signature is valid."
238 _err
"${ERR}could not verify the signature."
244 { # Unpack and install /gnu/store and /var/guix
248 _debug
"--- [ $FUNCNAME ] ---"
251 tar --warning=no-timestamp \
254 _msg
"${PAS}unpacked archive"
256 if [[ -e "/var/guix" ||
-e "/gnu" ]]; then
257 _err
"${ERR}A previous Guix installation was found. Refusing to overwrite."
260 _msg
"${INF}Installing /var/guix and /gnu..."
261 mv "${tmp_path}/var/guix" /var
/
262 mv "${tmp_path}/gnu" /
265 _msg
"${INF}Linking the root user's profile"
266 ln -sf /var
/guix
/profiles
/per-user
/root
/guix-profile \
269 GUIX_PROFILE
="${HOME}/.guix-profile"
270 source "${GUIX_PROFILE}/etc/profile"
271 _msg
"${PAS}activated root profile at /root/.guix-profile"
274 sys_create_build_user
()
275 { # Create the group and user accounts for build users.
277 _debug
"--- [ $FUNCNAME ] ---"
279 if [ $
(getent group guixbuild
) ]; then
280 _msg
"${INF}group guixbuild exists"
282 groupadd
--system guixbuild
283 _msg
"${PAS}group <guixbuild> created"
286 for i
in $
(seq -w 1 10); do
287 if id
"guixbuilder${i}" &>/dev
/null
; then
288 _msg
"${INF}user is already in the system, reset"
289 usermod
-g guixbuild
-G guixbuild \
290 -d /var
/empty
-s "$(which nologin)" \
291 -c "Guix build user $i" \
294 useradd
-g guixbuild
-G guixbuild \
295 -d /var
/empty
-s "$(which nologin)" \
296 -c "Guix build user $i" --system \
298 _msg
"${PAS}user added <guixbuilder${i}>"
303 sys_enable_guix_daemon
()
304 { # Run the daemon, and set it to automatically start on boot.
310 _debug
"--- [ $FUNCNAME ] ---"
312 info_path
="/usr/local/share/info"
313 local_bin
="/usr/local/bin"
314 var_guix
="/var/guix/profiles/per-user/root/guix-profile"
318 { initctl reload-configuration
;
319 cp ~root
/.guix-profile
/lib
/upstart
/system
/guix-daemon.conf \
321 start guix-daemon
; } &&
322 _msg
"${PAS}enabled Guix daemon via upstart"
325 { cp ~root
/.guix-profile
/lib
/systemd
/system
/guix-daemon.service \
326 /etc
/systemd
/system
/;
327 chmod 664 /etc
/systemd
/system
/guix-daemon.service
;
328 systemctl daemon-reload
&&
329 systemctl start guix-daemon
&&
330 systemctl
enable guix-daemon
; } &&
331 _msg
"${PAS}enabled Guix daemon via systemd"
334 _msg
"${ERR}unsupported init system; run the daemon manually:"
335 echo " ~root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild"
339 _msg
"${INF}making the guix command available to other users"
341 [ -e "$local_bin" ] || mkdir
-p "$local_bin"
342 ln -sf "${var_guix}/bin/guix" "$local_bin"
344 [ -e "$info_path" ] || mkdir
-p "$info_path"
345 for i
in ${var_guix}/share
/info
/*; do
346 ln -sf "$i" "$info_path"
350 sys_authorize_build_farms
()
351 { # authorize the public keys of the two build farms
353 read -p "Permit downloading pre-built package binaries from the project's build farms? (yes/no) " yn
355 [Yy
]*) guix archive
--authorize < ~root
/.guix-profile
/share
/guix
/hydra.gnu.org.pub
&&
356 _msg
"${PAS}Authorized public key for hydra.gnu.org";
357 guix archive
--authorize < ~root
/.guix-profile
/share
/guix
/berlin.guixsd.org.pub
&&
358 _msg
"${PAS}Authorized public key for berlin.guixsd.org";
360 [Nn
]*) _msg
"${INF}Skipped authorizing build farm public keys"
362 *) _msg
"Please answer yes or no.";
371 ░░▒▒░░░░░░░░░ ░░░░░░░░░▒▒░░
372 ░░▒▒▒▒▒░░░░░░░ ░░░░░░░▒▒▒▒▒░
373 ░▒▒▒░░▒▒▒▒▒ ░░░░░░░▒▒░
383 _____ _ _ _ _ _____ _
384 / ____| \ | | | | | / ____| (_)
385 | | __| \| | | | | | | __ _ _ ___ __
386 | | |_ | . ' | | | | | | |_ | | | | \ \/ /
387 | |__| | |\ | |__| | | |__| | |_| | |> <
388 \_____|_| \_|\____/ \_____|\__,_|_/_/\_\
390 This script installs GNU Guix on your system
392 https://www.gnu.org/software/guix/
394 echo -n "Press return to continue..."
403 _msg "Starting installation ($(date))"
406 chk_require "${REQUIRE[*]}"
410 _msg "${INF}system is ${ARCH_OS}"
412 tmp_path="$(mktemp -t -d guix.XXX)"
414 guix_get_bin_list "${GNU_URL}"
415 guix_get_bin "${GNU_URL}" "${BIN_VER}" "$tmp_path"
417 sys_create_store "${BIN_VER}.tar.xz" "${tmp_path}"
418 sys_create_build_user
419 sys_enable_guix_daemon
420 sys_authorize_build_farms
422 _msg "${INF}cleaning up ${tmp_path}"
425 _msg "${PAS}Guix has successfully been installed!"
426 _msg "${INF}Run 'info guix' to read the manual."