Skip to content

Instantly share code, notes, and snippets.

@Jawabiscuit
Created January 13, 2021 03:29
Show Gist options
  • Save Jawabiscuit/837c754b96d659aae8ba2390b67a2540 to your computer and use it in GitHub Desktop.
Save Jawabiscuit/837c754b96d659aae8ba2390b67a2540 to your computer and use it in GitHub Desktop.
Tested boxstarter on Win10 Home VM
<#
#OPTIONAL
# Dev Machine
[Environment]::SetEnvironmentVariable("BoxStarter:InstallDev", "1", "Machine") # Variable persists across sessions
[Environment]::SetEnvironmentVariable("BoxStarter:InstallDev", "1", "Process") # Variable used only during this session
[Environment]::SetEnvironmentVariable("BoxStarter:DataDrive", "D", "Machine")
[Environment]::SetEnvironmentVariable("BoxStarter:DataDrive", "D", "Process")
[Environment]::SetEnvironmentVariable("BoxStarter:SourceCodeFolder", "git", "Machine")
[Environment]::SetEnvironmentVariable("BoxStarter:SourceCodeFolder", "git", "Process")
[Environment]::SetEnvironmentVariable("BoxStarter:SkipWindowsUpdate", "1", "Machine")
[Environment]::SetEnvironmentVariable("BoxStarter:SkipWindowsUpdate", "1", "Process")
# If Home Machine
[Environment]::SetEnvironmentVariable("BoxStarter:InstallHome", "1", "Machine") # for reboots
[Environment]::SetEnvironmentVariable("BoxStarter:InstallHome", "1", "Process") # for right now
#START
START http://boxstarter.org/package/nr/url?http://boxstarter.org/package/nr/url?https://raw.githubusercontent.com/Jawabiscuit/dotfiles/master/box.ps1
wget -Uri 'https://raw.githubusercontent.com/Jawabiscuit/dotfiles/master/bootstrap.ps1' -OutFile "$($env:temp)\bootstrap.ps1";&Invoke-Command -ScriptBlock { &"$($env:temp)\bootstrap.ps1" -InstallDev -SkipWindowsUpdate }
#>
# Allow unattended reboots
$Boxstarter.RebootOk = $true
$Boxstarter.NoPassword = $false
$Boxstarter.AutoLogin = $true
$checkpointPrefix = 'BoxStarter:Checkpoint:'
function Enable-ChocolateyFeatures {
choco feature enable --name=allowGlobalConfirmation
}
function Disable-ChocolateyFeatures {
choco feature disable --name=allowGlobalConfirmation
}
function Update-Path {
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
}
function Get-CheckpointName {
param
(
[Parameter(Mandatory = $true)]
[string]
$CheckpointName
)
return "$checkpointPrefix$CheckpointName"
}
function Set-Checkpoint {
param
(
[Parameter(Mandatory = $true)]
[string]
$CheckpointName,
[Parameter(Mandatory = $true)]
[string]
$CheckpointValue
)
$key = Get-CheckpointName $CheckpointName
[Environment]::SetEnvironmentVariable($key, $CheckpointValue, "Machine") # for reboots
[Environment]::SetEnvironmentVariable($key, $CheckpointValue, "Process") # for right now
}
function Get-Checkpoint {
param
(
[Parameter(Mandatory = $true)]
[string]
$CheckpointName
)
$key = Get-CheckpointName $CheckpointName
[Environment]::GetEnvironmentVariable($key, "Process")
}
function Clear-Checkpoints {
$checkpointMarkers = Get-ChildItem Env: | where { $_.name -like "$checkpointPrefix*" } | Select -ExpandProperty name
foreach ($checkpointMarker in $checkpointMarkers) {
[Environment]::SetEnvironmentVariable($checkpointMarker, '', "Machine")
[Environment]::SetEnvironmentVariable($checkpointMarker, '', "Process")
}
}
function Use-Checkpoint {
param(
[string]
$CheckpointName,
[string]
$SkipMessage,
[scriptblock]
$Function
)
$checkpoint = Get-Checkpoint -CheckpointName $CheckpointName
if (-not $checkpoint) {
$Function.Invoke($Args)
Set-Checkpoint -CheckpointName $CheckpointName -CheckpointValue 1
}
else {
Write-BoxstarterMessage $SkipMessage
}
}
function Get-OSInformation {
$osInfo = Get-WmiObject -class Win32_OperatingSystem `
| Select-Object -First 1
return ConvertFrom-String -Delimiter \. -PropertyNames Major, Minor, Build $osInfo.version
}
function Test-IsOSWindows10 {
$osInfo = Get-OSInformation
return $osInfo.Major -eq 10
}
function Get-SystemDrive {
return $env:SystemDrive[0]
}
function Get-DataDrive {
$driveLetter = Get-SystemDrive
if ((Test-Path env:\BoxStarter:DataDrive) -and (Test-Path $env:BoxStarter:DataDrive)) {
$driveLetter = $env:BoxStarter:DataDrive
}
return $driveLetter
}
# Added function
function Get-MediaDrive {
$driveLetter = Get-SystemDrive
if ((Test-Path env:\BoxStarter:MediaDrive) -and (Test-Path $env:BoxStarter:MediaDrive)) {
$driveLetter = $env:BoxStarter:MediaDrive
}
return $driveLetter
}
function Install-WindowsUpdate {
if (Test-Path env:\BoxStarter:SkipWindowsUpdate) {
return
}
Enable-MicrosoftUpdate
Install-WindowsUpdate -acceptEula
#if (Test-PendingReboot) { Invoke-Reboot }
}
<#
.EXAMPLE
$dataDriveLetter = Get-DataDrive
$dataDrive = "$dataDriveLetter`:"
$tempInstallFolder = New-InstallCache -InstallDrive $dataDrive
# Install-WebPackageWithCheckpoint 'My App' 'exe' '/quiet' $DownloadFolder ftp://my.exe
#>
function Install-WebPackage {
param(
$packageName,
[ValidateSet('exe', 'msi')]
$fileType,
$installParameters,
$downloadFolder,
$url,
$filename
)
if ([String]::IsNullOrEmpty($filename)) {
$filename = Split-Path $url -Leaf
}
$fullFilename = Join-Path $downloadFolder $filename
if (test-path $fullFilename) {
Write-BoxstarterMessage "$fullFilename already exists"
return
}
Get-ChocolateyWebFile $packageName $fullFilename $url
Install-ChocolateyInstallPackage $packageName $fileType $installParameters $fullFilename
}
function Install-WebPackageWithCheckpoint {
param(
$packageName,
[ValidateSet('exe', 'msi')]
$fileType,
$installParameters,
$downloadFolder,
$url,
$filename
)
Use-Checkpoint `
-Function ${Function:Install-WebPackage} `
-CheckpointName $packageName `
-SkipMessage "$packageName is already installed" `
$packageName `
$fileType `
$installParameters `
$downloadFolder `
$url `
$filename
}
function Set-RegionalSettings {
# http://stackoverflow.com/questions/4235243/how-to-set-timezone-using-powershell
& "$env:windir\system32\tzutil.exe" /s "Eastern Standard Time"
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sShortDate -Value 'dd MM yy'
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sShortTime -Value 'HH:mm tt'
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sTimeFormat -Value 'HH:mm:ss tt'
}
function Set-DevSettings {
# Enable developer mode on the system
Set-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\AppModelUnlock -Name AllowDevelopmentWithoutDevLicense -Value 1
# Turn off screensaver
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name ScreenSaveActive -Value 0
# Disable UAC popups
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name EnableLUA -Value 0 -Force
}
function Set-BaseSettings {
# TODO: Set computer name
# $computername = "junior"
# if ($env:computername -ne $computername) {
# Rename-Computer -NewName $computername
# }
# Set DNS upstreams
Set-DNSClientServerAddress -InterfaceIndex $(Get-NetAdapter | Where-object {$_.Name -like "*Wi-Fi*" } | Select-Object -ExpandProperty InterfaceIndex) -ServerAddresses "8.8.8.8", "1.1.1.1", "2001:4860:4860::8888", "2001:4860:4860::8844"
Update-ExecutionPolicy -Policy Unrestricted
$sytemDrive = Get-SystemDrive
Set-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives -DisableShowProtectedOSFiles -EnableShowFileExtensions -EnableShowFullPathInTitleBar
Set-TaskbarOptions -Combine Never
# replace command prompt with powershell in start menu and win+x
# Set-CornerNavigationOptions -EnableUsePowerShellOnWinX
}
function Set-UserSettings {
choco install --limitoutput taskbar-never-combine
choco install --limitoutput explorer-show-all-folders
choco install --limitoutput explorer-expand-to-current-folder
}
function Set-BaseDesktopSettings {
if (-not Test-IsOSWindows10) {
return
}
Install-ChocolateyPinnedTaskBarItem "$($Boxstarter.programFiles86)\Google\Chrome\Application\chrome.exe"
}
function Set-DevDesktopSettings {
if (-not Test-IsOSWindows10) {
return
}
Install-ChocolateyPinnedTaskBarItem "$($Boxstarter.programFiles86)\Microsoft Visual Studio\Community\Common7\IDE\devenv.exe"
# Install-ChocolateyFileAssociation ".dll" "$env:LOCALAPPDATA\JetBrains\Installations\dotPeek06\dotPeek64.exe"
}
function Install-HomeApps {
if (-not (Test-Path env:\BoxStarter:InstallHome)) {
return
}
# choco install --limitoutput lastpass
# choco install --limitoutput skype
# choco install --limitoutput teamviewer
# pin apps that update themselves
# choco pin add -n=skype
}
function Install-CoreApps {
choco install --limitoutput firefox
choco install --limitoutput chrome
# Utils
choco install --limitoutput f.lux
choco install --limitoutput 7zip.install
choco install --limitoutput adobereader
choco install --limitoutput etcher
# Game launcher
choco install --limitoutput epicgameslauncher
choco install --limitoutput steam
# Social
choco install --limitoutput itch
choco install --limitoutput slack
choco install --limitoutput zoom
choco install --limitoutput twitch
# Media
choco install --limitoutput spotify
choco install --limitoutput vlc
choco install --limitoutput k-litecodecpack-standard
# VNC
choco install --limitoutput nomachine
choco install --limitoutput realvnc
# Image Editor
choco install --limitoutput inkscape
choco install --limitoutput gimp
# Document Creation
choco install --limitoutput libreoffice-fresh
# Screenshot/Streaming
choco install --limitoutput picpick.portable
choco install --limitoutput sharex
choco install --limitoutput obs-studio
# TODO: Radeon or NVidia graphics? #
choco install --limitoutput evga-precision-xoc
# File Xfer
choco install --limitoutput winscp
choco install --limitoutput putty
choco install --limitoutput filezilla
# System Nfo & Tuner
choco install --limitoutput cue
choco install --limitoutput cpu-z
choco install --limitoutput gpu-z
choco install --limitoutput hwinfo
choco install --limitoutput intel-rst-driver
choco install --limitoutput intel-xtu
choco install --limitoutput gpg4win
choco install --limitoutput treesizefree
# TODO: Spybot S&D and Anti-Beacon
# pin apps that update themselves
choco pin add -n=firefox
choco pin add -n=chrome
}
function Install-CoreDevApps {
# WSL
choco install -y Microsoft-Hyper-V-All -source windowsFeatures
choco install -y Microsoft-Windows-Subsystem-Linux -source windowsfeatures
Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile ~/Ubuntu.appx -UseBasicParsing
Add-AppxPackage -Path ~/Ubuntu.appx
RefreshEnv
Ubuntu1804 install --root
Ubuntu1804 run apt update
Ubuntu1804 run apt upgrade
choco install --limitoutput sysinternals
choco install --limitoutput dotnetcore-sdk
choco install --limitoutput javaruntime
choco install --limitoutput jdk8
choco install --limitoutput git.install -params "'/GitAndUnixToolsOnPath' '/NoAutoCrlf'"
choco install --limitoutput docker-for-windows
choco install --limitoutput anaconda2
choco install --limitoutput cygwin
# choco install --limitoutput nodejs
# choco install --limitoutput gitkraken
# choco install --limitoutput resharper-platform
# choco install --limitoutput prefix
# pin apps that update themselves
choco pin add -n=docker-for-windows
# choco pin add -n=gitkraken
# choco pin add -n=resharper-platform
}
function Install-DevOpsTools {
# choco install --limitoutput terraform
# choco install --limitoutput packer
}
function Install-DevTools {
# Editor
choco install --limitoutput emacs --version 24.5.0.20191123
choco install --limitoutput pandoc
choco install --limitoutput miktex
choco install --limitoutput vcxsrv
# Database
choco install --limitoutput pgadmin4
choco install --limitoutput postgresql10
# Terminal
choco install --limitoutput microsoft-windows-terminal
choco install --limitoutput poshgit
# Package Mgmt
choco install --limitoutput nugetpackageexplorer
# choco install --limitoutput redis-desktop-manager
# choco install --limitoutput fiddler4
Update-Path
}
function Install-VisualStudio2017Enterprise {
if (-not (Test-Path env:\BoxStarter:InstallVS2017Enterprise)) {
return
}
choco install --limitoutput visualstudio2017enterprise
choco pin add -n=visualstudio2017enterprise
}
function Install-VisualStudio2017Workloads {
if (-not (Test-Path env:\BoxStarter:InstallVS2017Community) -and -not (Test-Path env:\BoxStarter:InstallVS2017Enterprise)) {
return
}
# Gamedev
choco install --limitoutput visualstudio2017-workload-manageddesktop
choco install --limitoutput visualstudio2017-workload-nativedesktop
choco install --limitoutput visualstudio2017-workload-universal
choco install --limitoutput visualstudio2017-workload-universalbuildtools
choco install --limitoutput visualstudio2017-workload-datascience
choco install --limitoutput visualstudio2017-workload-nativegame
choco install --limitoutput visualstudio2017-workload-managedgame
choco install --limitoutput visualstudio2017-workload-nativecrossplat
# choco install --limitoutput --includeOptional visualstudio2017-workload-netcoretools
# choco install --limitoutput visualstudio2017-workload-netweb
# choco install --limitoutput visualstudio2017-workload-node
# choco install --limitoutput --includeOptional visualstudio2017-workload-data
}
function Install-VisualStudioCode {
# install visual studio code and extensions
choco install --limitoutput visualstudiocode
choco pin add -n=visualstudiocode
Update-Path
}
function Install-VSCodeExtensions {
# need to launch vscode so user folders are created as we can install extensions
$process = Start-Process code -PassThru
Start-Sleep -s 10
$process.Close()
code --install-extension ms-vscode.csharp
code --install-extension ms-vscode.PowerShell
code --install-extension DavidAnson.vscode-markdownlint
code --install-extension johnpapa.Angular2
code --install-extension donjayamanne.githistory
code --install-extension hnw.vscode-auto-open-markdown-preview
code --install-extension EditorConfig.editorconfig
code --install-extension djabraham.vscode-yaml-validation
code --install-extension robertohuertasm.vscode-icons
code --install-extension PeterJausovec.vscode-docker
code --install-extension ms-vscode-remote.remote-extensionpack
# code --install-extension eg2.tslint
# code --install-extension lukehoban.Go
# code --install-extension msjsdiag.debugger-for-chrome
# code --install-extension cake-build.cake-vscode
# code --install-extension mauve.terraform
# code --install-extension Arjun.swagger-viewer
# code --install-extension joelday.docthis
# code --install-extension wk-j.cake-runner
}
function Install-DevFeatures {
# Bash for windows
$features = choco list --source windowsfeatures
if ($features | Where-Object {$_ -like "*Linux*"}) {
choco install Microsoft-Windows-Subsystem-Linux --source windowsfeatures --limitoutput
}
# Windows containers
Enable-WindowsOptionalFeature -Online -FeatureName containers -All
# Hyper-V (required for windows containers)
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
# WSL2
# Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
wsl --set-version 2
}
function Install-PowerShellModules {
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
# Install without prompt
Set-PSRepository -Name 'PSGallery' -InstallationPolicy 'Trusted'
# Deps
Install-Module -Name PendingReboot
# Tools
Install-Module -Name -AllowClobber -Force Carbon
Install-Module -Name -Force PowerShellHumanizer
Set-PSRepository -Name 'PSGallery' -InstallationPolicy 'Untrusted'
}
# TODO: Make VM drives? Do this when not creating VM? Multiple media/data drives?
function Update-WindowsLibraries {
if(-not (Test-Path Env:\BoxStarter:CustomiseFolders)) {
return
}
# Set-Volume -DriveLetter $sytemDrive -NewFileSystemLabel "OS"
$dataDriveLetter = Get-DataDrive
$dataDrive = "$dataDriveLetter`:"
$mediaDriveLetter = Get-MediaDrive
$mediaDrive = "$mediaDriveLetter`:"
# if (Get-SystemDrive -eq $dataDriveLetter) {
# return
# }
Write-BoxstarterMessage "Configuring Data and Media drives"
Set-Volume -DriveLetter $dataDriveLetter -NewFileSystemLabel "Data"
Set-Volume -DriveLetter $mediaDriveLetter -NewFileSystemLabel "Media"
Move-WindowsLibrary -libraryName "Personal" -newPath (Join-Path $dataDrive "Documents")
Move-WindowsLibrary -libraryName "Desktop" -newPath (Join-Path $dataDrive "Desktop")
Move-WindowsLibrary -libraryName "Downloads" -newPath (Join-Path $dataDrive "Downloads")
Move-WindowsLibrary -libraryName "Pictures" -newPath (Join-Path $mediaDrive "Pictures")
Move-WindowsLibrary -libraryName "Video" -newPath (Join-Path $mediaDrive "Videos")
Move-WindowsLibrary -libraryName "Music" -newPath (Join-Path $mediaDrive "Music")
}
function Move-WindowsLibrary {
param(
$libraryName,
$newPath
)
if (-not (Test-Path $newPath)) {
Move-LibraryDirectory -libraryName $libraryName -newPath $newPath
}
}
# TODO: New drive dedicated to just source code?
function New-SourceCodeFolder {
$sourceCodeFolder = 'GitHub'
if (Test-Path env:\BoxStarter:SourceCodeFolder) {
$sourceCodeFolder = $env:BoxStarter:SourceCodeFolder
}
if ([System.IO.Path]::IsPathRooted($sourceCodeFolder)) {
$sourceCodePath = $sourceCodeFolder
}
else {
$drivePath = Get-DataDrive
$sourceCodePath = Join-Path "$drivePath`:" $sourceCodeFolder
}
if (-not (Test-Path $sourceCodePath)) {
New-Item $sourceCodePath -ItemType Directory
}
return $sourceCodePath
}
function New-InstallCache {
param
(
[String]
$InstallDrive
)
$tempInstallFolder = Join-Path $InstallDrive "temp\install-cache"
if (-not (Test-Path $tempInstallFolder)) {
New-Item $tempInstallFolder -ItemType Directory
}
return $tempInstallFolder
}
# Temporary
Disable-UAC
# Install PS modules
Use-Checkpoint -Function ${Function:Install-PowerShellModules} -CheckpointName 'PowerShellModules' -SkipMessage 'PowerShell modules are already installed'
# Disable chocolatey default confirmation behaviour (no need for --yes)
Use-Checkpoint -Function ${Function:Enable-ChocolateyFeatures} -CheckpointName 'IntialiseChocolatey' -SkipMessage 'Chocolatey features already configured'
# Update Windows
Write-BoxstarterMessage "Windows update..."
Install-WindowsUpdate
# Basic windows settings
Use-Checkpoint -Function ${Function:Set-RegionalSettings} -CheckpointName 'RegionalSettings' -SkipMessage 'Regional settings are already configured'
Use-Checkpoint -Function ${Function:Set-DevSettings} -CheckpointName 'DevSettings' -SkipMessage 'Dev settings are already configured'
Use-Checkpoint -Function ${Function:Set-BaseSettings} -CheckpointName 'BaseSettings' -SkipMessage 'Base settings are already configured'
Use-Checkpoint -Function ${Function:Set-UserSettings} -CheckpointName 'UserSettings' -SkipMessage 'User settings are already configured'
# Begin installing apps
Write-BoxstarterMessage "Starting installs"
# Install some apps and pin some to the taskbar
Use-Checkpoint -Function ${Function:Install-CoreApps} -CheckpointName 'InstallCoreApps' -SkipMessage 'Core apps are already installed'
Use-Checkpoint -Function ${Function:Set-BaseDesktopSettings} -CheckpointName 'BaseDesktopSettings' -SkipMessage 'Base desktop settings are already configured'
if (Test-Path env:\BoxStarter:InstallDev) {
Write-BoxstarterMessage "Installing dev apps"
# Enable dev related windows features
Use-Checkpoint -Function ${Function:Install-DevFeatures} -CheckpointName 'DevFeatures' -SkipMessage 'Windows dev features are already configured'
# if (Test-PendingReboot) { Invoke-Reboot }
# Install vs2017 community
Use-Checkpoint -Function ${Function:Install-VisualStudio2017} -CheckpointName 'VisualStudio2017Community' -SkipMessage 'Visual Studio 2017 Community is already installed'
# Install vs2017 workloads
Use-Checkpoint -Function ${Function:Install-VisualStudio2017Workloads} -CheckpointName 'VisualStudio2017Workloads' -SkipMessage 'Visual Studio 2017 Workloads are already installed'
# Install vscode and extensions
Use-Checkpoint -Function ${Function:Install-VisualStudioCode} -CheckpointName 'VisualStudioCode' -SkipMessage 'VSCode is already installed'
Use-Checkpoint -Function ${Function:Install-VSCodeExtensions} -CheckpointName 'VSCodeExtensions' -SkipMessage 'VSCode extensions are already installed'
# Install core apps needed for dev
Use-Checkpoint -Function ${Function:Install-CoreDevApps} -CheckpointName 'CoreDevApps' -SkipMessage 'Core dev apps are already installed'
# Find or create new folder for source code
# New-SourceCodeFolder
Use-Checkpoint -Function ${Function:Set-DevDesktopSettings} -CheckpointName 'DevDesktopSettings' -SkipMessage 'Dev desktop settings are already configured'
}
# Install apps for home use
Use-Checkpoint -Function ${Function:Install-HomeApps} -CheckpointName 'HomeApps' -SkipMessage 'Home apps are already installed'
#move windows libraries to data drive
Use-Checkpoint -Function ${Function:Update-WindowsLibraries} -CheckpointName 'WindowsLibraries' -SkipMessage 'Libraries are already configured'
# Install chocolatey as last choco package
choco install chocolatey --limitoutput
# Re-enable chocolatey default confirmation behaviour
Use-Checkpoint -Function ${Function:Disable-ChocolateyFeatures} -CheckpointName 'DisableChocolatey' -SkipMessage 'Chocolatey features already configured'
# if (Test-PendingReboot) { Invoke-Reboot }
# Reload path environment variable
Update-Path
# Set HOME to user profile for git
[Environment]::SetEnvironmentVariable("HOME", $env:UserProfile, "User")
# Re-run windows update after we have installed everything
Write-BoxstarterMessage "Windows update..."
Install-WindowsUpdate
Clear-Checkpoints
Enable-UAC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment