Advertisement
Combreal

installAndConfWSL.ps1

Jun 20th, 2019 (edited)
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $makeInstall = "C:\UbuntuWSL\ubuntu1604.exe install --root"
  2. $mustBeRoot = "C:\UbuntuWSL\ubuntu1604.exe config --default-user root"
  3. $runShellScript = "C:\UbuntuWSL\ubuntu1604.exe run `"/mnt/c/UbuntuWSL/configureWsl.sh`""
  4. $setDefaultUser = "C:\UbuntuWSL\ubuntu1604.exe config --default-user $env:USERNAME"
  5. $Source = "\\nas.dbs.fr\windows\Scripts\WSL\configureWsl.sh"
  6.  
  7. if (-not (Test-Path C:\Windows\System32\bash.exe))
  8. {
  9.     $ProgPref = $ProgressPreference
  10.     $ProgressPreference = 'SilentlyContinue'
  11.     $results = Enable-WindowsOptionalFeature -FeatureName Microsoft-Windows-Subsystem-Linux -Online -NoRestart -WarningAction SilentlyContinue
  12.     $ProgressPreference = $ProgPref
  13.     if ($results.RestartNeeded -eq $true)
  14.     {
  15.         Restart-Computer -Force
  16.     }
  17. }
  18. else
  19. {
  20.     if ( -not (Test-Path -Path 'C:\UbuntuWSL' -PathType Container) )# -not
  21.     {
  22.         Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1604 -OutFile C:\Temp\ubuntu.zip -UseBasicParsing
  23.         Expand-Archive C:\Temp\ubuntu.zip C:\UbuntuWSL -Force
  24.         Invoke-Expression -Command:$makeInstall
  25.  
  26.         Copy-Item $Source -Destination C:\UbuntuWSL
  27.  
  28.         Invoke-Expression -Command:$mustBeRoot
  29.         Invoke-Expression -Command:$runShellScript
  30.         Invoke-Expression -Command:$setDefaultUser
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement