Compare commits

...

53 Commits

Author SHA1 Message Date
06977c0db5 scrap git repository idea, download as zip only 2024-11-28 16:40:01 +01:00
c15f2c800c bugfix: rename zip installation directory to avoid conflict with git clone 2024-11-28 16:17:06 +01:00
406367b2eb bugfix: force overwrite, create fonts directory 2024-11-28 16:12:55 +01:00
7c86d72ece bugfix: parent of file is directory property 2024-11-28 16:04:33 +01:00
878db9489b bugfix: error on multiple contents of directory 2024-11-28 15:49:20 +01:00
1ed1bb7ef6 compat: fix compatibility with PowerShell 5 2024-11-28 15:17:33 +01:00
f952f8c891 elaborate yet safe installation commands 2024-11-28 15:11:16 +01:00
0c3bd50246 implement fallback strategy in case of local contents 2024-11-28 15:08:23 +01:00
1846230e91 bugfix: check default value and force lowercase 2024-11-28 15:07:58 +01:00
4ab07fb4db bugfix: logic error: pull only if in git repository 2024-11-28 15:07:31 +01:00
0e50978a74 bugfix: use directory's own name instead of full path instead 2024-11-28 14:54:34 +01:00
10d520c12a installing nerd-fonts by copying and registry 2024-11-28 14:17:31 +01:00
56d0f1e209 cleanup: replace custom solution with Path::GetDirName 2024-11-28 14:16:50 +01:00
05de50080a unzip all nerd-font zip archives in parent directory 2024-11-28 14:15:50 +01:00
d79c3bf43f bugfix: removed hardwired path in function 2024-11-25 16:14:47 +01:00
e1029ae1cd bugfix: actually using newly specified parameter 2024-11-25 15:35:53 +01:00
3e07cfaa12 replace with Invoke-WebRequest for optimizations in commit fa7d942 2024-11-25 15:33:04 +01:00
b5a56cd60e ignore command output for commit 94028ef 2024-11-25 15:31:27 +01:00
8995565e26 bugfix: accidentally merged output of commands 2024-11-25 15:28:58 +01:00
97fcc961a7 bugfix: save detected dotfiles repo location 2024-11-25 15:21:47 +01:00
94028eff12 bugfix: create powershell profile directory if not exists 2024-11-25 15:10:09 +01:00
8a4fed4295 bugfix: fix filepath when calling from local dir 2024-11-25 15:06:01 +01:00
fa7d942a8f optimize download without progressbar 2024-11-25 15:03:16 +01:00
107b83ced4 bugfix: create local user fonts directory if not exists 2024-11-25 14:34:36 +01:00
80a34d44c3 bugfix: renamed function parameter in 5090a04 2024-11-25 14:25:44 +01:00
7e8bc5fa19 bugfix: fix command to add user to sudoers group 2024-11-25 12:18:39 +01:00
7aa94ca8e2 provide additional user feedback with consistent style 2024-11-25 12:00:30 +01:00
0da955a90d replace dism.exe for CMD with builtin powershell module 2024-11-25 11:56:41 +01:00
cf885e7363 using wsl install without distro for older versions 2024-11-25 11:54:14 +01:00
72061fd686 remove excess colon in after install prompt 2024-11-25 11:45:47 +01:00
1d33d6ed32 optimize download without progressbar 2024-11-25 11:35:19 +01:00
4ce997d016 replace builtin install method with web request to app installer 2024-11-25 11:26:55 +01:00
24b6d1f115 replace unzip with builtin Expand-Archive tool 2024-11-24 23:41:49 +01:00
52e9367b04 optionally skip config after installation 2024-11-24 23:27:00 +01:00
8ed8d2d411 allow bypassing additional installation steps 2024-11-24 22:59:51 +01:00
eaf1e8e9f3 using push/pop location instead to accommodate for powershell v5 2024-11-24 22:55:12 +01:00
8c6dcd4590 bugfix: set location to dotfiles repo for admin processes 2024-11-24 22:39:20 +01:00
ff07ff7d17 bugfix: remove escaped quotes 2024-11-24 22:32:47 +01:00
7f7fc0a8ba bugfix: fix filepath when calling from local dir 2024-11-24 22:12:46 +01:00
c5c7703e00 Revert "bugfix: fix filepath when calling from local dir"
This reverts commit 1e19a5e1cf.
2024-11-24 22:12:09 +01:00
df70d04ddc bugfix: set bypass policy for admin processes 2024-11-24 21:51:25 +01:00
eed5118341 cleanup: improved minor quality and descriptions 2024-11-24 21:42:00 +01:00
5014da3a46 bugfix: install wsl and windows features as administrator 2024-11-24 21:40:51 +01:00
509ebf7437 bugfix: wait for admin installation process to complete 2024-11-24 21:35:50 +01:00
cb66813a8b bugfix: typos in function names (switcheroo) 2024-11-24 21:32:45 +01:00
9cc28a14e1 bugfix: call 'InstallWinget' with admin privileges 2024-11-24 21:29:15 +01:00
1e19a5e1cf bugfix: fix filepath when calling from local dir 2024-11-24 21:28:57 +01:00
e2edd0122e replace concrete commands with reference to installation modules 2024-11-24 21:17:39 +01:00
ec067674d3 add wsl/apt installation module 2024-11-24 21:15:14 +01:00
d95ba9823d add chocolatey installation module 2024-11-24 21:14:55 +01:00
3a849a448f add winget installation module 2024-11-24 21:14:46 +01:00
5090a04e95 rename function parameter for naming consistency 2024-11-24 21:12:23 +01:00
ad9ffc0a19 modularize windows install script by extracting functions 2024-11-24 18:41:24 +01:00
9 changed files with 406 additions and 208 deletions

View File

@ -33,31 +33,8 @@ These tools include the following for Windows Installs (Recommended using [Choco
- [Python](https://www.python.org/)
- [Composer](https://getcomposer.org/)
<details><summary>Windows Subsystem for Linux</summary>
```bash
sudo apt update
curl -fsSL https://deb.nodesource.com/setup_lts.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo add-apt-repository ppa:neovim-ppa/unstable -y
sudo apt install make gcc ripgrep unzip git xclip neovim nodejs python3-venv
curl https://sh.rustup.rs -sSf | sh
curl -LO https://go.dev/dl/go1.23.2.linux-amd64.tar.gz
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.23.2.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
```
</details>
<details><summary>Winget and Chocolatey</summary>
```pwsh
winget install chocolatey.chocolatey Neovide.Neovide Alacritty.Alacritty Git.Git GoLang.Go Microsoft.DotNet.SDK.8 OpenJS.NodeJS.LTS Python.Python.3.12 Rustlang.Rustup
choco install neovim ripgrep curl wget fd unzip gzip mingw make
```
</details>
> **NOTE**
> For more information, simply see all [util/](./util) installation modules.
## Installation
@ -73,6 +50,9 @@ Alternatively, feel free to run the [install script](./install_windows.ps1) afte
cloning the repository or directly execute it from shell:
```pwsh
# Using 'Invoke-RestMethod' and 'Invoke-Expression'
irm 'https://raw.githubusercontent.com/Baipyrus/dotfiles/main/install_windows.ps1' | iex
irm https://api.github.com/repos/Baipyrus/dotfiles/zipball -O "$env:TMP\dotfiles.zip"
Expand-Archive "$env:TMP\dotfiles.zip" -D "$env:TMP\dotfiles" -F
gci "$env:TMP\dotfiles\**\install_windows.ps1" | select -F 1 | % {
saps powershell.exe -Wait -Wo $_.DirectoryName -A "-Ex", "Bypass", "-F", $_.FullName
}
```

View File

@ -1,154 +1,30 @@
Import-Module ./util/chocolatey.psm1
Import-Module ./util/windows.psm1
Import-Module ./util/winget.psm1
Import-Module ./util/wsl.psm1
# (Optionally) Install required Software
WingetInstall
ChocolateyInstall
WSLInstall
Write-Host "Installation Steps complete!" -ForegroundColor Cyan
$continue = Read-Host "Continue with configuration? [Y/n]"
if ($continue.ToLower() -eq 'n')
{ return
}
# Define paths for tools and configurations
$dotfilesRepo = "$env:TMP\dotfiles"
$dotfilesRepo = (Get-Location).Path
$alacrittyConfigDir = "$env:APPDATA\alacritty"
$psProfile = "$env:USERPROFILE\Documents\PowerShell\Microsoft.PowerShell_profile.ps1"
$repoUrl = "https://github.com/Baipyrus/dotfiles.git"
# Function to determine if the current directory is the dotfiles repository
function IsGitRepository
{
param (
[string]$dir,
[string]$url
)
try
{
$isRepo = git -C $dir rev-parse --is-inside-work-tree 2>$null
$originUrl = git -C $dir remote get-url origin 2>$null
return $isRepo -eq 'true' -and $originUrl -eq $url
} catch
{
return $false
}
}
# Check if the script is running inside the dotfiles repository
$currentDir = (Get-Location).Path
if (IsGitRepository -dir $currentDir -url $repoUrl)
{
Write-Host "Already inside the dotfiles repository. Skipping clone step and pulling..." -ForegroundColor Yellow
$dotfilesRepo = $currentDir
git pull
} else
{
# Clone dotfiles repository to TMP if not already inside it
if (-not (Test-Path $dotfilesRepo))
{
Write-Host "Cloning dotfiles repository..." -ForegroundColor Cyan
git clone $repoUrl $dotfilesRepo
} else
{
Write-Host "Pulling latest changes from dotfiles repository..." -ForegroundColor Cyan
git -C $dotfilesRepo pull
}
}
# Function to copy files with overwrite prompt
function CopyFileWithPrompt
{
param (
[string]$source,
[string]$destination
)
if (Test-Path $destination)
{
$overwrite = Read-Host "File $destination exists. Overwrite? (y/n)"
if ($overwrite -ne 'y')
{
Write-Host "Skipping $destination" -ForegroundColor Yellow
return
}
}
Copy-Item -Path $source -Destination $destination -Force
}
# Function to handle URL files: download files or clone repositories
function ProcessUrlFiles
{
param (
[string]$sourceDir,
[Parameter(Mandatory=$false)][string]$destinationDir,
[Parameter(Mandatory=$false)][string]$fileExt
)
# Ensure the destination directory exists
if ($destinationDir -and (-not (Test-Path $destinationDir)))
{
Write-Host "Creating destination directory $destinationDir..." -ForegroundColor Cyan
New-Item -ItemType Directory -Path $destinationDir | Out-Null
}
# Create temporary directory for curl
$appname = $sourceDir.Split('\')[-1]
$tmpApp = "$env:TMP\$appname-config"
if (-not (Test-Path $tmpApp))
{ New-Item -ItemType Directory -Path $tmpApp | Out-Null
}
Set-Location $tmpApp
# Find all .url files in the source directory
$urlFiles = Get-ChildItem -Path $sourceDir -Filter '*.url'
foreach ($file in $urlFiles)
{
$url = Get-Content $file.FullName
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($file.Name)
$destinationPath = "$destinationDir\$fileName"
if (-not ($url -match 'git@|https://.*\.git'))
{
# Otherwise, download the file
$extension = [System.IO.Path]::GetExtension($url)
# Force apply $fileExt if given
if ($fileExt)
{
$extension = $fileExt
$url += $fileExt
}
$destinationPath = "$destinationDir\$fileName$extension"
# Respond only if destination is provided
$conditional = " to $destinationPath"
if (-not $destinationDir)
{ $conditional = ''
}
Write-Host "Downloading $fileName from $url$conditional..." -ForegroundColor Cyan
Invoke-RestMethod $url -OutFile $fileName$extension
$tmpDestination = "$tmpApp\$fileName$extension"
# Copy only if destination is provided
if ($destinationDir)
{ CopyFileWithPrompt $tmpDestination $destinationPath
}
continue
}
# Use $tmpApp as destination in case of git repo
if (-not $destinationDir)
{ $destinationPath = "$tmpApp\$fileName"
}
# If the URL is a git repository, pull it
if (IsGitRepository -dir $destinationPath -url $url)
{
Write-Host "Pulling inside existing repository $fileName..." -ForegroundColor Cyan
git -C $destinationPath pull
continue
}
# Or otherwise clone it
Write-Host "Cloning $fileName from $url to $destinationPath..." -ForegroundColor Cyan
git clone $url $destinationPath
}
Set-Location -
}
# Setting up Alacritty Configuration
Write-Host "Setting up Alacritty configuration..." -ForegroundColor Cyan
ProcessUrlFiles -sourceDir "$dotfilesRepo\alacritty" -destinationDir $alacrittyConfigDir
ProcessUrlFiles -source "$dotfilesRepo\alacritty" -destination $alacrittyConfigDir
# Copy the main Alacritty configuration file
CopyFileWithPrompt "$dotfilesRepo\alacritty\alacritty.toml" "$alacrittyConfigDir\alacritty.toml"
@ -157,19 +33,19 @@ CopyFileWithPrompt "$dotfilesRepo\alacritty\alacritty.toml" "$alacrittyConfigDir
Write-Host "Setting up Neovim configuration..." -ForegroundColor Cyan
$ubuntu = wsl.exe -l --all | Where-Object { $_.Replace("`0", "") -match '^Ubuntu' }
if ($null -eq $ubuntu)
{ ProcessUrlFiles -sourceDir "$dotfilesRepo\nvim" -destinationDir "$env:LOCALAPPDATA"
{ 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
Write-Host "Setting up PowerShell profile..." -ForegroundColor Cyan
# Create local PowerShell profile directory
$psDir = Split-Path -Path $psProfile
if (-not (Test-Path $psDir))
{ New-Item -ItemType Directory -Path $psDir | Out-Null
}
# Copy existing startup script to destination
CopyFileWithPrompt "$dotfilesRepo\PowerShell\Microsoft.PowerShell_profile.ps1" $psProfile
# Setting up self-made ProxySwitcher
@ -178,37 +54,11 @@ Write-Host "Setting up ProxySwitcher via subscript..." -ForegroundColor Cyan
Invoke-RestMethod 'https://raw.githubusercontent.com/Baipyrus/ProxySwitcher/main/install.ps1' | Invoke-Expression
Write-Host "============================================" -ForegroundColor DarkGray
function UnzipAndInstall
{
param (
[string]$source
)
# Create temporary directory for unzip
$appname = $source.Split('\')[-1]
$tmpApp = "$env:TMP\$appname-config"
if (-not (Test-Path $tmpApp))
{ New-Item -ItemType Directory -Path $tmpApp | Out-Null
}
# Find all .url files in the source directory
$urlFiles = Get-ChildItem -Path $source -Filter '*.url'
foreach ($file in $urlFiles)
{
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($file.Name)
Write-Host "Extracting archive $tmpApp\$fileName.zip to $tmpApp\$fileName\..." -ForegroundColor Cyan
unzip -o "$tmpApp\$fileName.zip" -d "$tmpApp\$fileName" | Out-Null
Write-Host "Installing fonts from $tmpApp\$fileName\ for current user..." -ForegroundColor Cyan
Copy-Item -Path "$tmpApp\$fileName\*" -Destination "$env:LOCALAPPDATA\Microsoft\Windows\Fonts\" -Force -ErrorAction SilentlyContinue
}
}
# Installing Nerd Fonts
Write-Host "Installing Nerd Fonts..." -ForegroundColor Cyan
ProcessUrlFiles -sourceDir "$dotfilesRepo\nerd-fonts" -fileExt ".zip"
UnzipAndInstall -source "$dotfilesRepo\nerd-fonts"
ProcessUrlFiles -source "$dotfilesRepo\nerd-fonts" -fileExt ".zip" -progress $false
Get-ChildItem -Path "$env:TMP\nerd-fonts-config" -Filter "*.zip" | `
ForEach-Object { InstallNerdFont -source $_.FullName }
# Final message
Write-Host "Windows setup complete!" -ForegroundColor Green

10
util/chocolatey.list Normal file
View File

@ -0,0 +1,10 @@
neovim
ripgrep
wget
curl
fd
unzip
gzip
mingw
make
composer

17
util/chocolatey.psm1 Normal file
View File

@ -0,0 +1,17 @@
function InstallPackages
{
choco.exe install (Get-Content ./util/chocolatey.list)
}
function ChocolateyInstall
{
$install = Read-Host "Install Chocolatey Packages now? [Y/n]"
if ($install.ToLower() -eq 'n')
{ return
}
# Start admin process, import this script, run 'InstallPackages' function
Start-Process powershell.exe -Verb RunAs -Wait `
-ArgumentList "-ExecutionPolicy", "Bypass", `
"-C", "cd $pwd; ipmo ./util/chocolatey.psm1; InstallPackages"
}

216
util/windows.psm1 Normal file
View File

@ -0,0 +1,216 @@
# Function to determine if the current directory is the dotfiles repository
function IsGitRepository
{
param (
[string]$dir,
[string]$url
)
try
{
$isRepo = git -C $dir rev-parse --is-inside-work-tree 2>$null
$originUrl = git -C $dir remote get-url origin 2>$null
return $isRepo -eq 'true' -and $originUrl -eq $url
} catch
{
return $false
}
}
# Function to copy files with overwrite prompt
function CopyFileWithPrompt
{
param (
[string]$source,
[string]$destination
)
if (Test-Path $destination)
{
$overwrite = Read-Host "File $destination exists. Overwrite? (y/N)"
if ($overwrite.ToLower() -ne 'y')
{
Write-Host "Skipping $destination" -ForegroundColor Yellow
return
}
}
Copy-Item -Path $source -Destination $destination -Force
}
# Function to handle URL files: download files or clone repositories
function ProcessUrlFiles
{
param (
[string]$source,
[Parameter(Mandatory=$false)][string]$destination,
[Parameter(Mandatory=$false)][string]$fileExt,
[bool]$progress=$true
)
# Disable progressbar for faster download
$progressPreference = 'continue'
if (-not $progress)
{ $progressPreference = 'silentlyContinue'
}
# Ensure the destination directory exists
if ($destination -and (-not (Test-Path $destination)))
{
Write-Host "Creating destination directory $destination..." -ForegroundColor Cyan
New-Item -ItemType Directory -Path $destination | Out-Null
}
# Create temporary directory for curl
$appname = Split-Path -Leaf $source
$tmpApp = "$env:TMP\$appname-config"
if (-not (Test-Path $tmpApp))
{ New-Item -ItemType Directory -Path $tmpApp | Out-Null
}
Push-Location
Set-Location $tmpApp
# Find all .url files in the source directory
$urlFiles = Get-ChildItem -Path $source -Filter '*.url'
foreach ($file in $urlFiles)
{
$url = Get-Content $file.FullName
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($file.Name)
$destinationPath = "$destination\$fileName"
if (-not ($url -match 'git@|https://.*\.git'))
{
# Otherwise, download the file
$extension = [System.IO.Path]::GetExtension($url)
# Force apply $fileExt if given
if ($fileExt)
{
$extension = $fileExt
$url += $fileExt
}
$destinationPath = "$destination\$fileName$extension"
# Respond only if destination is provided
$conditional = " to $destinationPath"
if (-not $destination)
{ $conditional = ''
}
Write-Host "Downloading $fileName from $url$conditional..." -ForegroundColor Cyan
Invoke-WebRequest $url -OutFile $fileName$extension
$tmpDestination = "$tmpApp\$fileName$extension"
# Copy only if destination is provided
if ($destination)
{ CopyFileWithPrompt $tmpDestination $destinationPath
}
continue
}
# Use $tmpApp as destination in case of git repo
if (-not $destination)
{ $destinationPath = "$tmpApp\$fileName"
}
# If the URL is a git repository, pull it
if (IsGitRepository -dir $destinationPath -url $url)
{
Write-Host "Pulling inside existing repository $fileName..." -ForegroundColor Cyan
git -C $destinationPath pull
continue
}
# Or otherwise clone it
Write-Host "Cloning $fileName from $url to $destinationPath..." -ForegroundColor Cyan
git clone $url $destinationPath
}
Pop-Location
}
# Function to unzip and install nerd fonts
function InstallNerdFont
{
param (
[string]$source
)
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($source)
$parent = Get-ChildItem $source | `
Select-Object -ExpandProperty Directory | `
Select-Object -ExpandProperty FullName
$destination = "$parent\$fileName"
# Create destination directory
if (-not (Test-Path $destination))
{ New-Item -ItemType Directory -Path $destination | Out-Null
}
# Extract contents of zip archive
Write-Host "Extracting archive $source to $destination..." -ForegroundColor Cyan
Expand-Archive $source -DestinationPath $destination -Force | Out-Null
# Install extracted fonts
$fontFiles = Get-ChildItem -Path $destination -Include "*.ttf", "*.otf"
foreach ($font in $fontFiles)
{
InstallFont $font
}
}
# Reference: https://www.alkanesolutions.co.uk/2021/12/06/installing-fonts-with-powershell/
function InstallFont
{
param
(
[System.IO.FileInfo]$file
)
# Prerequisites / Constants
Add-Type -AssemblyName PresentationCore
$destination = "$env:LOCALAPPDATA\Microsoft\Windows\Fonts\"
$regKey = "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Fonts"
# Create destination directory
if (-not (Test-Path $destination))
{ New-Item -ItemType Directory -Path $destination | Out-Null
}
# Get Glyph
$glyph = New-Object -TypeName Windows.Media.GlyphTypeface -ArgumentList $file.FullName
$family = $glyph.Win32FamilyNames['en-us']
if ($null -eq $family)
{ $family = $glyph.Win32FamilyNames.Values | Select-Object -First 1
}
$face = $glyph.Win32FaceNames['en-us']
if ($null -eq $face)
{ $face = $glyph.Win32FaceNames.Values | Select-Object -First 1
}
$name = ("$family $face").Trim()
switch ($file.Extension)
{
".ttf"
{ $name = "$name (TrueType)"
}
".otf"
{ $name = "$name (OpenType)"
}
}
$destFileName = Join-Path -Path $destination -ChildPath $file.Name
Write-Host "Installing font: $file with font name '$name'"
If (-not (Test-Path $destFileName))
{ Copy-Item -Path $file.FullName -Destination $destFileName -Force
}
Write-Host "Registering font: $file with font name '$name'"
$keyValue = Get-ItemProperty -Name $name -Path $regKey -ErrorAction SilentlyContinue
If (-not $keyValue)
{
New-ItemProperty -Name $name -Path $regKey `
-PropertyType string -Value $file.Name `
-Force -ErrorAction SilentlyContinue | Out-Null
}
}

11
util/winget.list Normal file
View File

@ -0,0 +1,11 @@
Git.Git
Microsoft.OpenJDK.21
Alacritty.Alacritty
OpenJS.NodeJS.LTS
Chocolatey.Chocolatey
Microsoft.DotNet.SDK.8
Microsoft.PowerShell
GoLang.Go
Python.Python.3.12
Rustlang.Rustup
rjpcomputing.luaforwindows

39
util/winget.psm1 Normal file
View File

@ -0,0 +1,39 @@
function InstallWinget
{
$progressPreference = 'silentlyContinue'
$download = 'https://api.github.com/repos/microsoft/winget-cli/releases/latest'
$setup = "$env:TMP\winget_setup.msixbundle"
if (-not (Test-Path $setup))
{
$releases = Invoke-RestMethod $download
$assets = $releases | Select-Object -ExpandProperty "assets"
$installer = $assets | Where-Object "name" -Match "msixbundle"
$url = $installer | Select-Object -ExpandProperty "browser_download_url"
Write-Host "Downloading WinGet '.msixbundle' installer ..."
Invoke-WebRequest $url -OutFile $setup
}
Write-Host "Installing WinGet app package..."
Add-AppxPackage -Path $setup
}
function WingetInstall
{
$update = Read-Host "Install/Update WinGet now? [Y/n]"
if ($update.ToLower() -ne 'n')
{
# Start admin process, import this script, run 'InstallPackages' function
Start-Process powershell.exe -Verb RunAs -Wait `
-ArgumentList "-ExecutionPolicy", "Bypass", `
"-C", "cd $pwd; ipmo ./util/winget.psm1; InstallWinget"
}
$install = Read-Host "Install WinGet Packages now? [Y/n]"
if ($install.ToLower() -eq 'n')
{ return
}
winget.exe install -s winget --accept-source-agreements (Get-Content ./util/winget.list)
}

14
util/wsl.list Normal file
View File

@ -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

61
util/wsl.psm1 Normal file
View File

@ -0,0 +1,61 @@
function InstallWSL
{
Write-Host "Enabling and downloading required Windows Features..."
Enable-WindowsOptionalFeature -Online -FeatureName "Microsoft-Windows-Subsystem-Linux" -All -NoRestart | Out-Null
Enable-WindowsOptionalFeature -Online -FeatureName "VirtualMachinePlatform" -All -NoRestart | Out-Null
Write-Host "Installing WSL2..."
wsl.exe --install --no-distribution
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
}
$update = Read-Host "Install/Update WSL2 now? [Y/n]"
if ($update.ToLower() -ne 'n')
{
# Start admin process, import this script, run 'InstallPackages' function
Start-Process powershell.exe -Verb RunAs -Wait `
-ArgumentList "-ExecutionPolicy", "Bypass", `
"-C", "cd $pwd; ipmo ./util/wsl.psm1; InstallWSL"
}
$install = Read-Host "Install WSL Distribution now? [Y/n]"
if ($install.ToLower() -eq 'n')
{ return
}
wsl.exe --install -d Ubuntu
# Add newly created user to sudoers group
$user = wsl.exe cut "-d:" "-f1" /etc/passwd | Select-Object -Last 1
wsl.exe -u root 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 ./util/windows.psm1
Push-Location
ProcessUrlFiles -source $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
Pop-Location
}