Skip to content

Instantly share code, notes, and snippets.

@jchadwick
Last active August 29, 2015 14:02
Show Gist options
  • Save jchadwick/bdfd0b4928c3db865a5c to your computer and use it in GitHub Desktop.
Save jchadwick/bdfd0b4928c3db865a5c to your computer and use it in GitHub Desktop.
Dev Environment Bootstrapper
$toolsDir = "C:\Tools"
$files = @(
# Web Essentials 2013
"http://visualstudiogallery.msdn.microsoft.com/56633663-6799-41d7-9df7-0f2a504ca361/file/105627/34/WebEssentials2013.vsix"
)
$packages = @(
"Chutzpah",
"Console2",
"GoogleChrome",
"nodejs.install",
"ReSharper",
"SysInternals",
"tfs2013powertools"
)
# Include utilities
. .\utility.ps1
$origExecutionPolicy = Get-ExecutionPolicy
Set-ExecutionPolicy RemoteSigned
try {
foreach($file in $files) {
try {
Write-Host Installing remote file $file
Install-RemoteFile $file
} catch {
Write-Host Failed to install $file
}
}
# Install Chocolatey (and 7zip)
.\install-chocolatey.ps1
# Install packages
cinst @packages
# Install SublimeText
.\install-sublimetext.ps1 (Join-Path $toolsDir "Sublime Text")
# Pin Console to taskbar
$consoleDir = (Get-Item C:\Chocolatey\Lib\Console*\bin).FullName
Pin-Application $consoleDir "console.exe"
}
finally {
Set-ExecutionPolicy $origExecutionPolicy
}
$url = "http://chocolatey.org/api/v2/package/chocolatey/"
$chocTempDir = Join-Path $env:TEMP "chocolatey"
$tempDir = Join-Path $chocTempDir "chocInstall"
if (![System.IO.Directory]::Exists($tempDir)) {[System.IO.Directory]::CreateDirectory($tempDir)}
$file = Join-Path $tempDir "chocolatey.zip"
function Download-File {
param (
[string]$url,
[string]$file
)
Write-Host "Downloading $url to $file"
$downloader = new-object System.Net.WebClient
$downloader.DownloadFile($url, $file)
}
Download-File $url $file
Write-Host "Download 7Zip commandline tool"
$7zaExe = Join-Path $tempDir '7za.exe'
$currentProtocol = [System.Net.ServicePointManager]::SecurityProtocol
try {
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Ssl3
Download-File 'https://github.com/chocolatey/chocolatey/blob/master/src/tools/7za.exe?raw=true' "$7zaExe"
}
catch {
throw
}
finally {
[System.Net.ServicePointManager]::SecurityProtocol = $currentProtocol
}
# unzip the package
Write-Host "Extracting $file to $tempDir..."
Start-Process "$7zaExe" -ArgumentList "x -o`"$tempDir`" -y `"$file`"" -Wait
Write-Host "Installing chocolatey on this machine"
$toolsFolder = Join-Path $tempDir "tools"
$chocInstallPS1 = Join-Path $toolsFolder "chocolateyInstall.ps1"
& $chocInstallPS1
write-host 'Ensuring chocolatey commands are on the path'
$chocInstallVariableName = "ChocolateyInstall"
$chocoPath = [Environment]::GetEnvironmentVariable($chocInstallVariableName, [System.EnvironmentVariableTarget]::User)
$chocoExePath = 'C:\Chocolatey\bin'
if ($chocoPath -ne $null) {
$chocoExePath = Join-Path $chocoPath 'bin'
}
if ($($env:Path).ToLower().Contains($($chocoExePath).ToLower()) -eq $false) {
$env:Path = [Environment]::GetEnvironmentVariable('Path',[System.EnvironmentVariableTarget]::Machine);
}
cp $7zaExe $chocoExePath
param(
[string]$sublimeDir = "C:\Tools\Sublime Text"
)
$source = "http://c758482.r82.cf2.rackcdn.com/Sublime%20Text%20Build%203059%20x64.zip"
$packageControl = "https://sublime.wbond.net/Package%20Control.sublime-package"
$localFile = Join-Path $sublimeDir "SublimeText.zip"
mkdir -Force $sublimeDir
(new-object System.Net.WebClient).DownloadFile($source, $localFile)
Push-Location -Path $sublimeDir
& 7za.exe x -y $localFile
Pop-Location
# Install Package Control
$packageDirectory = Join-Path $sublimeDir "Data\Installed Packages"
mkdir -Force $packageDirectory
$localFile = Join-Path $packageDirectory "Package Control.sublime-package"
(new-object System.Net.WebClient).DownloadFile($packageControl, $localFile)
# Pin to taskbar
$item = (new-object -c shell.application).namespace($sublimeDir).parseName("Sublime_text.exe")
$pinCmd = ($item.Verbs() | ? {$_.Name -eq 'Pin to Tas&kbar' })
if($pinCmd) {
$pinCmd.DoIt()
}
function Install-RemoteFile {
param(
[string] $url,
[string] $toolsDir = "C:\Tools"
)
if([System.IO.Directory]::Exists($toolsDir) -eq $False) {
mkdir $toolsDir
}
$file = Download-File $url
$name = [System.IO.Path]::GetFileNameWithoutExtension($file).Replace("%20", " ")
$extension = [System.IO.Path]::GetExtension($file).ToLower()
if(@(".exe", ".msi", ".vsix") -contains $extension) {
& $file
}
if(@(".zip", ".rar", ".7z") -contains $extension) {
$extractTo = Join-Path $toolsDir $name
Write-Host Extracting zip file to $extractTo
Extract-File $file $extractTo
return $extractTo
}
}
function Download-File {
param (
[Parameter(Mandatory = $true)][string]$url,
[string]$file = ""
)
if($file -eq "") {
$file = [System.IO.Path]::GetFilename($url).Replace("%20", " ")
}
$dest = Join-Path $env:Temp $file
Write-Host "Downloading $url to $dest"
(new-object System.Net.WebClient).DownloadFile($url, $dest)
return $dest
}
function Extract-File {
param (
[Parameter(Mandatory = $true)][string]$file,
[string]$destination = ""
)
if($destination -ne "") {
if([System.IO.Directory]::Exists($destination) -eq $False) {
Write-Host Creating folder $destination
mkdir $destination
}
Push-Location -Path $destination
}
& 7za.exe x -y $file
Pop-Location
return $destination
}
function Pin-Application {
param (
[Parameter(Mandatory = $true)][string]$folder,
[Parameter(Mandatory = $true)][string]$executable
)
$item = (new-object -c shell.application).namespace($folder).parseName($executable)
$pinCmd = ($item.Verbs() | ? {$_.Name -eq 'Pin to Tas&kbar' })
$pinCmd.DoIt()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment