Compare commits
4 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8fa8ffc5e5 | ||
|
|
ce747b8b8e | ||
|
|
9a77cca64b | ||
|
|
c937ddd38f |
4 changed files with 45 additions and 9 deletions
46
wsl-oobe.sh
46
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.
|
||||
|
|
|
|||
|
|
@ -73,6 +73,10 @@ case $key in
|
|||
exit 2
|
||||
fi
|
||||
;;
|
||||
--help | -h )
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
* )
|
||||
echo
|
||||
echo "ERROR BAD OPTION: $key"
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
L+ /tmp/.X11-unix - - - - /mnt/wslg/.X11-unix
|
||||
L /tmp/.X11-unix - - - - /mnt/wslg/.X11-unix
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue