Skip to content

Commit

Permalink
Update WSL.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
kousu authored Mar 21, 2021
1 parent 01c0c96 commit b1f08aa
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions scripts/WSL.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ Add-AppxPackage -Path ~/Ubuntu.appx

RefreshEnv

$distro = "ubuntu1804"
$username = "ubuntu"
$password = "ubuntu"

Ubuntu1804 install --root
& $distro install --root
if ($LASTEXITCODE -ne 0) { throw "Could not install distro." }

# the only non-interactive way to set up a WSL distro is the --root flag
Expand All @@ -21,16 +22,13 @@ if ($LASTEXITCODE -ne 0) { throw "Could not install distro." }
# Workaround this by installing with --root but then replicating,
# noninteractively, what happens in the WSL DistroLauncher:
# https://github.com/microsoft/WSL-DistroLauncher/blob/2ed9a9335fc89a688a5150c95eff4fbdbc830f25/DistroLauncher/DistributionInfo.cpp#L8-L33
wsl -d Ubuntu-18.04 -u root useradd -m "$username"
& $distro run useradd -m "$username"
if ($LASTEXITCODE -ne 0) { throw }
wsl -d Ubuntu-18.04 -u root sh -c 'echo "${username}:${password}" | chpasswd' # wrapped in sh -c to get the pipe to work
& $distro run sh -c 'echo "${username}:${password}" | chpasswd' # wrapped in sh -c to get the pipe to work
if ($LASTEXITCODE -ne 0) { throw }
wsl -d Ubuntu-18.04 -u root chsh -s /bin/bash "$username"
& $distro run chsh -s /bin/bash "$username"
if ($LASTEXITCODE -ne 0) { throw }
wsl -d Ubuntu-18.04 -u root usermod -aG adm,cdrom,sudo,dip,plugdev "$username"
if ($LASTEXITCODE -ne 0) { throw }

Ubuntu1804 config --default-user "$username"
& $distro run usermod -aG adm,cdrom,sudo,dip,plugdev "$username"
if ($LASTEXITCODE -ne 0) { throw }


Expand All @@ -39,15 +37,18 @@ $env:DEBIAN_FRONTEND = "noninteractive"
$env:WSLENV += ":DEBIAN_FRONTEND"

# update software
wsl -d Ubuntu-18.04 -u root apt-get update
& $distro run apt-get update
if ($LASTEXITCODE -ne 0) { throw }
wsl -d Ubuntu-18.04 -u root apt-get full-upgrade -y
& $distro run apt-get full-upgrade -y
if ($LASTEXITCODE -ne 0) { throw }
wsl -d Ubuntu-18.04 -u root apt-get autoremove -y
& $distro run apt-get autoremove -y
if ($LASTEXITCODE -ne 0) { throw }
wsl -d Ubuntu-18.04 -u root apt-get autoclean
& $distro run apt-get autoclean
if ($LASTEXITCODE -ne 0) { throw }
wsl --shutdown # instead of 'reboot'
wsl --terminate "Ubuntu-18.04" # instead of 'reboot'
if ($LASTEXITCODE -ne 0) { throw }

& $distro config --default-user "$username"
if ($LASTEXITCODE -ne 0) { throw }

<#
Expand Down

0 comments on commit b1f08aa

Please sign in to comment.