From dd476cfb76511063e19ac3e70afd1d5a391b47f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Fri, 5 Apr 2024 14:04:23 +0200 Subject: =?UTF-8?q?guix-install.sh:=20Add=20=E2=80=98--uninstall=E2=80=99?= =?UTF-8?q?=20flag.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * etc/guix-install.sh (REQUIRE): Add groupdel and userdel. (chk_term): Handle ‘WAR’. (sys_delete_store, sys_delete_build_user, sys_delete_guix_daemon) (sys_delete_init_profile, sys_delete_user_profiles): New functions. (main): Rename to… (main_install): … this. (main_uninstall): New function. (main): Dispatch between these two. * doc/guix.texi (Installation): Refer to “Binary Installation” instead of repeating it. (Binary Installation): Document uninstallation. Co-authored-by: Ludovic Courtès Change-Id: I55b7c10823773bced2e268273e8ce828cb3bd98d --- etc/guix-install.sh | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 165 insertions(+), 3 deletions(-) (limited to 'etc') diff --git a/etc/guix-install.sh b/etc/guix-install.sh index dde35e6d39..21441baec4 100755 --- a/etc/guix-install.sh +++ b/etc/guix-install.sh @@ -12,6 +12,7 @@ # Copyright © 2021, 2022, 2023 Maxim Cournoyer # Copyright © 2022 Prafulla Giri # Copyright © 2023 Andrew Tropin +# Copyright © 2020 David A. Redick # # This file is part of GNU Guix. # @@ -70,7 +71,9 @@ REQUIRE=( "chmod" "uname" "groupadd" + "groupdel" "useradd" + "userdel" "tail" "tr" "xz" @@ -191,6 +194,7 @@ chk_term() *) ERR="[ FAIL ] " PAS="[ PASS ] " + WAR="[ WARN ] " ;; esac fi @@ -377,6 +381,18 @@ sys_create_store() _msg "${PAS}activated root profile at ${GUIX_PROFILE}" } +sys_delete_store() +{ + _msg "${INF}removing /var/guix" + rm -rf /var/guix + + _msg "${INF}removing /gnu" + rm -rf /gnu + + _msg "${INF}removing ${ROOT_HOME}/.config/guix" + rm -rf ${ROOT_HOME}/.config/guix +} + sys_create_build_user() { # Create the group and user accounts for build users. @@ -411,6 +427,16 @@ sys_create_build_user() done } +sys_delete_build_user() +{ + for i in $(seq -w 1 10); do + userdel -f guixbuilder${i} + done + + _msg "${INF}delete group guixbuild" + groupdel -f guixbuild +} + sys_enable_guix_daemon() { # Run the daemon, and set it to automatically start on boot. @@ -500,6 +526,65 @@ sys_enable_guix_daemon() done } +sys_delete_guix_daemon() +{ # Disabled, stop and remove the various guix daemons. + + local info_path + local local_bin + local var_guix + + _debug "--- [ $FUNCNAME ] ---" + + info_path="/usr/local/share/info" + local_bin="/usr/local/bin" + + + case "$INIT_SYS" in + upstart) + _msg "${INF}stopping guix-daemon" + stop guix-daemon + _msg "${INF}removing guix-daemon" + rm /etc/init/guix-daemon.conf + ;; + + systemd) + _msg "${INF}disabling guix-daemon" + systemctl disable guix-daemon + _msg "${INF}stopping guix-daemon" + systemctl stop guix-daemon + _msg "${INF}removing guix-daemon" + rm -f /etc/systemd/system/guix-daemon.service + + if [ -x /etc/systemd/system/gnu-store.mount ]; then + _msg "${INF}disabling gnu-store.mount" + systemctl disable gnu-store.mount + _msg "${INF}stopping gnu-store.mount" + systemctl stop gnu-store.mount + _msg "${INF}removing gnu-store.mount" + 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 "${ERR}unsupported init system; disable, stop and remove the daemon manually:" + echo " ${ROOT_HOME}/.config/guix/current/bin/guix-daemon --build-users-group=guixbuild" + ;; + esac + + + _msg "${INF}removing $local_bin/guix" + rm -f "$local_bin"/guix + + _msg "${INF}removing $info_path/guix*" + rm -f "$info_path"/guix* +} + sys_authorize_build_farms() { # authorize the public key(s) of the build farm(s) local hosts=( @@ -623,8 +708,29 @@ sys_maybe_setup_selinux() restorecon -R /gnu /var/guix } +sys_delete_init_profile() +{ + _msg "${INF}removing /etc/profile.d/guix.sh" + rm -f /etc/profile.d/guix.sh +} + +sys_delete_user_profiles() +{ + _msg "${INF}removing ${ROOT_HOME}/.guix-profile" + rm -f ${ROOT_HOME}/.guix-profile + rm -rf ${ROOT_HOME}/.cache/guix + + _msg "${INF}removing .guix-profile, .cache/guix and .config/guix of all /home users" + 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="$1" local char cat<<"EOF" ░░░ ░░░ @@ -647,10 +753,17 @@ welcome() | |__| | |\ | |__| | | |__| | |_| | |> < \_____|_| \_|\____/ \_____|\__,_|_/_/\_\ -This script installs GNU Guix on your system - https://www.gnu.org/software/guix/ EOF + + if [ '--uninstall' = "$uninstall_flag" ]; then + echo "${WARN}This script will uninstall GNU Guix from your system" + echo "To install, run this script with no parameters." + else + echo "This script installs GNU Guix on your system" + echo "To uninstall, pass in the '--uninstall' parameter." + fi + # Don't use ‘read -p’ here! It won't display when run non-interactively. echo -n "Press return to continue..."$'\r' if ! read -r char; then @@ -665,7 +778,7 @@ EOF fi } -main() +main_install() { local tmp_path welcome @@ -715,4 +828,53 @@ main() _msg "${INF}Please log out and back in to complete the installation." } +main_uninstall() +{ + welcome --uninstall + _msg "Starting uninstall process ($(date))" + + chk_term + chk_require "${REQUIRE[@]}" + # it's ok to leave the gpg key + chk_init_sys + chk_sys_arch + + _msg "${INF}system is ${ARCH_OS}" + + # 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 "${INF}removing /etc/guix" + rm -rf /etc/guix + _msg "${INF}removing /var/log/guix" + rm -rf /var/log/guix + + _msg "${PAS}Guix has successfully been uninstalled!" +} + +main() +{ + # expect no parameters + # or '--uninstall' + if [ 0 -eq $# ]; then + main_install + else + local uninstall_flag="$1" + if [ '--uninstall' = "${uninstall_flag}" ]; then + main_uninstall + else + echo "unsupported parameters: $@" + exit 1 + fi + fi +} + main "$@" -- cgit v1.2.3