Compare commits

..

4 commits

Author SHA1 Message Date
Troy Dawson
8fa8ffc5e5 Fix ghost file permissions
Signed-off-by: Troy Dawson <tdawson@redhat.com>
2025-10-21 11:58:00 -07:00
Li Tian
ce747b8b8e 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 <litian@redhat.com>
2025-10-14 17:19:19 +00:00
Li Tian
9a77cca64b wsl-setup: fix --help|-h option error prompt
--help|-h ought not to fall into error prompt.

Signed-off-by: Li Tian <litian@redhat.com>
2025-10-14 17:19:19 +00:00
Li Tian
c937ddd38f 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 <litian@redhat.com>
2025-09-23 12:44:41 +08:00
4 changed files with 45 additions and 9 deletions

View file

@ -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.

View file

@ -73,6 +73,10 @@ case $key in
exit 2
fi
;;
--help | -h )
usage
exit 0
;;
* )
echo
echo "ERROR BAD OPTION: $key"

View file

@ -1 +1 @@
L+ /tmp/.X11-unix - - - - /mnt/wslg/.X11-unix
L /tmp/.X11-unix - - - - /mnt/wslg/.X11-unix

View file

@ -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