Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b1f08aa

Browse files
authoredMar 21, 2021
Update WSL.ps1
1 parent 01c0c96 commit b1f08aa

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed
 

‎scripts/WSL.ps1

+14-13
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ Add-AppxPackage -Path ~/Ubuntu.appx
88

99
RefreshEnv
1010

11+
$distro = "ubuntu1804"
1112
$username = "ubuntu"
1213
$password = "ubuntu"
1314

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

1718
# the only non-interactive way to set up a WSL distro is the --root flag
@@ -21,16 +22,13 @@ if ($LASTEXITCODE -ne 0) { throw "Could not install distro." }
2122
# Workaround this by installing with --root but then replicating,
2223
# noninteractively, what happens in the WSL DistroLauncher:
2324
# https://github.com/microsoft/WSL-DistroLauncher/blob/2ed9a9335fc89a688a5150c95eff4fbdbc830f25/DistroLauncher/DistributionInfo.cpp#L8-L33
24-
wsl -d Ubuntu-18.04 -u root useradd -m "$username"
25+
& $distro run useradd -m "$username"
2526
if ($LASTEXITCODE -ne 0) { throw }
26-
wsl -d Ubuntu-18.04 -u root sh -c 'echo "${username}:${password}" | chpasswd' # wrapped in sh -c to get the pipe to work
27+
& $distro run sh -c 'echo "${username}:${password}" | chpasswd' # wrapped in sh -c to get the pipe to work
2728
if ($LASTEXITCODE -ne 0) { throw }
28-
wsl -d Ubuntu-18.04 -u root chsh -s /bin/bash "$username"
29+
& $distro run chsh -s /bin/bash "$username"
2930
if ($LASTEXITCODE -ne 0) { throw }
30-
wsl -d Ubuntu-18.04 -u root usermod -aG adm,cdrom,sudo,dip,plugdev "$username"
31-
if ($LASTEXITCODE -ne 0) { throw }
32-
33-
Ubuntu1804 config --default-user "$username"
31+
& $distro run usermod -aG adm,cdrom,sudo,dip,plugdev "$username"
3432
if ($LASTEXITCODE -ne 0) { throw }
3533

3634

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

4139
# update software
42-
wsl -d Ubuntu-18.04 -u root apt-get update
40+
& $distro run apt-get update
4341
if ($LASTEXITCODE -ne 0) { throw }
44-
wsl -d Ubuntu-18.04 -u root apt-get full-upgrade -y
42+
& $distro run apt-get full-upgrade -y
4543
if ($LASTEXITCODE -ne 0) { throw }
46-
wsl -d Ubuntu-18.04 -u root apt-get autoremove -y
44+
& $distro run apt-get autoremove -y
4745
if ($LASTEXITCODE -ne 0) { throw }
48-
wsl -d Ubuntu-18.04 -u root apt-get autoclean
46+
& $distro run apt-get autoclean
4947
if ($LASTEXITCODE -ne 0) { throw }
50-
wsl --shutdown # instead of 'reboot'
48+
wsl --terminate "Ubuntu-18.04" # instead of 'reboot'
49+
if ($LASTEXITCODE -ne 0) { throw }
50+
51+
& $distro config --default-user "$username"
5152
if ($LASTEXITCODE -ne 0) { throw }
5253

5354
<#

0 commit comments

Comments
 (0)
Please sign in to comment.