Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions srcpkgs/wsl-base/files/oobe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/sh

set -eu

ps_env() {
var="$1"
val="$(powershell.exe -NoProfile -Command '& {
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$Env:'"${var}"'}')" 2>/dev/null || true
echo "${val%%[[:cntrl:]]}"
}

WIN_USER="$(ps_env 'UserName' | tr '[[:upper:]] ' '[[:lower:]]_' | sed 's/[^a-z0-9_-]//g; s/^[^a-z_]//')"
USER_ID=1000
USERNAME=''
DEF_GROUPS='users,wheel'
DEF_SHELL='/bin/bash'
if ! [ -x "$DEF_SHELL" ]; then
DEF_SHELL='/bin/sh'
fi


if ! getent passwd "$USER_ID" >/dev/null 2>&1; then
while true; do
USERNAME=''

printf 'Linux user account name (default: %s): ' "$WIN_USER"
read -r USERNAME

if [ -z "$USERNAME" ]; then
USERNAME="$WIN_USER"
fi

if ! printf '%s' "$USERNAME" | grep -E '^[a-z_][a-z0-9_-]*[$]?$' >/dev/null 2>&1; then
echo "Invalid username. Must start with a lowercase letter or underscore, and can only contain lowercase letters, numbers,, underscores, and dashes."
continue
fi

if ! /usr/bin/useradd --comment '' --shell "$DEF_SHELL" --groups "$DEF_GROUPS" --uid "$USER_ID" "$USERNAME" >/dev/null 2>&1; then
echo "Failed to create user '${USERNAME}'. Choose a different name."
continue
fi

if ! /usr/bin/passwd "$USERNAME"; then
echo "Failed to set password for user '${USERNAME}'. Try again."
/usr/bin/userdel "$USERNAME"
continue
fi

if getent passwd "$USER_ID" >/dev/null 2>&1; then
break
fi
done

# allow users in wheel sudo access
if ! [ -e /etc/sudoers.d/wheel ]; then
mkdir -p /etc/sudoers.d
echo "%wheel ALL=(ALL:ALL) ALL" >/etc/sudoers.d/wheel
fi

# set user as default
touch /etc/wsl.conf

if ! grep -q '^\[user\]' /etc/wsl.conf; then
printf '\n[user]\ndefault=%s\n' "$USERNAME" >>/etc/wsl.conf
fi

if ! sed -n '/^\[user\]/,/^\[/{/^\s*default\s*=/p}' /etc/wsl.conf | grep -q .; then
sed -i '/^\[user\]/a\default='"${USERNAME}"'\n' /etc/wsl.conf
fi
fi
11 changes: 11 additions & 0 deletions srcpkgs/wsl-base/files/wsl-distribution.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[oobe]
command = /usr/libexec/wsl/wsl-setup
defaultName = voidlinux-%%LIBC%%
defaultUid = 1000

[shortcut]
enabled = true
icon = /usr/share/wsl/voidlinux.ico

[windowsterminal]
enabled = true
2 changes: 2 additions & 0 deletions srcpkgs/wsl-base/files/wsl.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[boot]
systemd=false
24 changes: 24 additions & 0 deletions srcpkgs/wsl-base/template
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Template file for 'wsl-base'
pkgname=wsl-base
version=1
revision=1
archs="x86_64* aarch64*"
hostmakedepends="void-artwork ImageMagick"
depends="base-container-full"
short_desc="Base files for integration with Windows Subsystem for Linux"
maintainer="classabbyamp <void@placeviolette.net>"
license="Public Domain"
homepage="https://voidlinux.org"
conf_files="/etc/wsl.conf"

do_build() {
sed -e "s/%%LIBC%%/${XBPS_TARGET_LIBC}/g" "${FILESDIR}/wsl-distribution.conf" > wsl-distribution.conf
magick /usr/share/icons/hicolor/{16,32,48,256}x*/apps/void-logo.png voidlinux.ico
}

do_install() {
vinstall "${FILESDIR}/oobe.sh" 0755 usr/libexec/wsl wsl-setup
vinstall "${FILESDIR}/wsl.conf" 0644 etc
vinstall wsl-distribution.conf 0644 etc
vinstall voidlinux.ico 0644 usr/share/wsl
}