From c937ddd38f1a928c8a1d41712f05d09fceb09e89 Mon Sep 17 00:00:00 2001 From: Li Tian Date: Tue, 23 Sep 2025 12:30:51 +0800 Subject: [PATCH 1/4] tmpfiles: not forcefully create symlink /tmp/.X11-unix In RHEL/CentOS, the X11 socket is created in /tmp fine. Do not forcefully create it which cause an error during installation using dnf/yum. Signed-off-by: Li Tian --- wsl-setup-tmpfiles.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wsl-setup-tmpfiles.conf b/wsl-setup-tmpfiles.conf index 23ba7b5..a9c3d1f 100644 --- a/wsl-setup-tmpfiles.conf +++ b/wsl-setup-tmpfiles.conf @@ -1 +1 @@ -L+ /tmp/.X11-unix - - - - /mnt/wslg/.X11-unix +L /tmp/.X11-unix - - - - /mnt/wslg/.X11-unix From 9a77cca64b20881593574f8e054eb2dc5fdb84b4 Mon Sep 17 00:00:00 2001 From: Li Tian Date: Mon, 22 Sep 2025 13:08:56 +0800 Subject: [PATCH 2/4] wsl-setup: fix --help|-h option error prompt --help|-h ought not to fall into error prompt. Signed-off-by: Li Tian --- wsl-setup | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wsl-setup b/wsl-setup index 41bb0b0..698ca18 100755 --- a/wsl-setup +++ b/wsl-setup @@ -73,6 +73,10 @@ case $key in exit 2 fi ;; +--help | -h ) + usage + exit 0 +;; * ) echo echo "ERROR BAD OPTION: $key" From ce747b8b8e9760853a8608e6e9a1b137040a4491 Mon Sep 17 00:00:00 2001 From: Li Tian Date: Mon, 22 Sep 2025 13:13:17 +0800 Subject: [PATCH 3/4] wsl-oobe.sh: Ask for re-input of username when error Ask for re-input when username either is invalid or exists. Signed-off-by: Li Tian --- wsl-oobe.sh | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/wsl-oobe.sh b/wsl-oobe.sh index 3fbc38f..5cb4a69 100644 --- a/wsl-oobe.sh +++ b/wsl-oobe.sh @@ -11,6 +11,42 @@ set -ueo pipefail DEFAULT_USER_ID=1000 +function create_user() { + local rc=0 + + while true; do + read -r -p "Create a default Unix user account: " username + + # Create the user. + rc=$( + set +e + /usr/sbin/useradd -m -G wheel --uid "$DEFAULT_USER_ID" "$username" > /dev/null + echo $? + ) + + case $rc in + # 3: invalid argument to option + # 19: Bad login name (since Fedora 42) + 3 | 19) + echo "Invalid username. A valid username must start with a letter or underscore, and can contain letters, digits, underscores, dots, dashes and a dollar sign at the end." + continue + ;; + # 9: username or group name already in use + 9) + echo "User \"$username\" already exists" + continue + ;; + 0) + break + ;; + *) + echo "Unexpected error code from useradd: $rc" + break + ;; + esac + done +} + # When `cloud-init` is enabled it might take care of user creation and other bits, depending on its # configuration contained within the WSL image; or the WSL configuration as provided by the host. if systemctl is-enabled cloud-init.service > /dev/null ; then @@ -35,19 +71,15 @@ if systemctl is-enabled cloud-init.service > /dev/null ; then exit 0 fi -echo 'Please create a default user account. The username does not need to match your Windows username.' -echo 'For more information visit: https://aka.ms/wslusers' - if getent passwd $DEFAULT_USER_ID > /dev/null ; then echo 'User account already exists, skipping creation' exit 0 fi -# Prompt from the username -read -r -p 'Enter new UNIX username: ' username +echo 'Please create a default user account. The username does not need to match your Windows username.' +echo 'For more information visit: https://aka.ms/wslusers' -# Create the user -/usr/sbin/useradd -m -G wheel --uid $DEFAULT_USER_ID "$username" +create_user cat > /etc/sudoers.d/wsluser << EOF # Ensure the WSL initial user can use sudo without a password. From 8fa8ffc5e5a266018239a449ac78abca750d11f8 Mon Sep 17 00:00:00 2001 From: Troy Dawson Date: Tue, 21 Oct 2025 11:58:00 -0700 Subject: [PATCH 4/4] Fix ghost file permissions Signed-off-by: Troy Dawson --- wsl-setup.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wsl-setup.spec b/wsl-setup.spec index 6e895dd..4c637a0 100644 --- a/wsl-setup.spec +++ b/wsl-setup.spec @@ -67,7 +67,7 @@ install -Dpm0644 %{SOURCE5} %{buildroot}%{_unitdir}/systemd-firstboot.service.d/ %files %{_bindir}/wsl-setup %config(noreplace) %{_sysconfdir}/wsl.conf -%ghost %{_prefix}/lib/wsl-distribution.conf +%ghost %attr(644, root, root) %{_prefix}/lib/wsl-distribution.conf %{_sysconfdir}/wsl-distribution.conf %dir %{_datarootdir}/wsl-setup/ %{_datarootdir}/wsl-setup/wsl-distribution.conf.template