Compare commits

..

No commits in common. "rawhide" and "f43" have entirely different histories.

4 changed files with 9 additions and 45 deletions

View file

@ -11,42 +11,6 @@ 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
@ -71,15 +35,19 @@ 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
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'
# Prompt from the username
read -r -p 'Enter new UNIX username: ' username
create_user
# Create the user
/usr/sbin/useradd -m -G wheel --uid $DEFAULT_USER_ID "$username"
cat > /etc/sudoers.d/wsluser << EOF
# Ensure the WSL initial user can use sudo without a password.

View file

@ -73,10 +73,6 @@ 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 %attr(644, root, root) %{_prefix}/lib/wsl-distribution.conf
%ghost %{_prefix}/lib/wsl-distribution.conf
%{_sysconfdir}/wsl-distribution.conf
%dir %{_datarootdir}/wsl-setup/
%{_datarootdir}/wsl-setup/wsl-distribution.conf.template