Last active
March 14, 2022 14:13
-
-
Save andrefcdias/0340e2609798ac6ef45198fa3a936ebb to your computer and use it in GitHub Desktop.
To be run after activation of WSL features and reboot (deprecated)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -RunAsAdministrator | |
<# Coolest development environment setup script in the block (Part 2) | |
⚠️ WARNING: This script was created to setup WSL before the new easy installation and was not tested under more recent versions of Windows 11. | |
Please follow my other guide that uses the new modern installations https://gist.github.com/andrefcdias/e1435ae4458024ece36a3b93e3cdd24f | |
--------------------------------------------------------- | |
What can I expect from this script? | |
Part 2 of the setup script, to be run after rebooting to activate WSL | |
This will: | |
- Finish WSL setup | |
- Install latest Ubuntu distro | |
- Start development environment script in WSL | |
#> | |
# Set script to stop on errors | |
Set-StrictMode -Version Latest | |
$ErrorActionPreference = "Stop" | |
$PSDefaultParameterValues['*:ErrorAction']='Stop' | |
$client = new-object System.Net.WebClient | |
# File download URIs | |
$kernelUpdateUri = "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" | |
$linuxSetupUri = "https://gist.githubusercontent.com/raw/8374ed834fe0da107fdbc230b157c1b2" | |
echo "> Continuing the setup..." | |
echo "" | |
echo "" | |
# This will remove the Scheduled Task created to run this script in part 1 | |
try { | |
echo "Checking if Scheduled Task had been created..." | |
Get-ScheduledTask -TaskName "Setup Development Environment" | Out-Null | |
echo "Removing task..." | |
Unregister-ScheduledTask -TaskName "Setup Development Environment" -Confirm:$false | Out-Null | |
echo "Task removed!" | |
} | |
catch { | |
echo "Task does not exist, continuing..." | |
} | |
echo "" | |
echo "Downloading required Linux kernel update..." | |
$client.DownloadFile($kernelUpdateUri, "$env:TEMP/wsl_update_x64.msi") | Out-Null | |
cd $env:TEMP | |
echo "Update downloaded!" | |
echo "" | |
echo "Installing update..." | |
Start-Process msiexec.exe -Wait -ArgumentList '/I wsl_update_x64.msi /quiet' | |
echo "Update installed!" | |
echo "" | |
echo "Setting WSL default version to 2..." | |
wsl --set-default-version 2 | Out-Null | |
echo "Default version set!" | |
echo "" | |
echo "Installing Ubuntu distro..." | |
winget install Ubuntu | Out-Null | |
echo "Ubuntu installed!" | |
echo "Starting Ubuntu, please configure your Linux username and password and then close the Ubuntu window to continue..." | |
$ubuntuExec = Resolve-Path "$env:LOCALAPPDATA/Microsoft/WindowsApps/ubuntu*.exe" | |
Start-Process $ubuntuExec -Wait | |
echo "" | |
echo "Downloading the Linux development environment setup script..." | |
$client.DownloadFile($linuxSetupUri, "$env:TEMP/setup_wsl_environment.sh") | Out-Null | |
cd $env:TEMP | |
echo "Script downloaded!" | |
echo "" | |
echo "Running script in WSL..." | |
wsl ./setup_wsl_environment.sh | |
echo "Script concluded!" | |
echo "" | |
echo "Development environment setup script finished successfully. Enjoy!" | |
echo "" | |
pause | |
# Cleaning up after myself | |
Remove-Item $MyINvocation.InvocationName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment