From b31a1ddaa4496549bb7dfa5ad5ea2cd3e6d1c652 Mon Sep 17 00:00:00 2001
From: Arnaud Rebillout <arnaudr@kali.org>
Date: Mon, 3 Mar 2025 12:05:39 +0700
Subject: [PATCH] Sync 0031-kali-user-setup with kali-finish-install

Not sure why there was no info messsages at all in this script, I'm
adding it now to reduce the diff with kali-finish-install, hopefully I'm
not breaking anything by using stdout for informative messages...
---
 .../usr/lib/live/config/0031-kali-user-setup  | 43 ++++++++++++++-----
 1 file changed, 32 insertions(+), 11 deletions(-)

diff --git a/kali-config/common/includes.chroot/usr/lib/live/config/0031-kali-user-setup b/kali-config/common/includes.chroot/usr/lib/live/config/0031-kali-user-setup
index 7c95556..ec51c00 100755
--- a/kali-config/common/includes.chroot/usr/lib/live/config/0031-kali-user-setup
+++ b/kali-config/common/includes.chroot/usr/lib/live/config/0031-kali-user-setup
@@ -1,16 +1,33 @@
 #!/bin/sh
 
+# The reference version of this script is maintained in:
+#   kali-installer/simple-cdd/profiles/kali.postinst
+#   kali-live/kali-config/common/includes.installer/kali-finish-install
+#   kali-live/kali-config/common/includes.chroot/usr/lib/live/config/0031-kali-user-setup
+#   kali-vm/scripts/finish-install.sh
+# (sometimes with small variations)
+#
+# It is used in multiple places to finish configuring the target system
+# and build.sh copies it where required (in the simple-cdd configuration
+# and in the live-build configuration).
+
+get_user_list() {
+    echo kali
+}
+
 configure_zsh() {
-    # Stop if zsh is not present
-    if [ ! -x /usr/bin/zsh ]; then
+    if echo "${LIVE_CONFIG_CMDLINE}" | grep -q 'nozsh'; then
+        echo "INFO: user opted out of zsh by default"
         return
     fi
-    # Stop if user has opted out of zsh
-    if echo "${LIVE_CONFIG_CMDLINE}" | grep -qs 'nozsh'; then
+    if [ ! -x /usr/bin/zsh ]; then
+        echo "INFO: /usr/bin/zsh is not available"
         return
     fi
-    chsh --shell /usr/bin/zsh kali
-    chsh --shell /usr/bin/zsh root
+    for user in $(get_user_list); do
+        echo "INFO: changing default shell of user '$user' to zsh"
+        chsh --shell /usr/bin/zsh $user
+    done
 }
 
 configure_usergroups() {
@@ -19,15 +36,18 @@ configure_usergroups() {
     addgroup --system wireshark || true
 
     # adm - read access to log files
-    # dialout - for serial port access
+    # dialout - for serial access
     # kaboxer - for kaboxer
     # vboxsf - shared folders for virtualbox guest
-    # wireshark - capture sessions without being root
+    # wireshark - capture sessions in wireshark
     kali_groups="adm dialout kaboxer vboxsf wireshark"
 
-    for grp in $kali_groups; do
-        getent group $grp >/dev/null || continue
-        usermod -a -G $grp kali
+    for user in $(get_user_list | grep -xv root); do
+        echo "INFO: adding user '$user' to groups '$kali_groups'"
+        for grp in $kali_groups; do
+            getent group $grp >/dev/null || continue
+            usermod -a -G $grp $user
+        done
     done
 }
 
@@ -38,6 +58,7 @@ pkg_installed() {
 configure_terminal() {
     while read -r desktop terminal; do
         pkg_installed kali-desktop-$desktop || continue
+        echo "INFO: setting x-terminal-emulator alternative to '$terminal'"
         update-alternatives --verbose --set x-terminal-emulator /usr/bin/$terminal || true
         break
     done <<END