diff --git a/install_windows.ps1 b/install_windows.ps1 index 6ae4346..d9d0c5b 100644 --- a/install_windows.ps1 +++ b/install_windows.ps1 @@ -1,11 +1,13 @@ Import-Module ./util/chocolatey.psm1 Import-Module ./util/windows.psm1 Import-Module ./util/winget.psm1 +Import-Module ./util/wsl.psm1 # (Optionally) Install required Software InstallWinget InstallChocolatey +InstallWSL # Define paths for tools and configurations $dotfilesRepo = "$env:TMP\dotfiles" @@ -32,13 +34,7 @@ $ubuntu = wsl.exe -l --all | Where-Object { $_.Replace("`0", "") -match '^Ubuntu if ($null -eq $ubuntu) { ProcessUrlFiles -source "$dotfilesRepo\nvim" -destination "$env:LOCALAPPDATA" } else -{ - # TODO: Expand into generic WSL setup while installing required dev tools - ProcessUrlFiles -sourceDir "$dotfilesRepo\nvim" - Set-Location "$env:TMP\nvim-config" - Write-Host "Copying (forcably) configuration to WSL..." -ForegroundColor Yellow - wsl.exe cp -rf . ~/.config/ 2>$null | Out-Null - Set-Location - +{ InstallWSLNeovim -source "$dotfilesRepo\nvim" } # Setting up PowerShell Profile diff --git a/util/wsl.list b/util/wsl.list new file mode 100644 index 0000000..0ca7277 --- /dev/null +++ b/util/wsl.list @@ -0,0 +1,14 @@ +make +gcc +ripgrep +unzip +git +xclip +python3 +python3-venv +composer +luarocks +fd-find +python3-pip +python3-pynvim +openjdk-21-jdk-headless diff --git a/util/wsl.psm1 b/util/wsl.psm1 new file mode 100644 index 0000000..5fa0cc2 --- /dev/null +++ b/util/wsl.psm1 @@ -0,0 +1,48 @@ +function InstallWSL +{ + # Reference: https://learn.microsoft.com/en-us/windows/wsl/install-manual + dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart + dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart + wsl.exe --update + wsl.exe --set-default-version 2 +} + +function WSLInstall +{ + # Skip if any WSL2 installations can be found + $installations = wsl.exe -l -v + $filtered = $installations | Where-Object { $_.Replace("`0", '') -match '^.{2}Ubuntu' } + $versions = $filtered | ForEach-Object { $_.Substring($_.LastIndexOf(' ') + 1) } + if ($null -ne $versions -and $versions.Contains('2')) + { return + } + + $install = Read-Host "Install WSL2 now? [Y/n]" + if ($install.ToLower() -ne 'n') + { InstallWSL + } + wsl.exe --install -d Ubuntu + + # Add newly created user to sudoers group + $user = wsl.exe cut "-d:" "-f1" /etc/passwd + wsl.exe -u root echo "echo ""$user ALL=(ALL) NOPASSWD:ALL"" >> /etc/sudoers.d/$user" + + # Update packages and install from list + wsl.exe sudo apt update "&&" sudo apt upgrade "-y" + wsl.exe sudo apt install "-y" (Get-Content ./util/wsl.list) +} + +function InstallWSLNeovim +{ + param ( + [string]$source + ) + + Import-Module ./windows.psm1 + + ProcessUrlFiles -sourceDir $source + Set-Location "$env:TMP\nvim-config" + Write-Host "Copying (forcably) configuration to WSL..." -ForegroundColor Yellow + wsl.exe cp -rf . ~/.config/ 2>$null | Out-Null + Set-Location - +}