@@ -8,10 +8,11 @@ Add-AppxPackage -Path ~/Ubuntu.appx
88
99RefreshEnv
1010
11+ $distro = " ubuntu1804"
1112$username = " ubuntu"
1213$password = " ubuntu"
1314
14- Ubuntu1804 install -- root
15+ & $distro install -- root
1516if ($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 "
2526if ($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
2728if ($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 "
2930if ($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 "
3432if ($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
4341if ($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
4543if ($LASTEXITCODE -ne 0 ) { throw }
46- wsl - d Ubuntu - 18.04 - u root apt- get autoremove - y
44+ & $distro run apt- get autoremove - y
4745if ($LASTEXITCODE -ne 0 ) { throw }
48- wsl - d Ubuntu - 18.04 - u root apt- get autoclean
46+ & $distro run apt- get autoclean
4947if ($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 "
5152if ($LASTEXITCODE -ne 0 ) { throw }
5253
5354<#
0 commit comments