From 12c293c3e7777d425070ca140c8ab00a5c7a4883 Mon Sep 17 00:00:00 2001
From: Helmut Grohne <helmut@subdivi.de>
Date: Wed, 15 May 2024 06:50:36 +0200
Subject: useraddhook: rename USERNAME environment variable to be less generic

USERNAME has uses beyond e.g. in a Windows context, so avoid that. Then
again, this hook may be useful beyond debvm and is installed to
/usr/share/mmdebstrap, so don't use a DEBVM_ prefix either.

Reported-by: Johannes Schauer Marin Rodrigues <josch@mister-muffin.de>
---
 useraddhook/customize.sh | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

(limited to 'useraddhook')

diff --git a/useraddhook/customize.sh b/useraddhook/customize.sh
index bc827a7..ec85d0a 100755
--- a/useraddhook/customize.sh
+++ b/useraddhook/customize.sh
@@ -5,7 +5,7 @@
 # Add a non-root user, add them to the sudo group and use the same authorized
 # ssh keys as the root user.
 #
-#  - the new user is called "user" by default (customizable via $USERNAME)
+#  - the new user is called "user" by default (customizable via $USERADDHOOK_USERNAME)
 #  - no password required for login
 #  - requires the passwd and coreutils packages installed inside the chroot
 #  - adds the new user to the sudo group if it exists
@@ -24,24 +24,24 @@
 
 set -eu
 
-: "${USERNAME:=user}"
+: "${USERADDHOOK_USERNAME:=user}"
 
-chroot "$1" useradd --home-dir "/home/$USERNAME" --create-home --shell /bin/bash "$USERNAME"
-chroot "$1" passwd --delete "$USERNAME"
+chroot "$1" useradd --home-dir "/home/$USERADDHOOK_USERNAME" --create-home --shell /bin/bash "$USERADDHOOK_USERNAME"
+chroot "$1" passwd --delete "$USERADDHOOK_USERNAME"
 if chroot "$1" getent group sudo >/dev/null; then
-	echo "Adding $USERNAME to sudo group"
-	chroot "$1" usermod --append --groups sudo "$USERNAME"
+	echo "Adding $USERADDHOOK_USERNAME to sudo group"
+	chroot "$1" usermod --append --groups sudo "$USERADDHOOK_USERNAME"
 fi
 if [ -e "$1"/root/.ssh/authorized_keys ]; then
-	echo "Installing ssh authorized_keys for $USERNAME"
-	chroot "$1" install -o "$USERNAME" -g "$USERNAME" -m 700 -d "/home/$USERNAME/.ssh"
-	chroot "$1" install -o "$USERNAME" -g "$USERNAME" -t "/home/$USERNAME/.ssh" /root/.ssh/authorized_keys
+	echo "Installing ssh authorized_keys for $USERADDHOOK_USERNAME"
+	chroot "$1" install -o "$USERADDHOOK_USERNAME" -g "$USERADDHOOK_USERNAME" -m 700 -d "/home/$USERADDHOOK_USERNAME/.ssh"
+	chroot "$1" install -o "$USERADDHOOK_USERNAME" -g "$USERADDHOOK_USERNAME" -t "/home/$USERADDHOOK_USERNAME/.ssh" /root/.ssh/authorized_keys
 fi
 if [ -e "$1/etc/lightdm/lightdm.conf" ]; then
-	echo "Enabling autologin in lightdm for $USERNAME"
+	echo "Enabling autologin in lightdm for $USERADDHOOK_USERNAME"
 	cat >>"$1/etc/lightdm/lightdm.conf" <<EOF
 [SeatDefaults]
-autologin-user=$USERNAME
+autologin-user=$USERADDHOOK_USERNAME
 autologin-user-timeout=0
 EOF
 fi
-- 
cgit v1.2.3