Last active
March 20, 2023 01:09
-
-
Save KZeronimo/bdae1f83e6de7800bf8b5309407cc909 to your computer and use it in GitHub Desktop.
Chocolatey based Boxstarter Script - Bootstrap Metal - Win 10,11
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
# Set TLS 1.2 | |
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 | |
# Import Choco Install-* | |
Import-Module "$env:ChocolateyInstall\helpers\chocolateyInstaller.psm1" -Force | |
# Set up choco cache location to work around Boxstarter Issue 241 | |
$chocoCache = (Join-Path ([Environment]::GetEnvironmentVariable("LocalAppData")) "Temp\ChocoCache") | |
New-Item -Path $chocoCache -ItemType directory -Force | |
# Remove *.tmp from the choco cache directory so the ad-hoc package installs using Install-ChocolateyPackage behave idempotently - this is a hack | |
Remove-Item -Path (Join-Path $chocoCache '*.tmp') -Recurse -Force | |
# Get Post Build Content | |
Write-BoxstarterMessage "Getting post build content" | |
$path = "C:\_PostBuildContent" | |
$answersPath = "C:\Windows\Temp\User_Answers.json" | |
if (Test-Path -Path $path) { | |
Remove-Item -Path $path -Recurse | |
} | |
Invoke-WebRequest -UseBasicParsing https://github.com/KZeronimo/PostBuildContent/archive/refs/heads/master.zip -OutFile C:\PostBuildContent.zip | |
Expand-Archive -Path C:\PostBuildContent.zip -DestinationPath $path | |
Move-Item (Join-Path $path 'PostBuildContent-master\*') $path | |
if (Test-Path $answersPath) { | |
Copy-Item $answersPath -Destination (Join-Path $path 'User_Answers.json') | |
} | |
Remove-Item -Path (Join-Path $path 'PostBuildContent-master') | |
Remove-Item -Path C:\PostBuildContent.zip | |
# Configure Windows Explorer Options | |
Set-WindowsExplorerOptions -EnableShowFileExtensions -EnableShowHiddenFilesFoldersDrives -EnableShowFullPathInTitleBar | |
# Trust PSGallery | |
Get-PackageProvider -Name NuGet -ForceBootstrap | |
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted | |
# Install Source Code Pro and Nerd Fonts | |
Write-BoxstarterMessage "Installing Source Code Pro and Source Code Pro Nerd Fonts" | |
cinst sourcecodepro --cacheLocation $chocoCache | |
cinst nerd-fonts-sourcecodepro --cacheLocation $chocoCache | |
# Install Cascadia Code Nerd Font | |
Write-BoxstarterMessage "Installing Cascadia Code Nerd & PL Font" | |
cinst nerd-fonts-cascadiacode --cacheLocation $chocoCache | |
$latestBrowserDownloadUrl = Invoke-WebRequest -UseBasicParsing -Uri "https://api.github.com/repos/microsoft/cascadia-code/releases/latest" | ConvertFrom-Json | Select-Object -ExpandProperty assets | Select-Object -ExpandProperty browser_download_url | Where-Object { $_ -match '.*\/[^\/]*OTF[^\/]*\.zip$|.*\/[^\/]*\.zip$' } | Select-Object -First 1 | |
& C:\_PostBuildContent\helpers\install-font.ps1 -Url $latestBrowserDownloadUrl -FontFilesFilter '*.otf' | |
# Install oh-my-posh | |
Write-BoxstarterMessage "Installing posh-git and oh-my-posh" | |
Install-Module -Name posh-git -Scope CurrentUser | |
cinst oh-my-posh --cacheLocation $chocoCache | |
# Install PowerShell Core | |
Write-BoxstarterMessage "Installing PowerShell Core" | |
cinst powershell-core --cacheLocation $chocoCache | |
# Install Git (core credential mgr intalled with git for windows) | |
Write-BoxstarterMessage "Installing Git" | |
cinst git -params '"/GitAndUnixToolsOnPath"' --cacheLocation $chocoCache | |
# Install Visual Studio Code | |
Write-BoxstarterMessage "Installing VS Code" | |
cinst visualstudiocode --cacheLocation $chocoCache | |
# Install Notepad++ | |
Write-BoxstarterMessage "Installing Notepad++" | |
cinst notepadplusplus --cacheLocation $chocoCache | |
# Install Google Chrome | |
Write-BoxstarterMessage "Installing Chrome" | |
cinst googlechrome --cacheLocation $chocoCache | |
# Refresh Environment | |
Write-BoxstarterMessage "Refresh Environment" | |
refreshenv | |
# Create root folder structure | |
Write-BoxstarterMessage "Creating root folder structure" | |
New-Item -Path "C:\_Src" -Type Directory -Force | |
New-Item -Path "C:\_Src\Prod" -Type Directory -Force | |
New-Item -Path "C:\_Src\Prod\Mesh" -Type Directory -Force | |
New-Item -Path "C:\_Src\Sdbx" -Type Directory -Force | |
# Remove Desktop Shortcuts | |
Write-BoxstarterMessage "Removing desktop shortcuts" | |
Get-ChildItem -Path "C:\Users\*\Desktop\*" -Recurse -Include *.lnk | Remove-Item -Force | |
# Deploy post build content | |
Write-BoxstarterMessage "Deploying post build content" | |
if (! (Test-Path -Path (Join-Path $env:UserProfile ".gitconfig"))) { | |
Copy-Item "C:\_PostBuildContent\git\.gitconfig" -Destination $env:UserProfile -Force | |
} | |
Copy-Item "C:\_PostBuildContent\terminal\Microsoft.PowerShell_profile.ps1" -Destination (New-Item (Join-Path $env:UserProfile "Documents\WindowsPowerShell") -Type container -Force) -Force | |
Copy-Item "C:\_PostBuildContent\terminal\Microsoft.PowerShell_profile.ps1" -Destination (New-Item (Join-Path $env:UserProfile "Documents\PowerShell") -Type container -Force) -Force | |
Copy-Item "C:\_PostBuildContent\terminal\wt_profiles_settings.json" -Destination (Join-Path $env:LocalAppData "Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json") -Force | |
Copy-Item "C:\_PostBuildContent\terminal\agnoster-mesh.omp.json" -Destination (Join-Path $env:LocalAppData "Programs\oh-my-posh\themes\agnoster-mesh.omp.json") -Force | |
Copy-Item -Path "C:\_PostBuildContent\themes\*" -Destination (New-Item (Join-Path $env:UserProfile "Pictures\Themes") -Type container -Force) -Recurse -Force | |
Copy-Item -Path "C:\_PostBuildContent\layouts\*" -Destination $env:LocalAppData -Recurse -Force | |
# Configure my .gitconfig | |
Write-BoxstarterMessage "Customizing gitconfig" | |
& C:\_PostBuildContent\git\configure-my-gitconfig.ps1 | |
# Setup configuration and dotfile tracking | |
$path = Join-Path $env:UserProfile ".myconf" | |
New-Item -Path ($path) -Type Directory -Force | |
Set-Location -Path $path | |
if (! (Test-Path -Path "HEAD")) { | |
Write-BoxstarterMessage "Setting up configuration and dotfile tracking" | |
git init --bare $path | |
Write-Output '*' >> $env:UserProfile/.myconf/info/exclude | |
} | |
# Clone OneFlow Repo | |
Set-Location -Path C:\_Src\Prod\Mesh | |
$path = "https://meshsystems@dev.azure.com/meshsystems/Mesh%20Systems/_git/Mesh.DevAutomation.OneFlow" | |
if (! (Test-Path -Path ($path -split '/')[-1])) { | |
Write-BoxstarterMessage "Cloning OneFlow repo" | |
git clone $path | |
} | |
# Clone DotNet Templates Repo | |
Set-Location -Path C:\_Src\Prod\Mesh | |
$path = "https://meshsystems@dev.azure.com/meshsystems/Mesh%20Systems/_git/Mesh.DotNet.Templates" | |
if (! (Test-Path -Path ($path -split '/')[-1])) { | |
Write-BoxstarterMessage "Cloning DotNet Templates repo" | |
git clone $path | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment