iaas-setup.sh: support default user not existing

For CNaaS machines we supply cloud-init user-data that does not create a
default user, in this case the script would exit half-way through. Now
it only tries to remove a user if it exists in the first place.
This commit is contained in:
Patrik Lundin 2023-01-25 21:52:20 +01:00
parent 714506da1e
commit f1ab4506f1
Signed by untrusted user: patlu
GPG key ID: A0A812BA2249F294

View file

@ -26,10 +26,12 @@ fi
# === # ===
export LC_CTYPE=C.UTF-8 export LC_CTYPE=C.UTF-8
# Remove default user if present
if id "$os"; then
# Make sure there is no systemd process running as the initial cloud image user # Make sure there is no systemd process running as the initial cloud image user
# # after the "enable root" step in prepare-iaas-$os. If there are any # # after the "enable root" step in prepare-iaas-$os. If there are any
# proceses still running as the specified user the "userdel" command # below # proceses still running as the specified user the "userdel" command
# will fail. # below will fail.
# #
# Depending on how long we have waited between running the "enable root" # Depending on how long we have waited between running the "enable root"
# script and this one it is possible the process has timed out on its own, # script and this one it is possible the process has timed out on its own,
@ -51,14 +53,18 @@ while pgrep -u "$os" -xf "/lib/systemd/systemd --user"; do
attempt=$((attempt + 1)) attempt=$((attempt + 1))
done done
# From this point we expect all commands to succeed
set -e
# While the man page for "userdel" recommends using "deluser" we can not # While the man page for "userdel" recommends using "deluser" we can not
# run "deluser" with "--remove-home" without installing more than the # run "deluser" with "--remove-home" without installing more than the
# already included `perl-base` package on debian, so stick with the low # already included `perl-base` package on debian, so stick with the low
# level utility. # level utility.
userdel --remove "$os" if ! userdel --remove "$os"; then
exit 1
fi
fi
# From this point we expect all commands to succeed
set -e
rm /etc/sudoers.d/* rm /etc/sudoers.d/*
# Make sure en_US.UTF-8 is present in the system, expected by at least # Make sure en_US.UTF-8 is present in the system, expected by at least