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 # This script needs to know where root's home directory is. However, we
54 # cannot simply use the HOME environment variable, since there is no guarantee
55 # that it points to root's home directory.
56 ROOT_HOME
="$(echo ~root)"
58 # ------------------------------------------------------------------------------
62 { # All errors go to stderr.
63 printf "[%s]: %s\n" "$(date +%s.%3N)" "$1"
67 { # Default message to stdout.
68 printf "[%s]: %s\n" "$(date +%s.%3N)" "$1"
73 if [ "${DEBUG}" = '1' ]; then
74 printf "[%s]: %s\n" "$(date +%s.%3N)" "$1"
80 { # Check that every required command is available.
86 _debug
"--- [ $FUNCNAME ] ---"
88 for c
in ${cmds[@]}; do
89 command -v "$c" &>/dev
/null || warn
+=("$c")
92 [ "${#warn}" -ne 0 ] &&
93 { _err
"${ERR}Missing commands: ${warn[*]}.";
96 _msg
"${PAS}verification of required commands completed"
98 gpg
--list-keys ${OPENPGP_SIGNING_KEY_ID} >/dev
/null
2>&1 ||
(
99 _err
"${ERR}Missing OpenPGP public key. Fetch it with this command:"
100 echo " gpg --keyserver pool.sks-keyservers.net --recv-keys ${OPENPGP_SIGNING_KEY_ID}"
106 { # Check for ANSI terminal for color printing.
110 if [ "${TERM+set}" = 'set' ]; then
112 xterm
*|rxvt
*|urxvt
*|linux
*|vt
*|eterm
*|screen
*)
126 { # Return init system type name.
127 if [[ $
(/sbin
/init
--version 2>/dev
/null
) =~ upstart
]]; then
128 _msg
"${INF}init system is: upstart"
131 elif [[ $
(systemctl
) =~
-\.mount
]]; then
132 _msg
"${INF}init system is: systemd"
135 elif [[ -f /etc
/init.d
/cron
&& ! -h /etc
/init.d
/cron
]]; then
136 _msg
"${INF}init system is: sysv-init"
141 _err
"${ERR}Init system could not be detected."
146 { # Check for operating system and architecture type.
154 i386 | i486 | i686 | i786 | x86
)
157 x86_64 | x86-64 | x64 | amd64
)
167 _err
"${ERR}Unsupported CPU type: ${arch}"
176 _err
"${ERR}Your operation system (${os}) is not supported."
180 ARCH_OS
="${arch}-${os}"
183 # ------------------------------------------------------------------------------
187 { # Scan GNU archive and save list of binaries
193 _debug
"--- [ $FUNCNAME ] ---"
195 # Filter only version and architecture
196 bin_ver_ls
=("$(wget -qO- "$gnu_url" \
197 | sed -n -e 's/.*guix-binary-\([0-9.]*\)\..*.tar.xz.*/\1/p' \
200 latest_ver
="$(echo "$bin_ver_ls" \
201 | grep -oP "([0-9]{1,2}\.
){2}[0-9]{1,2}" \
204 default_ver
="guix-binary-${latest_ver}.${ARCH_OS}"
206 if [[ "${#bin_ver_ls}" -ne "0" ]]; then
207 _msg
"${PAS}Release for your system: ${default_ver}"
209 _err
"${ERR}Could not obtain list of Guix releases."
213 # Use default to download according to the list and local ARCH_OS.
214 BIN_VER
="$default_ver"
218 { # Download and verify binary package.
223 _debug
"--- [ $FUNCNAME ] ---"
225 _msg
"${INF}Downloading Guix release archive"
227 wget
--help |
grep -q '\--show-progress' && \
228 _PROGRESS_OPT
="-q --show-progress" || _PROGRESS_OPT
=""
229 wget
$_PROGRESS_OPT -P "$dl_path" "${url}/${bin_ver}.tar.xz" "${url}/${bin_ver}.tar.xz.sig"
231 if [[ "$?" -eq 0 ]]; then
232 _msg
"${PAS}download completed."
234 _err
"${ERR}could not download ${url}/${bin_ver}.tar.xz."
238 pushd $dl_path >/dev
/null
239 gpg
--verify "${bin_ver}.tar.xz.sig" >/dev
/null
2>&1
240 if [[ "$?" -eq 0 ]]; then
241 _msg
"${PAS}Signature is valid."
244 _err
"${ERR}could not verify the signature."
250 { # Unpack and install /gnu/store and /var/guix
254 _debug
"--- [ $FUNCNAME ] ---"
257 tar --warning=no-timestamp \
260 _msg
"${PAS}unpacked archive"
262 if [[ -e "/var/guix" ||
-e "/gnu" ]]; then
263 _err
"${ERR}A previous Guix installation was found. Refusing to overwrite."
266 _msg
"${INF}Installing /var/guix and /gnu..."
267 mv "${tmp_path}/var/guix" /var
/
268 mv "${tmp_path}/gnu" /
271 _msg
"${INF}Linking the root user's profile"
272 mkdir
-p "${ROOT_HOME}/.config/guix"
273 ln -sf /var
/guix
/profiles
/per-user
/root
/current-guix \
274 "${ROOT_HOME}/.config/guix/current"
276 GUIX_PROFILE
="${ROOT_HOME}/.config/guix/current"
277 source "${GUIX_PROFILE}/etc/profile"
278 _msg
"${PAS}activated root profile at ${ROOT_HOME}/.config/guix/current"
281 sys_create_build_user
()
282 { # Create the group and user accounts for build users.
284 _debug
"--- [ $FUNCNAME ] ---"
286 if [ $
(getent group guixbuild
) ]; then
287 _msg
"${INF}group guixbuild exists"
289 groupadd
--system guixbuild
290 _msg
"${PAS}group <guixbuild> created"
293 for i
in $
(seq -w 1 10); do
294 if id
"guixbuilder${i}" &>/dev
/null
; then
295 _msg
"${INF}user is already in the system, reset"
296 usermod
-g guixbuild
-G guixbuild \
297 -d /var
/empty
-s "$(which nologin)" \
298 -c "Guix build user $i" \
301 useradd
-g guixbuild
-G guixbuild \
302 -d /var
/empty
-s "$(which nologin)" \
303 -c "Guix build user $i" --system \
305 _msg
"${PAS}user added <guixbuilder${i}>"
310 sys_enable_guix_daemon
()
311 { # Run the daemon, and set it to automatically start on boot.
317 _debug
"--- [ $FUNCNAME ] ---"
319 info_path
="/usr/local/share/info"
320 local_bin
="/usr/local/bin"
321 var_guix
="/var/guix/profiles/per-user/root/current-guix"
325 { initctl reload-configuration
;
326 cp "${ROOT_HOME}/.config/guix/current/lib/upstart/system/guix-daemon.conf" \
328 start guix-daemon
; } &&
329 _msg
"${PAS}enabled Guix daemon via upstart"
332 { cp "${ROOT_HOME}/.config/guix/current/lib/systemd/system/guix-daemon.service" \
333 /etc
/systemd
/system
/;
334 chmod 664 /etc
/systemd
/system
/guix-daemon.service
;
335 systemctl daemon-reload
&&
336 systemctl start guix-daemon
&&
337 systemctl
enable guix-daemon
; } &&
338 _msg
"${PAS}enabled Guix daemon via systemd"
341 _msg
"${ERR}unsupported init system; run the daemon manually:"
342 echo " ${ROOT_HOME}/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild"
346 _msg
"${INF}making the guix command available to other users"
348 [ -e "$local_bin" ] || mkdir
-p "$local_bin"
349 ln -sf "${var_guix}/bin/guix" "$local_bin"
351 [ -e "$info_path" ] || mkdir
-p "$info_path"
352 for i
in ${var_guix}/share
/info
/*; do
353 ln -sf "$i" "$info_path"
357 sys_authorize_build_farms
()
358 { # authorize the public keys of the two build farms
360 read -p "Permit downloading pre-built package binaries from the project's build farms? (yes/no) " yn
362 [Yy
]*) guix archive
--authorize < "${ROOT_HOME}/.config/guix/current/share/guix/hydra.gnu.org.pub" &&
363 _msg
"${PAS}Authorized public key for hydra.gnu.org";
364 guix archive
--authorize < "${ROOT_HOME}/.config/guix/current/share/guix/ci.guix.info.pub" &&
365 _msg
"${PAS}Authorized public key for ci.guix.info";
367 [Nn
]*) _msg
"${INF}Skipped authorizing build farm public keys"
369 *) _msg
"Please answer yes or no.";
378 ░░▒▒░░░░░░░░░ ░░░░░░░░░▒▒░░
379 ░░▒▒▒▒▒░░░░░░░ ░░░░░░░▒▒▒▒▒░
380 ░▒▒▒░░▒▒▒▒▒ ░░░░░░░▒▒░
390 _____ _ _ _ _ _____ _
391 / ____| \ | | | | | / ____| (_)
392 | | __| \| | | | | | | __ _ _ ___ __
393 | | |_ | . ' | | | | | | |_ | | | | \ \/ /
394 | |__| | |\ | |__| | | |__| | |_| | |> <
395 \_____|_| \_|\____/ \_____|\__,_|_/_/\_\
397 This script installs GNU Guix on your system
399 https://www.gnu.org/software/guix/
401 echo -n "Press return to continue..."
410 _msg "Starting installation ($(date))"
413 chk_require "${REQUIRE[*]}"
417 _msg "${INF}system is ${ARCH_OS}"
419 tmp_path="$(mktemp -t -d guix.XXX)"
421 guix_get_bin_list "${GNU_URL}"
422 guix_get_bin "${GNU_URL}" "${BIN_VER}" "$tmp_path"
424 sys_create_store "${BIN_VER}.tar.xz" "${tmp_path}"
425 sys_create_build_user
426 sys_enable_guix_daemon
427 sys_authorize_build_farms
429 _msg "${INF}cleaning up ${tmp_path}"
432 _msg "${PAS}Guix has successfully been installed!"
433 _msg "${INF}Run 'info guix' to read the manual."