Skip to content

Instantly share code, notes, and snippets.

@tetov
Created December 10, 2023 11:52
Show Gist options
  • Save tetov/bf5f193a79a757306dd8576890c9d7c8 to your computer and use it in GitHub Desktop.
Save tetov/bf5f193a79a757306dd8576890c9d7c8 to your computer and use it in GitHub Desktop.
Bootstrap Windows
# Function to check if a Windows feature is enabled
Function IsFeatureEnabled($featureName) {
$feature = Get-WindowsOptionalFeature -Online -FeatureName $featureName
return $feature.State -eq "Enabled"
}
# Initialize variables to track if a restart is needed
$restartNeeded = $false
# Check and enable WSL feature if not already enabled
if (-not (IsFeatureEnabled "Microsoft-Windows-Subsystem-Linux")) {
Write-Output "Enabling Windows Subsystem for Linux..."
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart
$restartNeeded = $true
} else {
Write-Output "Windows Subsystem for Linux is already enabled."
}
# Check and enable Hyper-V feature if not already enabled
if (-not (IsFeatureEnabled "Microsoft-Hyper-V")) {
Write-Output "Enabling Hyper-V..."
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart
$restartNeeded = $true
} else {
Write-Output "Hyper-V is already enabled."
}
# Update WSL
Write-Output "Updating WSL..."
wsl --update
# Check if Ubuntu is already installed
$ubuntuInstalled = wsl -l -q | Select-String -Pattern "Ubuntu"
if (-not $ubuntuInstalled) {
# Install Ubuntu LTS if not installed
Write-Output "Installing Ubuntu LTS..."
wsl --install -d Ubuntu
}
# Set Execution Policy for Scoop Installation
Write-Output "Setting Execution Policy for Scoop Installation..."
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
# Install Scoop
Write-Output "Installing Scoop and essential tools..."
irm get.scoop.sh | iex
scoop install 7zip git aria2
scoop config SCOOP_REPO 'https://github.com/Ash258/Scoop-Core'
scoop update
scoop status
scoop checkup
# Wait for Ubuntu installation to complete
Start-Sleep -Seconds 30
# Update packages, add Ansible PPA, and install Ansible
Write-Output "Updating packages, adding Ansible PPA, and installing Ansible in Ubuntu..."
wsl -d Ubuntu -e bash -c "sudo apt update && sudo apt install -y software-properties-common && sudo add-apt-repository --yes --update ppa:ansible/ansible && sudo apt install -y ansible"
# Restart the computer if needed
if ($restartNeeded) {
Write-Output "A restart is required to complete the installation of features. Restarting now..."
Restart-Computer
return
}
Write-Output "WSL, Ansible, and Scoop installation and setup complete."
@tetov
Copy link
Author

tetov commented Dec 10, 2023

iwr -useb https://gist.githubusercontent.com/tetov/bf5f193a79a757306dd8576890c9d7c8/raw/ | iwr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment