Last active
March 4, 2022 11:13
-
-
Save rapgru/ad98b0b3beed0e5d3ed02d127d975a6e to your computer and use it in GitHub Desktop.
Boxstarter Script for Setting up My Laptop
This file contains hidden or 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
<# | |
Description: Boxstarter script for a development machine with VS 2019 and Ubuntu WSL with nix | |
Author: https://github.com/rapgru | |
Last Updated: 23.04.2020 | |
#> | |
# ---- Init ---- # | |
Update-ExecutionPolicy Unrestricted | |
# Workaround for nested chocolatey folders resulting in path too long error | |
$ChocoCachePath = "C:\Temp" | |
New-Item -Path $ChocoCachePath -ItemType directory -Force | |
# Temporary | |
Disable-UAC | |
# ---- Variables and "embedded" files ---- # | |
$Boxstarter.RebootOk=$true # Allow reboots? | |
$Boxstarter.NoPassword=$false # Is this a machine with no login password? | |
$Boxstarter.AutoLogin=$true # Save my password securely and auto-login after a reboot | |
$VSCodeConfigURL = "https://git.io/JftTN" | |
$VSCodeConfig = (Invoke-WebRequest -UseBasicParsing "$VSCodeConfigURL").Content | |
$MicrosoftTerminalConfigURL = "https://git.io/JftTh" | |
$MicrosoftTerminalConfig = (Invoke-WebRequest -UseBasicParsing "$MicrosoftTerminalConfigURL").Content | |
$VSCodeExtensionsURL = "https://git.io/JftTQ" | |
$VSCodeExtensionsList = (Invoke-WebRequest -UseBasicParsing "$VSCodeExtensionsURL" | ConvertFrom-Json).extensions | |
$WSLProvisionURL = "https://git.io/JftFY" | |
$WSLProvision = (Invoke-WebRequest -UseBasicParsing "$WSLProvisionURL").Content.Replace("{{home_folder}}", $Home.Replace("\", "/").Replace("C:/", "/mnt/c/")) | |
# ---- Explorer ---- # | |
Set-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives ` | |
-EnableShowFileExtensions -DisableShowFullPathInTitleBar ` | |
-EnableShowRecentFilesInQuickAccess -EnableShowFrequentFoldersInQuickAccess ` | |
-EnableShowRibbon | |
# ---- Scheduled Tasks ---- # | |
# Disable defrag (no need when having an SSD) | |
Get-ScheduledTask -TaskName *defrag* | Disable-ScheduledTask | |
# ---- Delete windows bloatware ---- # | |
# 3D Builder | |
# Get-AppxPackage Microsoft.3DBuilder | Remove-AppxPackage | |
# Alarms | |
# Get-AppxPackage Microsoft.WindowsAlarms | Remove-AppxPackage | |
# Autodesk | |
Get-AppxPackage *Autodesk* | Remove-AppxPackage | |
Get-AppxPackage XINGAG.XING | Remove-AppxPackage | |
# Bing Weather, News, Sports, and Finance (Money): | |
Get-AppxPackage Microsoft.BingFinance | Remove-AppxPackage | |
Get-AppxPackage Microsoft.BingNews | Remove-AppxPackage | |
Get-AppxPackage Microsoft.BingSports | Remove-AppxPackage | |
# Get-AppxPackage Microsoft.BingWeather | Remove-AppxPackage | |
# BubbleWitch | |
Get-AppxPackage *BubbleWitch* | Remove-AppxPackage | |
# Candy Crush | |
Get-AppxPackage king.com.CandyCrush* | Remove-AppxPackage | |
# Disney Magic Kingdom | |
Get-AppxPackage *DisneyMagicKingdom* | Remove-AppxPackage | |
# Dropbox | |
Get-AppxPackage *Dropbox* | Remove-AppxPackage | |
Get-AppxPackage *Facebook* | Remove-AppxPackage | |
# Feedback Hub | |
# Get-AppxPackage Microsoft.WindowsFeedbackHub | Remove-AppxPackage | |
# Get Started | |
# Get-AppxPackage Microsoft.Getstarted | Remove-AppxPackage | |
# Hidden City: Hidden Object Adventure | |
Get-AppxPackage *HiddenCityMysteryofShadows* | Remove-AppxPackage | |
# Keeper | |
Get-AppxPackage *Keeper* | Remove-AppxPackage | |
# Mail & Calendar | |
Get-AppxPackage microsoft.windowscommunicationsapps | Remove-AppxPackage | |
# Maps | |
# Get-AppxPackage Microsoft.WindowsMaps | Remove-AppxPackage | |
# March of Empires | |
Get-AppxPackage *MarchofEmpires* | Remove-AppxPackage | |
# Messaging | |
Get-AppxPackage Microsoft.Messaging | Remove-AppxPackage | |
# Minecraft | |
Get-AppxPackage *Minecraft* | Remove-AppxPackage | |
# Netflix | |
# Get-AppxPackage *Netflix* | Remove-AppxPackage | |
# Office Hub | |
Get-AppxPackage Microsoft.MicrosoftOfficeHub | Remove-AppxPackage | |
# One Connect | |
Get-AppxPackage Microsoft.OneConnect | Remove-AppxPackage | |
# OneNote | |
# Get-AppxPackage Microsoft.Office.OneNote | Remove-AppxPackage | |
# People | |
Get-AppxPackage Microsoft.People | Remove-AppxPackage | |
# Phone | |
Get-AppxPackage Microsoft.WindowsPhone | Remove-AppxPackage | |
# Photos | |
# Get-AppxPackage Microsoft.Windows.Photos | Remove-AppxPackage | |
# Plex | |
Get-AppxPackage *Plex* | Remove-AppxPackage | |
# Skype (Metro version) | |
Get-AppxPackage Microsoft.SkypeApp | Remove-AppxPackage | |
# Sound Recorder | |
#Get-AppxPackage Microsoft.WindowsSoundRecorder | Remove-AppxPackage | |
# Solitaire | |
Get-AppxPackage *Solitaire* | Remove-AppxPackage | |
# Sticky Notes | |
# Get-AppxPackage Microsoft.MicrosoftStickyNotes | Remove-AppxPackage | |
# Sway | |
Get-AppxPackage Microsoft.Office.Sway | Remove-AppxPackage | |
Get-AppxPackage *Twitter* | Remove-AppxPackage | |
# Xbox | |
#Get-AppxPackage Microsoft.XboxApp | Remove-AppxPackage | |
#Get-AppxPackage Microsoft.XboxIdentityProvider | Remove-AppxPackage | |
# Zune Music, Movies & TV | |
Get-AppxPackage Microsoft.ZuneMusic | Remove-AppxPackage | |
Get-AppxPackage Microsoft.ZuneVideo | Remove-AppxPackage | |
# ---- General Program installs ---- # | |
cinst geogebra-classic.install --cacheLocation $ChocoCachePath | |
cinst windirstat --cacheLocation $ChocoCachePath | |
cinst wireshark --cacheLocation $ChocoCachePath | |
cinst firacode --cacheLocation $ChocoCachePath | |
cinst anki --cacheLocation $ChocoCachePath | |
cinst adobereader --cacheLocation $ChocoCachePath | |
cinst chocolatey --cacheLocation $ChocoCachePath | |
cinst unifying --cacheLocation $ChocoCachePath | |
cinst virtualbox --params "/NoDesktopShortcut" --cacheLocation $ChocoCachePath | |
cinst vagrant --cacheLocation $ChocoCachePath | |
cinst vivaldi.install --cacheLocation $ChocoCachePath | |
cinst microsoft-office-deployment --params "/64bit /Product=O365HomePremRetail /Language=de-de" --cacheLocation $ChocoCachePath | |
cinst microsoft-windows-terminal --cacheLocation $ChocoCachePath | |
cinst spotify --cacheLocation $ChocoCachePath | |
cinst garmin-basecamp --cacheLocation $ChocoCachePath | |
cinst aiirc --cacheLocation $ChocoCachePath | |
cinst uplay --cacheLocation $ChocoCachePath | |
cinst calibre --cacheLocation $ChocoCachePath | |
cinst discord --cacheLocation $ChocoCachePath | |
cinst deluge --cacheLocation $ChocoCachePath | |
cinst etcher --cacheLocation $ChocoCachePath | |
cinst firefox --cacheLocation $ChocoCachePath | |
cinst gimp --cacheLocation $ChocoCachePath | |
cinst jabref --cacheLocation $ChocoCachePath | |
cinst signal --cacheLocation $ChocoCachePath | |
cinst thunderbird --cacheLocation $ChocoCachePath | |
# ---- Git ---- # | |
# Download https://github.com/git-for-windows/git/releases/latest/download/MinGit-2.26.2-64-bit.zip | |
# Latest release via github api | |
if(!(Get-Command git -ErrorAction SilentlyContinue)) { | |
$gitDir = "$env:LOCALAPPDATA\CustomGit" | |
if(Test-Path $gitDir) { Remove-Item -Path $gitDir -Recurse -Force } | |
New-Item -Path $gitDir -ItemType Directory | |
$gitLatestReleaseApi = (Invoke-WebRequest -UseBasicParsing https://api.github.com/repos/git-for-windows/git/releases/latest).Content | ConvertFrom-Json | |
$mingitObject = $gitLatestReleaseApi.assets ` | |
| Where-Object {$_.name -match "MinGit-[\d.]*?-64-bit.zip"} ` | |
| Select-Object browser_download_url | |
Write-Host "Matching asset count: $((Measure-Object -InputObject $mingitObject).Count)" | |
if ((Measure-Object -InputObject $mingitObject).Count -eq 1) { | |
$mingitObject ` | |
| ForEach-Object { Invoke-WebRequest -Uri $_.browser_download_url -UseBasicParsing -OutFile "$gitDir\mingit.zip" } | |
Write-Host "Installing latest release fetched from github api!" | |
} else { | |
Write-Host "There were more than one mingit assets found in the latest release!" | |
Write-Host "Installing release 2.26.2 instead!" | |
Invoke-WebRequest -Uri "https://github.com/git-for-windows/git/releases/latest/download/MinGit-2.26.2-64-bit.zip" -UseBasicParsing -OutFile "$gitDir\mingit.zip" | |
} | |
Expand-Archive -Path "$gitDir\mingit.zip" -DestinationPath "$gitDir" | |
#Copy-Item -Path "$gitDir\mingit\cmd\git.exe" -Destination "$gitDir\git.exe" -Recurse | |
Remove-Item -Path "$gitDir\mingit.zip" -Recurse -Force | |
if(([Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::User)) -notlike "*$gitDir*") { | |
Write-Host "Updating PATH" | |
[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::User) + ";$gitDir\cmd", [System.EnvironmentVariableTarget]::User) | |
} | |
} | |
RefreshEnv | |
# ---- Git Config ---- # | |
git.exe config --system http.sslcainfo "$gitDir\mingw64\ssl\certs\ca-bundle.crt" | |
# ---- VS Code ---- # | |
# Install VS Code | |
cinst vscode --cacheLocation $ChocoCachePath | |
RefreshEnv | |
# Install VS Code Extensions | |
foreach ($extension in $VSCodeExtensionsList) { | |
code --install-extension "$extension" | |
} | |
# Paste VS Code Configuration | |
$VSCodeConfig | Out-File -Encoding default "$Home\AppData\Roaming\Code\User\settings.json" | |
# Paste Terminal Configuration | |
$MicrosoftTerminalConfig | Out-File -Encoding default "$Home\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json" | |
# ---- Visual Studio 2019 ---- # | |
# Install .NET Framework, as this is required for Visual Studio Installer | |
cinst dotnetfx --cacheLocation $ChocoCachePath | |
cinst netfx-4.8-devpack --cacheLocation $ChocoCachePath | |
if (Test-PendingReboot) { Invoke-Reboot } | |
# Install Visual Studio and Data Workload | |
cinst visualstudio2019community --cacheLocation $ChocoCachePath | |
if (Test-PendingReboot) { Invoke-Reboot } | |
cinst visualstudio2019-workload-data --cacheLocation $ChocoCachePath | |
if (Test-PendingReboot) { Invoke-Reboot } | |
cinst visualstudio2019-workload-manageddesktop --cacheLocation $ChocoCachePath | |
if (Test-PendingReboot) { Invoke-Reboot } | |
cinst visualstudio2019-workload-netcore --cacheLocation $ChocoCachePath | |
if (Test-PendingReboot) { Invoke-Reboot } | |
# ---- Java ---- # | |
cinst ojdkbuild11 --cacheLocation $ChocoCachePath | |
cinst ojdkbuild8 --cacheLocation $ChocoCachePath | |
# ---- JetBrains ---- # | |
cinst datagrip --cacheLocation $ChocoCachePath | |
cinst intellijidea-ultimate --cacheLocation $ChocoCachePath | |
# ---- WSL ---- # | |
# Activate WSL | |
cinst Microsoft-Windows-Subsystem-Linux -source windowsFeatures --cacheLocation $ChocoCachePath | |
# Do not attempt to install ubuntu twice | |
if(!(Get-Command Ubuntu1804 -ErrorAction SilentlyContinue)) { | |
# Install appx for Ubuntu 18.04 | |
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile ~/Ubuntu.appx -UseBasicParsing | |
Add-AppxPackage -Path ~/Ubuntu.appx | |
Invoke-Reboot | |
} | |
if (!(Test-Path "$Home\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs")) { | |
# run the distro once and have it install locally with root user, unset password | |
RefreshEnv | |
Ubuntu1804 install --root | |
} | |
RefreshEnv | |
# do not recreate user if already existing | |
# if user exists a fully installed wsl with nix and rgruber user is expected | |
if ((Ubuntu1804 run getent passwd | Select-String -Pattern '^rgruber' -AllMatches).Matches.Count -ne 1) { | |
Ubuntu1804 run apt update | |
# Create passwordless rgruber | |
Ubuntu1804 run 'useradd -m -s /bin/bash rgruber' | |
Ubuntu1804 run 'usermod -aG sudo rgruber' | |
# supress password prompts from sudo commands | |
Ubuntu1804 run "echo 'rgruber ALL=(ALL) NOPASSWD: ALL' | sudo EDITOR='tee -a' visudo" | |
# Prepare nix install as root | |
Ubuntu1804 run 'rm -rf /etc/nix' | |
Ubuntu1804 run 'mkdir -p /etc/nix' | |
Ubuntu1804 run 'echo "sandbox = false" >> /etc/nix/nix.conf' | |
Ubuntu1804 run 'echo "use-sqlite-wal = false" >> /etc/nix/nix.conf' | |
# Switch default user from root to rgruber | |
Ubuntu1804 config --default-user rgruber | |
# Install Nix | |
Ubuntu1804 run 'curl https://nixos.org/nix/install | sh' | |
} | |
# Copy and run provisioning script as rgruber | |
# sudo is can be used and script MUST be repeatable! | |
$WSLProvision | Ubuntu1804 run 'cat - > /home/rgruber/provision.sh' | |
Ubuntu1804 run 'chmod +x /home/rgruber/provision.sh' | |
Ubuntu1804 run '/home/rgruber/provision.sh' | |
# ---- SSH Config ---- # | |
# Delete .ssh folder and symlink it to OneDrive | |
Remove-Item -Path "$Home\.ssh" -Force -Recurse | |
if (!(Test-Path -Path "$Home\OneDrive\Dokumente\Machine\backup\.ssh")) { New-Item -Path "$Home\OneDrive\Dokumente\Machine\backup\.ssh" -ItemType Directory } | |
New-Item -Path "$Home\.ssh" -ItemType Junction -Value "$Home\OneDrive\Dokumente\Machine\backup\.ssh" | |
# ---- PS Scripts in Start Menu ---- # | |
# Delete scripts folder and create links for all scripts | |
# The first line in a script file must be a comment stating the name of the script after #<space> | |
# The second line in a script file must be a comment stating the mode of the shell after #<space> | |
# shell modes are = hidden | exit | noexit | |
$StartMenuFolder = "$Home\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Scripts" | |
$psScripts = Get-ChildItem "$Home\OneDrive\Dokumente\Machine\scripts" | |
Remove-Item -Path $StartMenuFolder -Force -Recurse | |
New-Item -Path $StartMenuFolder -Type Directory | |
foreach($script in $psScripts) { | |
$scriptPath = $script.FullName | |
$scriptName = (Get-Content $scriptPath -First 1) -replace '^..' | |
$linkName = "${scriptName}.lnk" | |
$linkPath = Join-Path $StartMenuFolder $linkName | |
$scriptMode = (Get-Content $script.FullName -TotalCount 2)[-1] -replace '^..' | |
$scriptParam = "" | |
if($scriptMode -eq "hidden") { | |
$scriptParam = "-windowstyle hidden" | |
} elseif ($scriptMode -eq "noexit") { | |
$scriptParam = "-noexit" | |
} else { | |
$scriptParam = "" | |
} | |
$WScriptShell = New-Object -ComObject WScript.Shell | |
$Shortcut = $WScriptShell.CreateShortcut($linkPath) | |
$Shortcut.TargetPath = "powershell.exe" | |
$Shortcut.Arguments = "$scriptParam -ExecutionPolicy Bypass -File `"$scriptPath`"" | |
$Shortcut.Save() | |
} | |
# ---- Docker ---- # | |
# Install Docker late to avoid error, when Docker Daemon is not started before next reboot | |
cinst docker-desktop --cacheLocation $ChocoCachePath | |
# ---- Declutter Desktop ---- # | |
Get-ChildItem "$Home\OneDrive\Desktop\*.lnk" | Remove-Item | |
Get-ChildItem "C:\Users\Public\Desktop\*.lnk" | Remove-Item | |
# ---- Cleanup & Windows Update ---- # | |
Remove-Item $ChocoCachePath -Recurse | |
choco feature disable -n=allowGlobalConfirmation | |
Enable-MicrosoftUpdate | |
Install-WindowsUpdate -getUpdatesFromMS -acceptEula | |
Enable-UAC | |
# Afterwards | |
# - Change WSL rgruber Password |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment