diff --git a/chroot_setup.sh b/chroot_setup.sh index daee18f..e5d8107 100644 --- a/chroot_setup.sh +++ b/chroot_setup.sh @@ -20,10 +20,21 @@ cat </etc/hosts EOF echo ">>> Creating users" + +# Root password echo "root:${ROOT_PASSWORD}" | chpasswd -useradd -m -G wheel -s /bin/bash "${USERNAME}" + +# Create user only if missing +if ! id -u "${USERNAME}" &>/dev/null; then + useradd -m -G wheel -s /bin/bash "${USERNAME}" +else + echo "User ${USERNAME} already exists, skipping creation." +fi + +# Always (re)set password echo "${USERNAME}:${USER_PASSWORD}" | chpasswd +# Ensure sudoers configuration exists mkdir -p /etc/sudoers.d echo "%wheel ALL=(ALL:ALL) ALL" > /etc/sudoers.d/10-wheel chmod 440 /etc/sudoers.d/10-wheel