X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;f=wsl2%2Finstall-wsl2.ps1;h=3f419b99c68a6e59fdef9b66b7c6bd070c3de3a5;hb=d68d0376b9cead7e1bf6446e71f00c8e3c965a45;hp=a7abcfdc3f021ce572b662a215407c91c970d32c;hpb=4b19fbc17727bd1a422e292eb617ea0acd680f0a;p=webi-installers%2F.git diff --git a/wsl2/install-wsl2.ps1 b/wsl2/install-wsl2.ps1 index a7abcfd..3f419b9 100644 --- a/wsl2/install-wsl2.ps1 +++ b/wsl2/install-wsl2.ps1 @@ -7,16 +7,39 @@ echo "" echo "Installing 2 of 3 VirtualMachinePlatform ..." & dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart +Function Test-CommandExists +{ + Param ($command) + $oldPreference = $ErrorActionPreference + $ErrorActionPreference = 'stop' + try {if(Get-Command $command){RETURN $true}} + Catch {Write-Host “$command does not exist”; RETURN $false} + Finally {$ErrorActionPreference=$oldPreference} +} + echo "" -echo "Installing 3 of 3 Microsoft Linux Kernel (wsl_update_x64.msi) ..." -& curl.exe -f -o wsl_update_x64.msi "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" -# TODO could we do /quiet /qn to get rid of the popup? -powershell -Command "Start-Process msiexec -Wait -ArgumentList '/a wsl_update_x64.msi /quiet /qn TARGETDIR=""$env:TEMP""'" -#& msiexec /a "wsl_update_x64.msi" /qb TARGETDIR="$env:TEMP" -#Start-Sleep -s 10 -echo "Copied to $env:TEMP" +IF(!(Test-CommandExists wsl)) +{ + echo "Skipping 3 of 3: Microsoft Linux Kernel requires WSL 1 to be installed first ..." +} +ELSE +{ + echo "Installing 3 of 3 Microsoft Linux Kernel (wsl_update_x64.msi) ..." + + IF (!(Test-Path -Path "$Env:TEMP\wsl_update_x64.msi")) { + & curl.exe -f -o "$Env:TEMP\wsl_update_x64.msi" "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" + } + IF (!(Test-Path -Path "C:\Temp\System32\lxss\tools\kernel")) { + # NOTE: This WILL NOT work with TARGETDIR=$Env:TEMP!! + echo "Start-Process msiexec -Wait -ArgumentList '/a ""$Env:TEMP\wsl_update_x64.msi"" /quiet /qn TARGETDIR=""C:\Temp""'" + powershell -Command "Start-Process msiexec -Wait -ArgumentList '/a ""$Env:TEMP\wsl_update_x64.msi"" /quiet /qn TARGETDIR=""C:\Temp""'" + echo "Unpacked to C:\Temp\System32\lxss\tools\kernel" + } + Copy-Item -Path "C:\Temp\System32\lxss" -Destination "C:\System32" -Recurse -Force + echo "Copied to C:\System32\lxss\tools\kernel ..." -Copy-Item -Path "$env:TEMP\System32\lxss" -Destination "C:\System32" -Recurse -echo "Installed C:\System32\lxss\tools\kernel ..." + echo "Start-Process msiexec -Wait -ArgumentList '/i','$Env:TEMP\wsl_update_x64.msi','/quiet','/qn'" + powershell -Command "Start-Process msiexec -Wait -ArgumentList '/i','$Env:TEMP\wsl_update_x64.msi','/quiet','/qn'" +} -Start-Sleep -s 2 +Start-Sleep -s 3