From 148a880fb51b35720fe4294c435282a20ec1a881 Mon Sep 17 00:00:00 2001 From: releng bot Date: Mon, 27 Jan 2025 16:55:19 +0000 Subject: [PATCH 01/14] Added the README --- README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..63f5317 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# wsl-setup + +The wsl-setup package From 7fee63c813cd3ff3931eee02c52317edb8ae11c1 Mon Sep 17 00:00:00 2001 From: Jeremy Cline Date: Mon, 27 Jan 2025 13:42:03 -0500 Subject: [PATCH 02/14] Initial import (rhbz #2342289) --- .gitignore | 0 LICENSE | 20 +++++++++++++++ sources | 0 wsl-distribution.conf | 19 ++++++++++++++ wsl-oobe.sh | 38 ++++++++++++++++++++++++++++ wsl-setup.spec | 58 +++++++++++++++++++++++++++++++++++++++++++ wsl.conf | 4 +++ 7 files changed, 139 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 sources create mode 100644 wsl-distribution.conf create mode 100644 wsl-oobe.sh create mode 100644 wsl-setup.spec create mode 100644 wsl.conf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..570ff3f --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright 2025 Fedora Project Authors. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/sources b/sources new file mode 100644 index 0000000..e69de29 diff --git a/wsl-distribution.conf b/wsl-distribution.conf new file mode 100644 index 0000000..cf1e04d --- /dev/null +++ b/wsl-distribution.conf @@ -0,0 +1,19 @@ +# The /etc/wsl-distribution.conf configuration file. +# +# This is not intended to be edited by users; it is how WSL discovers +# distribution defaults. +# +# Available configuration options are documented at +# https://learn.microsoft.com/en-us/windows/wsl/build-custom-distro + +[oobe] +# Command run the first time the user opens an interactive shell. +# If the command returns non-zero, it is considered unsuccessful and the +# user won't be able to open a shell. +command = /usr/libexec/wsl/oobe.sh +# Default UID for user the distribution starts with. +defaultUid = 1000 +# Default name the distribution is registered under. +# This is used when the user double-clicks to install, or uses +# wsl --install --from-file ./Fedora.wsl +defaultName = $NAME diff --git a/wsl-oobe.sh b/wsl-oobe.sh new file mode 100644 index 0000000..e406b57 --- /dev/null +++ b/wsl-oobe.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# The Fedora WSL out of box experience script. +# +# This command runs the first time the user opens an interactive shell. +# +# A non-zero exit code indicates to WSL that setup failed. + +set -ueo pipefail + +DEFAULT_USER_ID=1000 + +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 + +# 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 +$username ALL=(ALL) NOPASSWD: ALL +EOF + +# Set the default user; necessary when this script is manually run in versions +# of WSL prior to 2.4. +cat >> /etc/wsl.conf << EOF + +[user] +default = "$username" +EOF diff --git a/wsl-setup.spec b/wsl-setup.spec new file mode 100644 index 0000000..8c67f6e --- /dev/null +++ b/wsl-setup.spec @@ -0,0 +1,58 @@ +%if 0%{?eln} + %define default_name ELN +%else + %define default_name Fedora +%endif + + +Name: wsl-setup +Version: 1.0.0 +Release: %autorelease +Summary: Windows Subsystem for Linux setup script and configuration +License: MIT +URL: https://src.fedoraproject.org/rpms/wsl-setup +BuildArch: noarch + +Source1: LICENSE +Source2: wsl.conf +Source3: wsl-distribution.conf +Source4: wsl-oobe.sh + + +%description +Provides WSL specific configuration files and first-time setup script. + + +%prep +%if 0%{?fedora} +sed -i 's,$NAME,Fedora,' %{SOURCE3} +%else +sed -i 's,$NAME,ELN,' %{SOURCE3} +%endif + + +%build + + +%install +install -pm 0644 %{SOURCE1} LICENSE +install -Dpm0644 -t %{buildroot}%{_sysconfdir}/ %{SOURCE2} +install -Dpm0644 -t %{buildroot}%{_prefix}/lib/ %{SOURCE3} +install -Dpm0755 -T %{SOURCE4} %{buildroot}%{_libexecdir}/wsl/oobe.sh +ln -s ..%{_prefix}/lib/wsl-distribution.conf %{buildroot}%{_sysconfdir}/wsl-distribution.conf + + +%check +grep "defaultName = %{default_name}" %{buildroot}%{_sysconfdir}/wsl-distribution.conf + + +%files +%config(noreplace) %{_sysconfdir}/wsl.conf +%{_prefix}/lib/wsl-distribution.conf +%{_sysconfdir}/wsl-distribution.conf +%{_libexecdir}/wsl/oobe.sh +%license LICENSE + + +%changelog +%autochangelog diff --git a/wsl.conf b/wsl.conf new file mode 100644 index 0000000..1a92e7c --- /dev/null +++ b/wsl.conf @@ -0,0 +1,4 @@ +# Refer to https://learn.microsoft.com/en-us/windows/wsl/wsl-config#wslconf +# for the full set of configuration options. +[boot] +systemd=true From 36a22f247c7a309522b4c343925c5e6109e18adc Mon Sep 17 00:00:00 2001 From: Jeremy Cline Date: Tue, 28 Jan 2025 09:42:51 -0500 Subject: [PATCH 03/14] Replace define macro with global Zbyszek noted global is preferred to define in a review comment. --- wsl-setup.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wsl-setup.spec b/wsl-setup.spec index 8c67f6e..a8308cb 100644 --- a/wsl-setup.spec +++ b/wsl-setup.spec @@ -1,7 +1,7 @@ %if 0%{?eln} - %define default_name ELN + %global default_name ELN %else - %define default_name Fedora + %global default_name Fedora %endif From 3fb3ab214ea36e1adda214b84d39dd1c919175e5 Mon Sep 17 00:00:00 2001 From: Jeremy Cline Date: Fri, 31 Jan 2025 10:13:55 -0500 Subject: [PATCH 04/14] Add tmpfiles configuration for x11, Wayland, and PulseAudio support This includes the tmpfiles config to link the various WSL-provided service sockets to the expected location. It also includes an override snippet for systemd-firstboot to have it not run inside WSL for the present as it hangs forever. --- firstboot-override.conf | 2 ++ wsl-setup-tmpfiles.conf | 1 + wsl-setup-user-tmpfiles.conf | 3 +++ wsl-setup.spec | 23 +++++++++++++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 firstboot-override.conf create mode 100644 wsl-setup-tmpfiles.conf create mode 100644 wsl-setup-user-tmpfiles.conf diff --git a/firstboot-override.conf b/firstboot-override.conf new file mode 100644 index 0000000..c6fab5d --- /dev/null +++ b/firstboot-override.conf @@ -0,0 +1,2 @@ +[Unit] +ConditionVirtualization=!wsl diff --git a/wsl-setup-tmpfiles.conf b/wsl-setup-tmpfiles.conf new file mode 100644 index 0000000..23ba7b5 --- /dev/null +++ b/wsl-setup-tmpfiles.conf @@ -0,0 +1 @@ +L+ /tmp/.X11-unix - - - - /mnt/wslg/.X11-unix diff --git a/wsl-setup-user-tmpfiles.conf b/wsl-setup-user-tmpfiles.conf new file mode 100644 index 0000000..6a155a8 --- /dev/null +++ b/wsl-setup-user-tmpfiles.conf @@ -0,0 +1,3 @@ +L+ /run/user/%U/wayland-0.lock - - - - /mnt/wslg/runtime-dir/wayland-0.lock +L+ /run/user/%U/wayland-0 - - - - /mnt/wslg/runtime-dir/wayland-0 +L+ /run/user/%U/pulse - - - - /mnt/wslg/runtime-dir/pulse diff --git a/wsl-setup.spec b/wsl-setup.spec index a8308cb..f8ceaac 100644 --- a/wsl-setup.spec +++ b/wsl-setup.spec @@ -17,6 +17,11 @@ Source1: LICENSE Source2: wsl.conf Source3: wsl-distribution.conf Source4: wsl-oobe.sh +Source5: firstboot-override.conf +Source6: wsl-setup-tmpfiles.conf +Source7: wsl-setup-user-tmpfiles.conf + +BuildRequires: systemd-rpm-macros %description @@ -41,6 +46,21 @@ install -Dpm0644 -t %{buildroot}%{_prefix}/lib/ %{SOURCE3} install -Dpm0755 -T %{SOURCE4} %{buildroot}%{_libexecdir}/wsl/oobe.sh ln -s ..%{_prefix}/lib/wsl-distribution.conf %{buildroot}%{_sysconfdir}/wsl-distribution.conf +# WSL provides a socket for x11, but we need to ensure its linked to in /tmp. +# The official recommendation is to disable tmpfiles entirely, but it would be +# nice to work with it, instead. +# https://learn.microsoft.com/en-us/windows/wsl/build-custom-distro#systemd-recommendations +install -Dpm0644 %{SOURCE6} %{buildroot}%{_tmpfilesdir}/%{name}.conf + +# WSL provides a Wayland and PulseAudio docket as well, which are expected to be in +# the user's runtime directory. This configuration sets up the links for each user. +install -Dpm0644 %{SOURCE7} %{buildroot}%{_user_tmpfilesdir}/%{name}.conf + +# Currently systemd-firstboot hangs forever attempting to acquire the console; this is +# problematic since many other services wait for it to complete before starting, including +# things like the system D-Bus. Configure it to not run in WSL (a preset didn't seem to work) +# until we can see about adjusting either WSL or systemd to make it behave. +install -Dpm0644 %{SOURCE5} %{buildroot}%{_unitdir}/systemd-firstboot.service.d/override.conf %check grep "defaultName = %{default_name}" %{buildroot}%{_sysconfdir}/wsl-distribution.conf @@ -51,6 +71,9 @@ grep "defaultName = %{default_name}" %{buildroot}%{_sysconfdir}/wsl-distribution %{_prefix}/lib/wsl-distribution.conf %{_sysconfdir}/wsl-distribution.conf %{_libexecdir}/wsl/oobe.sh +%{_tmpfilesdir}/%{name}.conf +%{_user_tmpfilesdir}/%{name}.conf +%{_unitdir}/systemd-firstboot.service.d/override.conf %license LICENSE From aae108edd0088ca4dedf803e4616fc4f8c35eb5e Mon Sep 17 00:00:00 2001 From: Jeremy Cline Date: Tue, 18 Feb 2025 10:23:35 -0500 Subject: [PATCH 05/14] oobe: Let the user know they're in wheel and have passwordless sudo Also include the command to set a password, if they wish. --- wsl-oobe.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/wsl-oobe.sh b/wsl-oobe.sh index e406b57..ace2e51 100644 --- a/wsl-oobe.sh +++ b/wsl-oobe.sh @@ -25,7 +25,11 @@ read -r -p 'Enter new UNIX username: ' username /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 +# Ensure the WSL initial user can use sudo without a password. +# +# Since the user is in the wheel group, this file can be removed +# if you wish to require a password for sudo. Be sure to set a +# user password before doing so with 'sudo passwd $username'! $username ALL=(ALL) NOPASSWD: ALL EOF @@ -36,3 +40,6 @@ cat >> /etc/wsl.conf << EOF [user] default = "$username" EOF + +echo 'Your user has been created, is included in the wheel group, and can use sudo without a password.' +echo "To set a password for your user, run 'sudo passwd $username'" From 7b44929d3ba965070099dd1881736b81fdad271a Mon Sep 17 00:00:00 2001 From: David Senoner Date: Sun, 23 Feb 2025 21:18:35 +0000 Subject: [PATCH 06/14] fix typo --- wsl-setup.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wsl-setup.spec b/wsl-setup.spec index f8ceaac..429cb1b 100644 --- a/wsl-setup.spec +++ b/wsl-setup.spec @@ -52,7 +52,7 @@ ln -s ..%{_prefix}/lib/wsl-distribution.conf %{buildroot}%{_sysconfdir}/wsl-dist # https://learn.microsoft.com/en-us/windows/wsl/build-custom-distro#systemd-recommendations install -Dpm0644 %{SOURCE6} %{buildroot}%{_tmpfilesdir}/%{name}.conf -# WSL provides a Wayland and PulseAudio docket as well, which are expected to be in +# WSL provides a Wayland and PulseAudio socket as well, which are expected to be in # the user's runtime directory. This configuration sets up the links for each user. install -Dpm0644 %{SOURCE7} %{buildroot}%{_user_tmpfilesdir}/%{name}.conf From 821d0da3672923cabb48f1af8322a0a2472ba58c Mon Sep 17 00:00:00 2001 From: Jeremy Cline Date: Fri, 21 Mar 2025 11:38:03 -0400 Subject: [PATCH 07/14] Add distribution icon to wsl-distribution.conf Added in https://pagure.io/fedora-logos/pull-request/27 there's now a logo in a format acceptable to WSL. This adds a dependency on the logos package and configures the icon setting for the distribution. --- wsl-distribution.conf | 4 ++++ wsl-setup.spec | 3 +++ 2 files changed, 7 insertions(+) diff --git a/wsl-distribution.conf b/wsl-distribution.conf index cf1e04d..1bf9706 100644 --- a/wsl-distribution.conf +++ b/wsl-distribution.conf @@ -17,3 +17,7 @@ defaultUid = 1000 # This is used when the user double-clicks to install, or uses # wsl --install --from-file ./Fedora.wsl defaultName = $NAME + +[shortcut] +enabled = true +icon = /usr/share/pixmaps/fedora-logo.ico diff --git a/wsl-setup.spec b/wsl-setup.spec index 429cb1b..a56f58a 100644 --- a/wsl-setup.spec +++ b/wsl-setup.spec @@ -23,6 +23,9 @@ Source7: wsl-setup-user-tmpfiles.conf BuildRequires: systemd-rpm-macros +# Needed for the distribution icon +Requires: system-logos + %description Provides WSL specific configuration files and first-time setup script. From cac1fa2a3be36ea1bf1c6a2e09eaf7d0ee204dcc Mon Sep 17 00:00:00 2001 From: Troy Dawson Date: Fri, 11 Apr 2025 07:31:27 -0700 Subject: [PATCH 08/14] Expand variations for default_name Signed-off-by: Troy Dawson --- wsl-setup.spec | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/wsl-setup.spec b/wsl-setup.spec index a56f58a..078bd30 100644 --- a/wsl-setup.spec +++ b/wsl-setup.spec @@ -1,5 +1,11 @@ -%if 0%{?eln} +%if %{defined eln} %global default_name ELN +%elif %{defined epel} && %{defined centos} + %global default_name CentosStream-EPEL-%{?centos} +%elif %{defined centos} + %global default_name CentosStream-%{?centos} +%elif %{defined fedora} + %global default_name Fedora-%{?fedora} %else %global default_name Fedora %endif @@ -32,11 +38,7 @@ Provides WSL specific configuration files and first-time setup script. %prep -%if 0%{?fedora} -sed -i 's,$NAME,Fedora,' %{SOURCE3} -%else -sed -i 's,$NAME,ELN,' %{SOURCE3} -%endif +sed -i 's,$NAME,%{default_name},' %{SOURCE3} %build From 3c2b79527f6f38dd90373901be3c837cb74e1c33 Mon Sep 17 00:00:00 2001 From: Troy Dawson Date: Tue, 15 Apr 2025 10:32:51 -0700 Subject: [PATCH 09/14] Dynamically set DefaultName on package install Signed-off-by: Troy Dawson --- wsl-distribution.conf | 2 +- wsl-setup.spec | 22 ++++++---------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/wsl-distribution.conf b/wsl-distribution.conf index 1bf9706..8361f26 100644 --- a/wsl-distribution.conf +++ b/wsl-distribution.conf @@ -16,7 +16,7 @@ defaultUid = 1000 # Default name the distribution is registered under. # This is used when the user double-clicks to install, or uses # wsl --install --from-file ./Fedora.wsl -defaultName = $NAME +defaultName = DEFAULT_NAME [shortcut] enabled = true diff --git a/wsl-setup.spec b/wsl-setup.spec index 078bd30..ba05619 100644 --- a/wsl-setup.spec +++ b/wsl-setup.spec @@ -1,16 +1,3 @@ -%if %{defined eln} - %global default_name ELN -%elif %{defined epel} && %{defined centos} - %global default_name CentosStream-EPEL-%{?centos} -%elif %{defined centos} - %global default_name CentosStream-%{?centos} -%elif %{defined fedora} - %global default_name Fedora-%{?fedora} -%else - %global default_name Fedora -%endif - - Name: wsl-setup Version: 1.0.0 Release: %autorelease @@ -38,7 +25,6 @@ Provides WSL specific configuration files and first-time setup script. %prep -sed -i 's,$NAME,%{default_name},' %{SOURCE3} %build @@ -67,8 +53,12 @@ install -Dpm0644 %{SOURCE7} %{buildroot}%{_user_tmpfilesdir}/%{name}.conf # until we can see about adjusting either WSL or systemd to make it behave. install -Dpm0644 %{SOURCE5} %{buildroot}%{_unitdir}/systemd-firstboot.service.d/override.conf -%check -grep "defaultName = %{default_name}" %{buildroot}%{_sysconfdir}/wsl-distribution.conf + +%post +# generate the "auto" naming +. %{_sysconfdir}/os-release +DYNAMIC_NAME="${NAME// /}-${VERSION_ID%.*}" +sed -i "s,DEFAULT_NAME,${DYNAMIC_NAME}," %{_sysconfdir}/wsl-distribution.conf %files From b781149120302f5e76b52acc04e42a64bbd49abf Mon Sep 17 00:00:00 2001 From: Troy Dawson Date: Wed, 14 May 2025 14:30:24 -0700 Subject: [PATCH 10/14] Make wsl-setup a script The script generates wsl-distribution.conf from a template. You can pass it options for the Name as well as the logo file. Signed-off-by: Troy Dawson --- wsl-distribution.conf | 2 +- wsl-setup | 86 +++++++++++++++++++++++++++++++++++++++++++ wsl-setup.spec | 14 ++++--- 3 files changed, 96 insertions(+), 6 deletions(-) create mode 100755 wsl-setup diff --git a/wsl-distribution.conf b/wsl-distribution.conf index 8361f26..3c8e1e5 100644 --- a/wsl-distribution.conf +++ b/wsl-distribution.conf @@ -20,4 +20,4 @@ defaultName = DEFAULT_NAME [shortcut] enabled = true -icon = /usr/share/pixmaps/fedora-logo.ico +icon = DEFAULT_ICON_FULL_PATH diff --git a/wsl-setup b/wsl-setup new file mode 100755 index 0000000..4722334 --- /dev/null +++ b/wsl-setup @@ -0,0 +1,86 @@ +#!/usr/bin/bash +# +# Setup the environment for the new WSL configuration +# +# Copyright (C) 2025 +# SPDX-License-Identifier: MIT +# +# Authors: +# Troy Dawson +# + +############### +# Variables +############### +DISTRIBUTION_TEMPLATE_FILE="/usr/share/wsl-setup/wsl-distribution.conf.template" +DISTRIBUTION_CONF_FILE="/usr/lib/wsl-distribution.conf" +DISTRIBUTION_CONF_LINK="/etc/wsl-distribution.conf" +. /etc/os-release +DEFAULT_NAME="${NAME// /}-${VERSION_ID%.*}" +ICON_PATH="/usr/share/pixmaps/fedora-logo.ico" + +############### +# Show help +############### +usage() { + echo "Usage `basename $0` " >&2 + echo >&2 + echo "Setup the environment for the new WSL configuration" >&2 + echo >&2 + echo "Options:" >&2 + echo " --name, -n" >&2 + echo " Set the distro name" >&2 + echo " Default: ${DEFAULT_NAME}" >&2 + echo " --icon, -i" >&2 + echo " Full pathname to the icon" >&2 + echo " Default: ${ICON_PATH}" >&2 + echo " --help, -h" >&2 + echo " Show this options menu" >&2 + echo >&2 + popd &>/dev/null + exit 1 +} + + +############### +# Get our arguments +############### +while [[ "$#" -ge 1 ]] +do +key="$1" +case $key in +--name | -n ) + if ! [ "${2}" == "" ] ; then + DEFAULT_NAME="${2}" + shift + else + echo "ERROR: Name is not provided" + echo + usage + exit 2 + fi +;; +--icon | -i ) + if ! [ "${2}" == "" ] ; then + ICON_PATH="${2}" + shift + else + echo "ERROR: Icon full path is not provided" + echo + usage + exit 2 + fi +;; +* ) + usage + exit 2 +;; +esac +done + +############### +# Do the work +############### + +cp -f ${DISTRIBUTION_TEMPLATE_FILE} ${DISTRIBUTION_CONF_FILE} +sed -i -e "s|DEFAULT_NAME|${DEFAULT_NAME}|" -e "s|DEFAULT_ICON_FULL_PATH|${ICON_PATH}|" ${DISTRIBUTION_CONF_FILE} diff --git a/wsl-setup.spec b/wsl-setup.spec index ba05619..7906355 100644 --- a/wsl-setup.spec +++ b/wsl-setup.spec @@ -1,5 +1,5 @@ Name: wsl-setup -Version: 1.0.0 +Version: 1.0.1 Release: %autorelease Summary: Windows Subsystem for Linux setup script and configuration License: MIT @@ -13,6 +13,7 @@ Source4: wsl-oobe.sh Source5: firstboot-override.conf Source6: wsl-setup-tmpfiles.conf Source7: wsl-setup-user-tmpfiles.conf +Source8: wsl-setup BuildRequires: systemd-rpm-macros @@ -34,7 +35,9 @@ Provides WSL specific configuration files and first-time setup script. install -pm 0644 %{SOURCE1} LICENSE install -Dpm0644 -t %{buildroot}%{_sysconfdir}/ %{SOURCE2} install -Dpm0644 -t %{buildroot}%{_prefix}/lib/ %{SOURCE3} +install -Dpm0644 -T %{SOURCE3} %{buildroot}%{_datarootdir}/wsl-setup/wsl-distribution.conf.template install -Dpm0755 -T %{SOURCE4} %{buildroot}%{_libexecdir}/wsl/oobe.sh +install -Dpm0755 -T %{SOURCE8} %{buildroot}%{_bindir}/wsl-setup ln -s ..%{_prefix}/lib/wsl-distribution.conf %{buildroot}%{_sysconfdir}/wsl-distribution.conf # WSL provides a socket for x11, but we need to ensure its linked to in /tmp. @@ -55,16 +58,17 @@ install -Dpm0644 %{SOURCE5} %{buildroot}%{_unitdir}/systemd-firstboot.service.d/ %post -# generate the "auto" naming -. %{_sysconfdir}/os-release -DYNAMIC_NAME="${NAME// /}-${VERSION_ID%.*}" -sed -i "s,DEFAULT_NAME,${DYNAMIC_NAME}," %{_sysconfdir}/wsl-distribution.conf +# generate the "auto" naming, using the defaults +%{_bindir}/wsl-setup %files +%{_bindir}/wsl-setup %config(noreplace) %{_sysconfdir}/wsl.conf %{_prefix}/lib/wsl-distribution.conf %{_sysconfdir}/wsl-distribution.conf +%dir %{_datarootdir}/wsl-setup/ +%{_datarootdir}/wsl-setup/wsl-distribution.conf.template %{_libexecdir}/wsl/oobe.sh %{_tmpfilesdir}/%{name}.conf %{_user_tmpfilesdir}/%{name}.conf From 0479b8395c274205d08acd185f7afe0c8ebb00cd Mon Sep 17 00:00:00 2001 From: Troy Dawson Date: Mon, 19 May 2025 08:37:26 -0700 Subject: [PATCH 11/14] Change /usr/lib/wsl-distribution.conf to a ghost file Signed-off-by: Troy Dawson --- wsl-setup.spec | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wsl-setup.spec b/wsl-setup.spec index 7906355..f4f8495 100644 --- a/wsl-setup.spec +++ b/wsl-setup.spec @@ -34,7 +34,6 @@ Provides WSL specific configuration files and first-time setup script. %install install -pm 0644 %{SOURCE1} LICENSE install -Dpm0644 -t %{buildroot}%{_sysconfdir}/ %{SOURCE2} -install -Dpm0644 -t %{buildroot}%{_prefix}/lib/ %{SOURCE3} install -Dpm0644 -T %{SOURCE3} %{buildroot}%{_datarootdir}/wsl-setup/wsl-distribution.conf.template install -Dpm0755 -T %{SOURCE4} %{buildroot}%{_libexecdir}/wsl/oobe.sh install -Dpm0755 -T %{SOURCE8} %{buildroot}%{_bindir}/wsl-setup @@ -65,7 +64,7 @@ install -Dpm0644 %{SOURCE5} %{buildroot}%{_unitdir}/systemd-firstboot.service.d/ %files %{_bindir}/wsl-setup %config(noreplace) %{_sysconfdir}/wsl.conf -%{_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 From 5afaf63d99184801fe5688c05c5aba6a6bb2041d Mon Sep 17 00:00:00 2001 From: Simon de Vlieger Date: Wed, 28 May 2025 12:01:25 +0200 Subject: [PATCH 12/14] oobe: exit early for cloud-init WSL supports `cloud-init` for provisioning. In some cases (RHEL) this is enabled. If `wsl-setup` is used on RHEL then there's a TOCTOU between the check for "no user exists" and the "create user" part as `cloud-init` creates the user during the prompt. Let's exit early and assume everything is handled by `cloud-init` *if* it is enabled. Signed-off-by: Simon de Vlieger --- wsl-oobe.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wsl-oobe.sh b/wsl-oobe.sh index ace2e51..240dde6 100644 --- a/wsl-oobe.sh +++ b/wsl-oobe.sh @@ -2,7 +2,8 @@ # The Fedora WSL out of box experience script. # -# This command runs the first time the user opens an interactive shell. +# This command runs the first time the user opens an interactive shell if +# `cloud-init` is not enabled. # # A non-zero exit code indicates to WSL that setup failed. @@ -10,6 +11,10 @@ set -ueo pipefail DEFAULT_USER_ID=1000 +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' From 3ee41192ed2efe6a791947f0c2f8b7d6d69647b7 Mon Sep 17 00:00:00 2001 From: Simon de Vlieger Date: Thu, 5 Jun 2025 16:45:11 +0200 Subject: [PATCH 13/14] oobe: message for enabled cloud-init Show a message when cloud-init is enabled so users know what is going on. Signed-off-by: Simon de Vlieger --- wsl-oobe.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/wsl-oobe.sh b/wsl-oobe.sh index 240dde6..b55e831 100644 --- a/wsl-oobe.sh +++ b/wsl-oobe.sh @@ -12,6 +12,7 @@ set -ueo pipefail DEFAULT_USER_ID=1000 if systemctl is-enabled cloud-init.service > /dev/null ; then + echo 'cloud-init is enabled, skipping user account creation' exit 0 fi From fc30a377e89fc19665dc0180f74162bee90789e1 Mon Sep 17 00:00:00 2001 From: Simon de Vlieger Date: Wed, 18 Jun 2025 20:26:14 +0200 Subject: [PATCH 14/14] oobe: wait for cloud-init to finish Let's wait for `cloud-init` to finish before we exit the OOBE; this ensures that any potential user has been created. In the future we might want to always continue with our OOBE, in those cases that `cloud-init` didn't create a user we can then continue with the prompt(s). Signed-off-by: Simon de Vlieger --- wsl-oobe.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wsl-oobe.sh b/wsl-oobe.sh index b55e831..b246933 100644 --- a/wsl-oobe.sh +++ b/wsl-oobe.sh @@ -12,7 +12,8 @@ set -ueo pipefail DEFAULT_USER_ID=1000 if systemctl is-enabled cloud-init.service > /dev/null ; then - echo 'cloud-init is enabled, skipping user account creation' + echo 'cloud-init is enabled, skipping user account creation. Waiting for cloud-init to finish.' + cloud-init status --wait > /dev/null 2>&1 exit 0 fi