diff --git a/scripts/WSL.ps1 b/scripts/WSL.ps1 index 60602589..f7167638 100644 --- a/scripts/WSL.ps1 +++ b/scripts/WSL.ps1 @@ -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 @@ -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 } @@ -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 } <#