Content-Security-Policy: default-src 'none'
Content-Type: text/plain; charset=UTF-8
Content-Length: 19941
Content-Disposition: inline; filename="php.scm"
Last-Modified: Sat, 16 Nov 2024 13:38:21 GMT
Expires: Tue, 14 Nov 2034 13:38:21 GMT
ETag: "c7e6fcb6e97c717e051d272e663bf8fbc2cb4f81"

;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016 Julien Lepiller <julien@lepiller.eu>
;;; Copyright © 2016 Marius Bakke <mbakke@fastmail.com>
;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2019 Oleg Pykhalov <go.wigust@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see </td></tr></table>
<table class='tabs'><tr><td>
<a class='active' href='/guix/about/'>about</a><a href='/guix/'>summary</a><a href='/guix/refs/?id=a1b16662bcabd6086a5e9d4d14688d148e3c1406'>refs</a><a href='/guix/log/'>log</a><a href='/guix/tree/?id=a1b16662bcabd6086a5e9d4d14688d148e3c1406'>tree</a><a href='/guix/commit/?id=a1b16662bcabd6086a5e9d4d14688d148e3c1406'>commit</a><a href='/guix/diff/?id=a1b16662bcabd6086a5e9d4d14688d148e3c1406'>diff</a></td><td class='form'><form class='right' method='get' action='/guix/log/'>
<input type='hidden' name='id' value='a1b16662bcabd6086a5e9d4d14688d148e3c1406'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='content'><div id='summary'><pre>
#!/bin/sh
# GNU Guix --- Functional package management for GNU
# Copyright © 2017 sharlatan &lt;sharlatanus@gmail.com&gt;
# Copyright © 2018 Ricardo Wurmus &lt;rekado@elephly.net&gt;
# Copyright © 2018 Efraim Flashner &lt;efraim@flashner.co.il&gt;
# Copyright © 2019–2020, 2022 Tobias Geerinckx-Rice &lt;me@tobias.gr&gt;
# Copyright © 2020 Morgan Smith &lt;Morgan.J.Smith@outlook.com&gt;
# Copyright © 2020 Simon Tournier &lt;zimon.toutoune@gmail.com&gt;
# Copyright © 2020 Daniel Brooks &lt;db48x@db48x.net&gt;
# Copyright © 2021 Jakub Kądziołka &lt;kuba@kadziolka.net&gt;
# Copyright © 2021 Chris Marusich &lt;cmmarusich@gmail.com&gt;
# Copyright © 2021, 2022, 2023 Maxim Cournoyer &lt;maxim.cournoyer@gmail.com&gt;
# Copyright © 2022 Prafulla Giri &lt;prafulla.giri@protonmail.com&gt;
# Copyright © 2023 Andrew Tropin &lt;andrew@trop.in&gt;
# Copyright © 2020 David A. Redick &lt;david.a.redick@gmail.com&gt;
# Copyright © 2024 Janneke Nieuwenhuizen &lt;janneke@gnu.org&gt;
# Copyright © 2024 Tomas Volf &lt;~@wolfsden.cz&gt;
# Copyright © 2024 Richard Sent &lt;richard@freakingpenguin.com&gt;
#
# This file is part of GNU Guix.
#
# GNU Guix is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.
#
# GNU Guix is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Guix.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

# We require Bash but for portability we&apos;d rather not use /bin/bash or
# /usr/bin/env in the shebang, hence this hack.

# Environment variables
#
# GUIX_BINARY_FILE_NAME
#
# Can be used to override the automatic download mechanism and point
# to a local Guix binary archive filename like
# &quot;/tmp/guix-binary-1.4.0rc2.armhf-linux.tar.xz&quot;
#
# GUIX_ALLOW_OVERWRITE
#
# Instead of aborting to avoid overwriting a previous installations,
# allow copying over /var/guix or /gnu.  This can be useful when the
# installation required the user to extract Guix packs under /gnu to
# satisfy its dependencies.

if [ &quot;x$BASH_VERSION&quot; = &quot;x&quot; ]
then
    exec bash &quot;$0&quot; &quot;$@&quot;
fi

set -eo pipefail

[ &quot;$UID&quot; -eq 0 ] || { echo &quot;This script must be run as root.&quot;; exit 1; }

REQUIRE=(
    &quot;dirname&quot;
    &quot;readlink&quot;
    &quot;wget&quot;
    &quot;gpg&quot;
    &quot;grep&quot;
    &quot;which&quot;
    &quot;sed&quot;
    &quot;sort&quot;
    &quot;getent&quot;
    &quot;mktemp&quot;
    &quot;rm&quot;
    &quot;chmod&quot;
    &quot;uname&quot;
    &quot;groupadd&quot;
    &quot;groupdel&quot;
    &quot;useradd&quot;
    &quot;userdel&quot;
    &quot;tail&quot;
    &quot;tr&quot;
    &quot;xz&quot;
)

# Add variables using form FOO_INIT_REQUIRE when init system FOO dependencies
# should be checked.
SYSV_INIT_REQUIRE=(
    &quot;daemonize&quot;
)

PAS=$&apos;[ \033[32;1mPASS\033[0m ] &apos;
ERR=$&apos;[ \033[31;1mFAIL\033[0m ] &apos;
WAR=$&apos;[ \033[33;1mWARN\033[0m ] &apos;
INF=&quot;[ INFO ] &quot;

DEBUG=0
GNU_URL=&quot;https://ftp.gnu.org/gnu/guix/&quot;
#GNU_URL=&quot;https://alpha.gnu.org/gnu/guix/&quot;

# The following associative array holds set of GPG keys used to sign the
# releases, keyed by their corresponding Savannah user ID.
declare -A GPG_SIGNING_KEYS
GPG_SIGNING_KEYS[15145]=3CE464558A84FDC69DB40CFB090B11993D9AEBB5  # ludo
GPG_SIGNING_KEYS[127547]=27D586A4F8900854329FF09F1260E46482E63562 # maxim

# ------------------------------------------------------------------------------
#+UTILITIES

_err()
{ # All errors go to stderr.
    printf &quot;[%s]: %s\n&quot; &quot;$(date +%s.%3N)&quot; &quot;$1&quot;
}

_msg()
{ # Default message to stdout.
    printf &quot;[%s]: %s\n&quot; &quot;$(date +%s.%3N)&quot; &quot;$1&quot;
}

_debug()
{
    if [ &quot;${DEBUG}&quot; = &apos;1&apos; ]; then
        printf &quot;[%s]: %s\n&quot; &quot;$(date +%s.%3N)&quot; &quot;$1&quot;
    fi
}

die()
{
    _err &quot;${ERR}$*&quot;
    exit 1
}

# Return true if user answered yes, false otherwise.  The prompt is
# yes-biased, that is, when the user simply enter newline, it is equivalent to
# answering &quot;yes&quot;.
# $1: The prompt question.
prompt_yes_no() {
    local -l yn
    read -rp &quot;$1 [Y/n]&quot; yn
    [[ ! $yn || $yn = y || $yn = yes ]] || return 1
}

chk_require()
{ # Check that every required command is available.
    declare -a warn
    local c

    _debug &quot;--- [ ${FUNCNAME[0]} ] ---&quot;

    for c in &quot;$@&quot;; do
        command -v &quot;$c&quot; &amp;&gt;/dev/null || warn+=(&quot;$c&quot;)
    done

    [ &quot;${#warn}&quot; -ne 0 ] &amp;&amp; die &quot;Missing commands: ${warn[*]}.&quot;

    _msg &quot;${PAS}verification of required commands completed&quot;
}

add_init_sys_require()
{ # Add the elements of FOO_INIT_SYS to REQUIRE
    local init_require=&quot;${INIT_SYS}_REQUIRE[@]&quot;
    if [[ ! -z &quot;$init_require&quot; ]]; then
        # Have to add piecemeal because ${!foo[@]} performs direct array key
        # expansion, not indirect plain array expansion.
        for r in &quot;${!init_require}&quot;; do
            REQUIRE+=(&quot;$r&quot;)
        done
    fi
}

chk_gpg_keyring()
{ # Check whether the Guix release signing public key is present.
    _debug &quot;--- [ ${FUNCNAME[0]} ] ---&quot;
    local user_id
    local gpg_key_id
    local exit_flag

    for user_id in &quot;${!GPG_SIGNING_KEYS[@]}&quot;; do
        gpg_key_id=${GPG_SIGNING_KEYS[$user_id]}
        # Without --dry-run this command will create a ~/.gnupg owned by root on
        # systems where gpg has never been used, causing errors and confusion.
        if gpg --dry-run --list-keys &quot;$gpg_key_id&quot; &gt;/dev/null 2&gt;&amp;1; then
            continue
        fi
        if prompt_yes_no &quot;${INF}The following OpenPGP public key is \
required to verify the Guix binary signature: $gpg_key_id.
Would you like me to fetch it for you?&quot;; then
            # Use a reasonable time-out here so users don&apos;t report silent
            # ‘freezes’ when Savannah goes out to lunch, as has happened.
            if wget &quot;https://sv.gnu.org/people/viewgpg.php?user_id=$user_id&quot; \
                    --timeout=30 --no-verbose -O- | gpg --import -; then
                continue
            fi
        fi
	# If we reach this point, the key is (still) missing.  Report further
	# missing keys, if any, but then abort the installation.
        _err &quot;${ERR}Missing OpenPGP public key ($gpg_key_id).
Fetch it with this command:

  wget \&quot;https://sv.gnu.org/people/viewgpg.php?user_id=$user_id\&quot; -O - | \
sudo -i gpg --import -&quot;
        exit_flag=yes
    done
    if [ &quot;$exit_flag&quot; = yes ]; then
        exit 1
    fi
}

chk_term()
{ # Check for ANSI terminal for color printing.
    if [ -t 2 ]; then
        if [ &quot;${TERM+set}&quot; = &apos;set&apos; ]; then
            case &quot;$TERM&quot; in
                xterm*|rxvt*|urxvt*|linux*|vt*|eterm*|screen*)
                    ;;
                *)
                    ERR=&quot;[ FAIL ] &quot;
                    PAS=&quot;[ PASS ] &quot;
                    WAR=&quot;[ WARN ] &quot;
                    ;;
            esac
        fi
    fi
}

chk_init_sys()
{ # Return init system type name.
    if [[ $(/sbin/init --version 2&gt;/dev/null) =~ upstart ]]; then
        _msg &quot;${INF}init system is: upstart&quot;
        INIT_SYS=&quot;upstart&quot;
        return 0
    elif [[ $(systemctl 2&gt;/dev/null) =~ -\.mount ]]; then
        _msg &quot;${INF}init system is: systemd&quot;
        INIT_SYS=&quot;systemd&quot;
        return 0
    elif [[ -f /etc/init.d/cron &amp;&amp; ! -h /etc/init.d/cron ]]; then
        _msg &quot;${INF}init system is: sysv-init&quot;
        INIT_SYS=&quot;sysv-init&quot;
        return 0
    elif [[ $(openrc --version 2&gt;/dev/null) =~ \(OpenRC ]]; then
        _msg &quot;${INF}init system is: OpenRC&quot;
        INIT_SYS=&quot;openrc&quot;
        return 0
    else
        INIT_SYS=&quot;NA&quot;
        _err &quot;${ERR}Init system could not be detected.&quot;
    fi
}

chk_sys_arch()
{ # Check for operating system and architecture type.
    local os
    local arch

    os=&quot;$(uname -s)&quot;
    arch=&quot;$(uname -m)&quot;

    case &quot;$arch&quot; in
        i386 | i486 | i686 | i786 | x86)
            local arch=i686
            ;;
        x86_64 | x86-64 | x64 | amd64)
            local arch=x86_64
            ;;
        aarch64)
            local arch=aarch64
            ;;
        armv7l)
            local arch=armhf
            ;;
        ppc64le | powerpc64le)
            local arch=powerpc64le
            ;;
        *)
            die &quot;Unsupported CPU type: ${arch}&quot;
    esac

    case &quot;$os&quot; in
        Linux | linux)
            local os=linux
            ;;
        *)
            die &quot;Your operation system (${os}) is not supported.&quot;
    esac

    ARCH_OS=&quot;${arch}-${os}&quot;
}

chk_sys_nscd()
{ # Check if nscd is up and suggest to start it or install it
    if [ &quot;$(type -P pidof)&quot; ]; then
        if [ ! &quot;$(pidof nscd)&quot; ]; then
            _msg &quot;${WAR}We recommend installing and/or starting your distribution &apos;nscd&apos; service&quot;
            _msg &quot;${WAR}Please read &apos;info guix \&quot;Application Setup\&quot;&apos; about \&quot;Name Service Switch\&quot;&quot;
        fi
    else
        _msg &quot;${INF}We cannot determine if your distribution &apos;nscd&apos; service is running&quot;
        _msg &quot;${INF}Please read &apos;info guix \&quot;Application Setup\&quot;&apos; about \&quot;Name Service Switch\&quot;&quot;
    fi
}

# Configure substitute discovery according to user&apos;s preferences.
# $1 is the installed service file to edit.
configure_substitute_discovery() {
    if grep -q -- &apos;--discover=no&apos; &quot;$1&quot; &amp;&amp; \
            prompt_yes_no &quot;Would you like the Guix daemon to automatically \
discover substitute servers on the local network?&quot;; then
        sed -i &apos;s/--discover=no/--discover=yes/&apos; &quot;$1&quot;
    fi
}

# ------------------------------------------------------------------------------
#+MAIN

guix_get_bin_list()
{ # Scan GNU archive and save list of binaries
    local gnu_url=&quot;$1&quot;
    local -a bin_ver_ls
    local latest_ver
    local default_ver

    _debug &quot;--- [ ${FUNCNAME[0]} ] ---&quot;

    # Filter only version and architecture
    bin_ver_ls=(&quot;$(wget &quot;$gnu_url&quot; --no-verbose -O- \
        | sed -n -e &apos;s/.*guix-binary-\([0-9.]*[a-z0-9]*\)\..*.tar.xz.*/\1/p&apos; \
        | sort -Vu)&quot;)

    latest_ver=&quot;$(echo &quot;${bin_ver_ls[0]}&quot; \
                       | grep -oE &quot;([0-9]{1,2}\.){2}[0-9]{1,2}[a-z0-9]*&quot; \
                       | tail -n1)&quot;

    default_ver=&quot;guix-binary-${latest_ver}.${ARCH_OS}&quot;

    if [[ &quot;${#bin_ver_ls}&quot; -ne &quot;0&quot; ]]; then
        _msg &quot;${PAS}Release for your system: ${default_ver}&quot;
    else
        die &quot;Could not obtain list of Guix releases.&quot;
    fi

    # Use default to download according to the list and local ARCH_OS.
    BIN_VER=&quot;${default_ver}&quot;
}

guix_get_bin()
{ # Download and verify binary package.
    local url=&quot;$1&quot;
    local bin_ver=&quot;$2&quot;
    local dl_path=&quot;$3&quot;
    local wget_args=()

    _debug &quot;--- [ ${FUNCNAME[0]} ] ---&quot;

    _msg &quot;${INF}Downloading Guix release archive&quot;

    wget --help | grep -q &apos;\--show-progress&apos; \
        &amp;&amp; wget_args=(&quot;--no-verbose&quot; &quot;--show-progress&quot;)

    if wget &quot;${wget_args[@]}&quot; -P &quot;$dl_path&quot; \
            &quot;${url}/${bin_ver}.tar.xz&quot; &quot;${url}/${bin_ver}.tar.xz.sig&quot;; then
        _msg &quot;${PAS}download completed.&quot;
    else
        die &quot;could not download ${url}/${bin_ver}.tar.xz.&quot;
    fi

    pushd &quot;${dl_path}&quot; &gt;/dev/null
    if gpg --verify &quot;${bin_ver}.tar.xz.sig&quot; &gt;/dev/null 2&gt;&amp;1; then
        _msg &quot;${PAS}Signature is valid.&quot;
        popd &gt;/dev/null
    else
        die &quot;could not verify the signature.&quot;
    fi
}

sys_create_store()
{ # Unpack and install /gnu/store and /var/guix
    local pkg=&quot;$1&quot;
    local tmp_path=&quot;$2&quot;

    _debug &quot;--- [ ${FUNCNAME[0]} ] ---&quot;

    if [[ -e /var/guix &amp;&amp; -e /gnu ]]; then
        if [ -n &quot;$GUIX_ALLOW_OVERWRITE&quot; ]; then
            _msg &quot;${WAR}Overwriting existing installation!&quot;
        else
            die &quot;A previous Guix installation was found.  Refusing to overwrite.&quot;
        fi
    fi

    cd &quot;$tmp_path&quot;
    _msg &quot;${INF}Installing /var/guix and /gnu...&quot;
    # Strip (skip) the leading ‘.’ component, which fails on read-only ‘/’.
    tar --extract --strip-components=1 --file &quot;$pkg&quot; -C /

    _msg &quot;${INF}Linking the root user&apos;s profile&quot;
    mkdir -p ~root/.config/guix
    ln -sf /var/guix/profiles/per-user/root/current-guix \
       ~root/.config/guix/current

    GUIX_PROFILE=~root/.config/guix/current
    # shellcheck disable=SC1090
    source &quot;${GUIX_PROFILE}/etc/profile&quot;
    _msg &quot;${PAS}activated root profile at ${GUIX_PROFILE}&quot;
}

sys_delete_store()
{
    _msg &quot;${INF}removing /var/guix&quot;
    rm -rf /var/guix

    _msg &quot;${INF}removing /gnu&quot;
    rm -rf /gnu

    _msg &quot;${INF}removing ${ROOT_HOME}/.config/guix&quot;
    rm -rf ${ROOT_HOME}/.config/guix
}

sys_create_build_user()
{ # Create the group and user accounts for build users.

    _debug &quot;--- [ ${FUNCNAME[0]} ] ---&quot;

    if getent group guixbuild &gt; /dev/null; then
        _msg &quot;${INF}group guixbuild exists&quot;
    else
        groupadd --system guixbuild
        _msg &quot;${PAS}group &lt;guixbuild&gt; created&quot;
    fi

    if getent group kvm &gt; /dev/null; then
        _msg &quot;${INF}group kvm exists and build users will be added to it&quot;
        local KVMGROUP=,kvm
    fi

    for i in $(seq -w 1 10); do
        if id &quot;guixbuilder${i}&quot; &amp;&gt;/dev/null; then
            _msg &quot;${INF}user is already in the system, reset&quot;
            usermod -g guixbuild -G guixbuild${KVMGROUP}     \
                    -d /var/empty -s &quot;$(which nologin)&quot; \
                    -c &quot;Guix build user $i&quot;             \
                    &quot;guixbuilder${i}&quot;;
        else
            useradd -g guixbuild -G guixbuild${KVMGROUP}     \
                    -d /var/empty -s &quot;$(which nologin)&quot; \
                    -c &quot;Guix build user $i&quot; --system    \
                    &quot;guixbuilder${i}&quot;;
            _msg &quot;${PAS}user added &lt;guixbuilder${i}&gt;&quot;
        fi
    done
}

sys_delete_build_user()
{
    for i in $(seq -w 1 10); do
        userdel -f guixbuilder${i}
    done

    _msg &quot;${INF}delete group guixbuild&quot;
    groupdel -f guixbuild
}

sys_enable_guix_daemon()
{ # Run the daemon, and set it to automatically start on boot.

    local info_path
    local local_bin
    local var_guix

    _debug &quot;--- [ ${FUNCNAME[0]} ] ---&quot;

    info_path=&quot;/usr/local/share/info&quot;
    local_bin=&quot;/usr/local/bin&quot;
    var_guix=&quot;/var/guix/profiles/per-user/root/current-guix&quot;

    case &quot;$INIT_SYS&quot; in
        upstart)
            { initctl reload-configuration;
              cp ~root/.config/guix/current/lib/upstart/system/guix-daemon.conf \
                 /etc/init/ &amp;&amp;
                  configure_substitute_discovery /etc/init/guix-daemon.conf &amp;&amp;
                  start guix-daemon; } &amp;&amp;
                _msg &quot;${PAS}enabled Guix daemon via upstart&quot;
            ;;
        systemd)
            { install_unit()
              {
                  local dest=&quot;/etc/systemd/system/$1&quot;
                  rm -f &quot;$dest&quot;
                  cp ~root/.config/guix/current/lib/systemd/system/&quot;$1&quot; &quot;$dest&quot;
                  chmod 664 &quot;$dest&quot;
                  systemctl daemon-reload
                  systemctl enable &quot;$1&quot;
              }

              install_unit guix-daemon.service

              configure_substitute_discovery \
                  /etc/systemd/system/guix-daemon.service

              # Install after guix-daemon.service to avoid a harmless warning.
              # systemd .mount units must be named after the target directory.
              # Here we assume a hard-coded name of /gnu/store.
              install_unit gnu-store.mount

              systemctl daemon-reload &amp;&amp;
                  systemctl start  guix-daemon; } &amp;&amp;
                _msg &quot;${PAS}enabled Guix daemon via systemd&quot;
            ;;
        sysv-init)
            { mkdir -p /etc/init.d;
              cp ~root/.config/guix/current/etc/init.d/guix-daemon \
                 /etc/init.d/guix-daemon;
              chmod 775 /etc/init.d/guix-daemon;

              configure_substitute_discovery /etc/init.d/guix-daemon

              update-rc.d guix-daemon defaults &amp;&amp;
                  update-rc.d guix-daemon enable &amp;&amp;
                  service guix-daemon start; } &amp;&amp;
                _msg &quot;${PAS}enabled Guix daemon via sysv&quot;
            ;;
        openrc)
            { mkdir -p /etc/init.d;
              cp ~root/.config/guix/current/etc/openrc/guix-daemon \
                 /etc/init.d/guix-daemon;
              chmod 775 /etc/init.d/guix-daemon;

              configure_substitute_discovery /etc/init.d/guix-daemon

              rc-update add guix-daemon default &amp;&amp;
                  rc-service guix-daemon start; } &amp;&amp;
                _msg &quot;${PAS}enabled Guix daemon via OpenRC&quot;
            ;;
        NA|*)
            _msg &quot;${ERR}unsupported init system; run the daemon manually:&quot;
            echo &quot;  ~root/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild&quot;
            ;;
    esac

    _msg &quot;${INF}making the guix command available to other users&quot;

    [ -e &quot;$local_bin&quot; ] || mkdir -p &quot;$local_bin&quot;
    ln -sf &quot;${var_guix}/bin/guix&quot;  &quot;$local_bin&quot;

    [ -e &quot;$info_path&quot; ] || mkdir -p &quot;$info_path&quot;
    for i in &quot;${var_guix}&quot;/share/info/*; do
        ln -sf &quot;$i&quot; &quot;$info_path&quot;
    done
}

sys_delete_guix_daemon()
{ # Disabled, stop and remove the various guix daemons.

    local info_path
    local local_bin
    local var_guix

    _debug &quot;--- [ $FUNCNAME ] ---&quot;

    info_path=&quot;/usr/local/share/info&quot;
    local_bin=&quot;/usr/local/bin&quot;


    case &quot;$INIT_SYS&quot; in
        upstart)
            _msg &quot;${INF}stopping guix-daemon&quot;
            stop guix-daemon
            _msg &quot;${INF}removing guix-daemon&quot;
            rm /etc/init/guix-daemon.conf
            ;;

        systemd)
            _msg &quot;${INF}disabling guix-daemon&quot;
            systemctl disable guix-daemon
            _msg &quot;${INF}stopping guix-daemon&quot;
            systemctl stop guix-daemon
            _msg &quot;${INF}removing guix-daemon&quot;
            rm -f /etc/systemd/system/guix-daemon.service

            if [ -x /etc/systemd/system/gnu-store.mount ]; then
                _msg &quot;${INF}disabling gnu-store.mount&quot;
                systemctl disable gnu-store.mount
                _msg &quot;${INF}stopping gnu-store.mount&quot;
                systemctl stop gnu-store.mount
                _msg &quot;${INF}removing gnu-store.mount&quot;
                rm -f /etc/systemd/system/gnu-store.mount
            fi
            systemctl daemon-reload
            ;;

        sysv-init)
            update-rc.d guix-daemon disable
            service guix-daemon stop
            rm -rf /etc/init.d/guix-daemon
            ;;
        NA|*)
            _msg &quot;${ERR}unsupported init system; disable, stop and remove the daemon manually:&quot;
            echo &quot;  ${ROOT_HOME}/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild&quot;
            ;;
    esac


    _msg &quot;${INF}removing $local_bin/guix&quot;
    rm -f &quot;$local_bin&quot;/guix

    _msg &quot;${INF}removing $info_path/guix*&quot;
    rm -f &quot;$info_path&quot;/guix*
}

sys_authorize_build_farms()
{ # authorize the public key(s) of the build farm(s)
    local hosts=(
	bordeaux.guix.gnu.org
	ci.guix.gnu.org
    )

    if prompt_yes_no &quot;Permit downloading pre-built package binaries from the \
project&apos;s build farms?&quot;; then
	for host in &quot;${hosts[@]}&quot;; do
	    local key=~root/.config/guix/current/share/guix/$host.pub
	    [ -f &quot;$key&quot; ] \
		&amp;&amp; guix archive --authorize &lt; &quot;$key&quot; \
		&amp;&amp; _msg &quot;${PAS}Authorized public key for $host&quot;
	done
    else
        _msg &quot;${INF}Skipped authorizing build farm public keys&quot;
    fi
}

sys_create_init_profile()
{ # Define for better desktop integration
  # This will not take effect until the next shell or desktop session!
    [ -d &quot;/etc/profile.d&quot; ] || mkdir /etc/profile.d # Just in case
    cat &lt;&lt;&quot;EOF&quot; &gt; /etc/profile.d/zzz-guix.sh
# Explicitly initialize XDG base directory variables to ease compatibility
# with Guix System: see &lt;https://issues.guix.gnu.org/56050#3&gt;.
export XCURSOR_PATH=&quot;${XCURSOR_PATH:-/usr/local/share/icons:/usr/share/icons}&quot;
export XDG_DATA_HOME=&quot;${XDG_DATA_HOME:-$HOME/.local/share}&quot;
export XDG_CONFIG_HOME=&quot;${XDG_CONFIG_HOME:-$HOME/.config}&quot;
export XDG_STATE_HOME=&quot;${XDG_STATE_HOME:-$HOME/.local/state}&quot;
export XDG_DATA_DIRS=&quot;${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/}&quot;
export XDG_CONFIG_DIRS=&quot;${XDG_CONFIG_DIRS:-/etc/xdg}&quot;
export XDG_CACHE_HOME=&quot;${XDG_CACHE_HOME:-$HOME/.cache}&quot;
# no default for XDG_RUNTIME_DIR (depends on foreign distro for semantics)

# _GUIX_PROFILE: `guix pull` profile
_GUIX_PROFILE=&quot;$HOME/.config/guix/current&quot;
export PATH=&quot;$_GUIX_PROFILE/bin${PATH:+:}$PATH&quot;

# GUIX_PROFILE: User&apos;s default profile and home profile
GUIX_PROFILE=&quot;$HOME/.guix-profile&quot;
[ -f &quot;$GUIX_PROFILE/etc/profile&quot; ] &amp;&amp; . &quot;$GUIX_PROFILE/etc/profile&quot;
[ -L &quot;$GUIX_PROFILE&quot; ] &amp;&amp; \
GUIX_LOCPATH=&quot;$GUIX_PROFILE/lib/locale${GUIX_LOCPATH:+:}$GUIX_LOCPATH&quot;

# 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 &apos;Info-default-directory-list&apos;.
export INFOPATH=&quot;$_GUIX_PROFILE/share/info:$GUIX_PROFILE/share/info:$INFOPATH&quot;

GUIX_PROFILE=&quot;$HOME/.guix-home/profile&quot;
[ -f &quot;$GUIX_PROFILE/etc/profile&quot; ] &amp;&amp; . &quot;$GUIX_PROFILE/etc/profile&quot;
[ -L &quot;$GUIX_PROFILE&quot; ] &amp;&amp; \
GUIX_LOCPATH=&quot;$GUIX_PROFILE/lib/locale${GUIX_LOCPATH:+:}$GUIX_LOCPATH&quot;

export GUIX_LOCPATH

# Make Guix modules available
export GUILE_LOAD_PATH=&quot;$_GUIX_PROFILE/share/guile/site/3.0${GUILE_LOAD_PATH:+:}$GUILE_LOAD_PATH&quot;
export GUILE_LOAD_COMPILED_PATH=&quot;$_GUIX_PROFILE/lib/guile/3.0/site-ccache${GUILE_LOAD_COMPILED_PATH:+:}$GUILE_LOAD_COMPILED_PATH&quot;

EOF
}

sys_create_shell_completion()
{ # Symlink supported shell completions system-wide

    var_guix=/var/guix/profiles/per-user/root/current-guix
    bash_completion=/etc/bash_completion.d
    zsh_completion=/usr/share/zsh/site-functions
    fish_completion=/usr/share/fish/vendor_completions.d

    { # Just in case
        for dir_shell in $bash_completion $zsh_completion $fish_completion; do
            [ -d &quot;$dir_shell&quot; ] || mkdir -p $dir_shell
        done;

        ln -sf ${var_guix}/etc/bash_completion.d/* &quot;$bash_completion&quot;;
        ln -sf ${var_guix}/share/zsh/site-functions/* &quot;$zsh_completion&quot;;
        ln -sf ${var_guix}/share/fish/vendor_completions.d/* &quot;$fish_completion&quot;; } &amp;&amp;
        _msg &quot;${PAS}installed shell completion&quot;
}

sys_customize_bashrc()
{
    prompt_yes_no &quot;Customize users Bash shell prompt for Guix?&quot; || return 0

    for bashrc in /home/*/.bashrc /root/.bashrc; do
        test -f &quot;$bashrc&quot; || continue
        grep -Fq &apos;$GUIX_ENVIRONMENT&apos; &quot;$bashrc&quot; &amp;&amp; continue
        cp &quot;${bashrc}&quot; &quot;${bashrc}.bak&quot;
        echo &apos;
# Automatically added by the Guix install script.
if [ -n &quot;$GUIX_ENVIRONMENT&quot; ]; then
    if [[ $PS1 =~ (.*)&quot;\\$&quot; ]]; then
        PS1=&quot;${BASH_REMATCH[1]} [env]\\\$ &quot;
    fi
fi
&apos; &gt;&gt; &quot;$bashrc&quot;
    done
    _msg &quot;${PAS}Bash shell prompt successfully customized for Guix&quot;
}

sys_maybe_setup_selinux()
{
    if ! [ -f /sys/fs/selinux/policy ]
    then
	return
    fi

    local c
    for c in semodule restorecon
    do
        if ! command -v &quot;$c&quot; &amp;&gt;/dev/null
	then
	    return
	fi
    done

    prompt_yes_no &quot;Install SELinux policy that might be required to run guix-daemon?&quot; \
	|| return 0

    local var_guix=/var/guix/profiles/per-user/root/current-guix
    semodule -i &quot;${var_guix}/share/selinux/guix-daemon.cil&quot;
    restorecon -R /gnu /var/guix
}

sys_delete_init_profile()
{
    _msg &quot;${INF}removing /etc/profile.d/guix.sh&quot;
    rm -f /etc/profile.d/guix.sh
}

sys_delete_user_profiles()
{
    _msg &quot;${INF}removing ${ROOT_HOME}/.guix-profile&quot;
    rm -f ${ROOT_HOME}/.guix-profile
    rm -rf ${ROOT_HOME}/.cache/guix

    _msg &quot;${INF}removing .guix-profile, .cache/guix and .config/guix of all /home users&quot;
    for user in `ls -1 /home`; do
        rm -f /home/$user/.guix-profile
        rm -rf /home/$user/.cache/guix
        rm -rf /home/$user/.config/guix
    done
}

welcome()
{
    local uninstall_flag=&quot;$1&quot;
    local char
    cat&lt;&lt;&quot;EOF&quot;
    ░░░                                     ░░░
    ░░▒▒░░░░░░░░░               ░░░░░░░░░▒▒░░
     ░░▒▒▒▒▒░░░░░░░           ░░░░░░░▒▒▒▒▒░
         ░▒▒▒░░▒▒▒▒▒         ░░░░░░░▒▒░
               ░▒▒▒▒░       ░░░░░░
                ▒▒▒▒▒      ░░░░░░
                 ▒▒▒▒▒     ░░░░░
                 ░▒▒▒▒▒   ░░░░░
                  ▒▒▒▒▒   ░░░░░
                   ▒▒▒▒▒ ░░░░░
                   ░▒▒▒▒▒░░░░░
                    ▒▒▒▒▒▒░░░
                     ▒▒▒▒▒▒░
     _____ _   _ _    _    _____       _
    / ____| \ | | |  | |  / ____|     (_)
   | |  __|  \| | |  | | | |  __ _   _ ___  __
   | | |_ | . &apos; | |  | | | | |_ | | | | \ \/ /
   | |__| | |\  | |__| | | |__| | |_| | |&gt;  &lt;
    \_____|_| \_|\____/   \_____|\__,_|_/_/\_\

https://www.gnu.org/software/guix/
EOF

    if [ &apos;--uninstall&apos; = &quot;$uninstall_flag&quot; ]; then
        echo &quot;${WARN}This script will uninstall GNU Guix from your system&quot;
        echo &quot;To install, run this script with no parameters.&quot;
    else
        echo &quot;This script installs GNU Guix on your system&quot;
        echo &quot;To uninstall, pass in the &apos;--uninstall&apos; parameter.&quot;
    fi

    # Don&apos;t use ‘read -p’ here!  It won&apos;t display when run non-interactively.
    echo -n &quot;Press return to continue...&quot;$&apos;\r&apos;
    if ! read -r char; then
	echo
	die &quot;Can&apos;t read standard input.  Hint: don&apos;t pipe scripts into a shell.&quot;
    fi
    if [ &quot;$char&quot; ]; then
	echo
	echo &quot;...that ($char) was not a return!&quot;
	_msg &quot;${WAR}Use newlines to automate installation, e.g.: yes &apos;&apos; | ${0##*/}&quot;
	_msg &quot;${WAR}Any other method is unsupported and likely to break in future.&quot;
    fi
}

main_install()
{
    local tmp_path
    welcome

    _msg &quot;Starting installation ($(date))&quot;

    chk_term
    chk_init_sys
    add_init_sys_require
    chk_require &quot;${REQUIRE[@]}&quot;
    chk_gpg_keyring
    chk_sys_arch
    chk_sys_nscd

    _msg &quot;${INF}system is ${ARCH_OS}&quot;

    umask 0022
    tmp_path=&quot;$(mktemp -t -d guix.XXXXXX)&quot;

    if [ -z &quot;${GUIX_BINARY_FILE_NAME}&quot; ]; then
        guix_get_bin_list &quot;${GNU_URL}&quot;
        guix_get_bin &quot;${GNU_URL}&quot; &quot;${BIN_VER}&quot; &quot;$tmp_path&quot;
        GUIX_BINARY_FILE_NAME=${BIN_VER}.tar.xz
    else
        if ! [[ $GUIX_BINARY_FILE_NAME =~ $ARCH_OS ]]; then
            _err &quot;$ARCH_OS not in ${GUIX_BINARY_FILE_NAME}; aborting&quot;
        fi
        _msg &quot;${INF}Using manually provided binary ${GUIX_BINARY_FILE_NAME}&quot;
        GUIX_BINARY_FILE_NAME=$(realpath &quot;$GUIX_BINARY_FILE_NAME&quot;)
    fi

    sys_create_store &quot;${GUIX_BINARY_FILE_NAME}&quot; &quot;${tmp_path}&quot;
    sys_create_build_user
    sys_maybe_setup_selinux
    sys_enable_guix_daemon
    sys_authorize_build_farms
    sys_create_init_profile
    sys_create_shell_completion
    sys_customize_bashrc

    _msg &quot;${INF}cleaning up ${tmp_path}&quot;
    rm -r &quot;${tmp_path}&quot;

    _msg &quot;${PAS}Guix has successfully been installed!&quot;
    _msg &quot;${INF}Run &apos;info guix&apos; to read the manual.&quot;

    # Required to source /etc/profile in desktop environments.
    _msg &quot;${INF}Please log out and back in to complete the installation.&quot;
 }

main_uninstall()
{
    welcome --uninstall
    _msg &quot;Starting uninstall process ($(date))&quot;

    chk_term
    chk_require &quot;${REQUIRE[@]}&quot;
    # it&apos;s ok to leave the gpg key
    chk_init_sys
    chk_sys_arch

    _msg &quot;${INF}system is ${ARCH_OS}&quot;

    # stop the build, package system.
    sys_delete_guix_daemon
    # stop people from accessing their profiles.
    sys_delete_user_profiles
    # kill guix off all the guts of guix
    sys_delete_store
    # clean up the system
    sys_delete_init_profile
    sys_delete_build_user

    # these directories are created on the fly during usage.
    _msg &quot;${INF}removing /etc/guix&quot;
    rm -rf /etc/guix
    _msg &quot;${INF}removing /var/log/guix&quot;
    rm -rf /var/log/guix

    _msg &quot;${PAS}Guix has successfully been uninstalled!&quot;
}

main()
{
    # expect no parameters
    # or &apos;--uninstall&apos;
    if [ 0 -eq $# ]; then
        main_install
    else
        local uninstall_flag=&quot;$1&quot;
        if [ &apos;--uninstall&apos; = &quot;${uninstall_flag}&quot; ]; then
            main_uninstall
        else
            echo &quot;unsupported parameters: $@&quot;
            exit 1
        fi
    fi
}

main &quot;$@&quot;
</pre>
</div></div> <!-- class=content -->
                         <div class=footer>generated by
                             <a href="https://git.zx2c4.com/cgit/about/">
                                 cgit
                             </a>
                         </div>
                        </div> <!-- id=cgit -->
</body>
</html>
