guix-install.sh: Run the uninstall even if already partially done

Removing users, groups or Systemd units fails if they are already absent,
causing the uninstall script to exit. The goal here is to make the uninstall
always run entirely, whatever parts are already done.

* etc/guix-install.sh (sys_delete_build_user): Test if users and groups exist
before deleting them.
(sys_delete_guix_daemon): Test if /etc/systemd/system/guix-daemon.service file
exists before removing the matching Systemd unit.

Change-Id: Ibffb1f1b39de675542fb8057af21ecaea1b53d4c
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
David Boilleau 2024-11-08 15:10:24 +01:00 committed by Ludovic Courtès
parent 8edd081164
commit e62dc1ebd0
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -451,11 +451,15 @@ sys_create_build_user()
sys_delete_build_user() sys_delete_build_user()
{ {
for i in $(seq -w 1 10); do for i in $(seq -w 1 10); do
userdel -f guixbuilder${i} if id -u "guixbuilder${i}" &>/dev/null; then
userdel -f guixbuilder${i}
fi
done done
_msg "${INF}delete group guixbuild" _msg "${INF}delete group guixbuild"
groupdel -f guixbuild if getent group guixbuild &>/dev/null; then
groupdel -f guixbuild
fi
} }
sys_enable_guix_daemon() sys_enable_guix_daemon()
@ -569,12 +573,14 @@ sys_delete_guix_daemon()
;; ;;
systemd) systemd)
_msg "${INF}disabling guix-daemon" if [ -f /etc/systemd/system/guix-daemon.service ]; then
systemctl disable guix-daemon _msg "${INF}disabling guix-daemon"
_msg "${INF}stopping guix-daemon" systemctl disable guix-daemon
systemctl stop guix-daemon _msg "${INF}stopping guix-daemon"
_msg "${INF}removing guix-daemon" systemctl stop guix-daemon
rm -f /etc/systemd/system/guix-daemon.service _msg "${INF}removing guix-daemon"
rm -f /etc/systemd/system/guix-daemon.service
fi
if [ -f /etc/systemd/system/gnu-store.mount ]; then if [ -f /etc/systemd/system/gnu-store.mount ]; then
_msg "${INF}disabling gnu-store.mount" _msg "${INF}disabling gnu-store.mount"