Skip to content

Instantly share code, notes, and snippets.

@jburwell
Last active February 25, 2023 11:03
Show Gist options
  • Save jburwell/dd670de4d70bf8711835d621cdab799e to your computer and use it in GitHub Desktop.
Save jburwell/dd670de4d70bf8711835d621cdab799e to your computer and use it in GitHub Desktop.
Windows 10 Configuration
[CmdLetBinding()]
Param([switch] $FullInstall)
Set-StrictMode -Version "2.0"
$logFile = "provision." + (Get-Date -Format FileDateTime) + ".log"
# TODO Add output timestamps
function Log-Message {
[CmdLetBinding()]
Param([Parameter(ValueFromPipeline)] $message)
$message | Out-File -LiteralPath $logFile -Append
}
function Execute-Command([String] $command, [String] $description = "")
{
if (-Not ([String]::IsNullOrEmpty($description))) {
"-> [" + $description + "]"
}
iex $command | Log-Message
}
function Check-Package-Installed()
{
[OutputType([Boolean])]
Param (
[parameter(Mandatory=$true)]
[String] $package
)
$searchCommand = "choco list --local-only | sls " + $package
$searchOutput = iex -Command $searchCommand -OutVariable searchOutput
if ([String]::IsNullOrEmpty($searchOutput))
{
return $false
}
return $true
}
function Install-Choco-Package([String] $package)
{
if (-Not (Check-Package-Installed($package)))
{
Execute-Command -Command ("choco install " + $package) -Description "Installing $package"
Execute-Command -Command refreshenv
}
}
function Install-Vagrant-Plugin([String] $plugin)
{
if (-Not (Check-Package-Installed("vagrant")))
{
return
}
$searchCommand = "vagrant plugin list | sls " + $plugin
$searchOutput = iex -Command $searchCommand -OutVariable searchOutput
if ([String]::IsNullOrEmpty($searchOutput))
{
Execute-Command -Command ("vagrant plugin install " + $plugin) -Description "Installing Vagrant plugin $plugin"
}
}
function Enable-Windows-Optional-Feature([String] $featureName)
{
"Checking Windows Optional Feature " + $featureName
$feature = Get-WindowsOptionalFeature -Online -FeatureName $featureName
if ($feature -And $feature.State -eq "Disabled")
{
Enable-WindowsOptionalFeature -Online -FeatureName $feature.FeatureName
}
}
function Set-User-Environment-Variable([String] $name, [String] $value)
{
if (-Not ([Environment]::GetEnvironmentVariable($name)))
{
"Setting environment variable $name to $value"
[Environment]::SetEnvironmentVariable($name, $value, [EnvironmentVariableTarget]::User)
refreshenv
}
}
function Copy-File()
{
Param (
[parameter(Mandatory=$true)]
[String] $source,
[parameter(Mandatory=$true)]
[String] $destination
)
if (-Not (Test-Path -Path $source))
{
Copy-Item $source -Destination $destination
}
}
$base_packages = "chromelpass-chrome",
"ConEmu",
"curl",
"docker",
"eclipse",
"Emacs64",
"Everything",
"git",
"gitflow-avh",
"GraphViz",
"hunspell.portable",
"Inconsolata",
"intellijidea-community",
"jdk8",
"kdiff3",
"keepass",
"keepass-plugin-keeagent",
"keepass-keepasshttp",
"kubernetes-cli",
"kubernetes-helm",
"Less",
"maven",
"nmap",
"postman",
"openssh",
"plantuml",
"poshgit",
"pt",
"putty",
"python2",
"SourceCodePro",
"unzip",
"velocity",
"vim",
"wox",
"zip"
$full_packages = "awscli",
"docker-machine",
"Firefox",
"gradle",
"GoogleChrome",
"minikube",
"spotify",
"vagrant",
"virtualbox"
# Install chocolately if it is not installed
if ((Get-Command "choco.exe" -ErrorAction SilentlyContinue) -eq $null)
{
Set-ExecutionPolicy Bypass -Scope Process -Force
Execute-Command -Command ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) -Description "Installing Chocolately"
Execute-Command -Command "choco feature enable -n allowGlobalConfirmation"
}
$packages = if ($FullInstall) { $base_packages + $full_packages } else { $base_packages }
foreach ($package in $packages)
{
Install-Choco-Package $package
}
$vagrant_plugin = "vagrant-proxyconf"
Install-Vagrant-Plugin $vagrant_plugin
"Installing Powershell Help"
Update-Help
if ($FullInstall) {
Enable-Windows-Optional-Feature "Microsoft-Windows-Subsystem-Linux"
}
$dotfiles_home="$env:HOMEPATH\Documents\dotfiles"
if (-Not (Test-Path -Path $dotfiles_home))
{
Execute-Command -Command "git clone https://github.com/jburwell/windows-dotfiles.git $dotfiles_home" -Description "Checking out dotfiles"
}
Set-User-Environment-Variable -Name "HOME" -Value "c:$env:HOMEPATH"
Set-User-Environment-Variable -Name "ALTERNATIVE_EDITOR" -Value (Get-Command "emacs.exe").Source
$spacemacs_home="$env:HOMEPATH\.emacs.d"
if (-Not (Test-Path -Path $spacemacs_home))
{
Execute-Command -Command "git clone -b develop https://github.com/syl20bnr/spacemacs.git $spacemacs_home" -Description "Installing spacemacs into $spacemacs_home"
}
$velocity_home="$env:HOMEPATH\AppData\Local\Silverlake Software LLC\Velocity"
if (-Not (Test-Path -Path $velocity_home))
{
New-Item -ItemType Directory -Path $velocity_home
Copy-Item "$dotfiles_home\velocity\*" -Destination $velocity_home
}
$vimrc_path="$env:HOMEPATH\_vimrc"
if (-Not (Test-Path -Path $vimrc_path))
{
Copy-Item "$dotfiles_home\vim\_vimrc" -Destination $vimrc_path
}
Copy-File -Source "$dotfiles_home\vim\_vimrc" -Destination "$env:HOMEPATH\_vimrc"
Copy-File -Source "$dotfiles_home\conemu\conemu.xml" -Destination "$env:HOMEPATH\AppData\Roaming"
Copy-File -Source "$dotfiles_home\git\gitignore" -Destination "$env:HOMEPATH\.gitignore"
$searcher = [adsisearcher]"(samaccountname=$env:USERNAME)"
$email_address = $searcher.FindOne().Properties.mail
$template = Get-Content "$dotfiles_home\git\gitconfig.tmpl"
iex "`"$template`"" | Out-File -FilePath "$env:HOMEPATH\.gitconfig" -NoClobber
# TODO Configure Wox
# TODO Pull spacemacs configuration
# TODO Set background color and remove background picture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment