Skip to content

Instantly share code, notes, and snippets.

@mefellows
Last active April 6, 2018 01:06
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save mefellows/c892feb4c28442f87a76 to your computer and use it in GitHub Desktop.
Save mefellows/c892feb4c28442f87a76 to your computer and use it in GitHub Desktop.
Bootstrap Vagrant + Packer for Windows Development and Automation
try {
Write-Host -ForegroundColor green "Bootstrapping machine ${remoteHost}"
Write-Host "Setting up package management and installing required packages for Dev."
# Install Choco (if not already installed) + required packages
if ( (Get-Command "choco" -errorAction SilentlyContinue) ) {
Write-Host "Chocolatey already installed. Skipping."
} else {
Write-Host "Installing Chocolatey"
$wc=new-object net.webclient; $wp=[system.net.WebProxy]::GetDefaultProxy(); $wp.UseDefaultCredentials=$true; $wc.Proxy=$wp; iex ($wc.DownloadString('https://chocolatey.org/install.ps1'))
}
Write-Host "Installing required packages."
choco install cyg-get
If ( -not ($env:path | Select-String -SimpleMatch "c:\tools\cygwin\bin") ) {
Write-Host "Adding cygwin to path"
$userPath = [Environment]::GetEnvironmentVariable("PATH","User")
$userPath += ";c:\tools\cygwin\bin"
$env:PATH += ";c:\tools\cygwin\bin" # For this session..
[Environment]::SetEnvironmentVariable("PATH", $userPath, "User") # Permanently
}
Write-Host "Packages installed"
Write-Host "Configuring Cygwin for use with Vagrant"
# Setup SSH / Rsync for use with Vagrant
C:\tools\cygwin\cygwinsetup.exe --site http://mirror.internode.on.net/pub/cygwin/ --quiet-mode --packages rsync,openssh
Write-Host "Cygwin configuration complete."
Write-Host "Installing Vagrant and friends... This will take a little bit of time"
if ( -not (Get-Command 'vagrant' -ErrorAction SilentlyContinue)) {
choco install vagrant
$env:PATH +=";C:\HashiCorp\Vagrant\bin"
} else {
Write-Host "Vagrant already installed"
}
if ( -not (Test-Path 'C:\Program Files\Oracle\VirtualBox\VBoxManage.exe' -ErrorAction SilentlyContinue)) {
choco install virtualbox
choco install virtualbox.extensionpack
} else {
Write-Host "Virtualbox already installed"
}
RefreshEnv
Write-Host "Vagrant and friends installed, Installing required Vagrant plugins..."
vagrant plugin install vagrant-proxyconf vagrant-multi-hostsupdater vagrant-windows-domain vagrant-dsc
# Installing Packer
choco install packer-windows-plugins -Pre
Write-Host "Vagrant plugins installed"
} finally {
}
@jerkovicl
Copy link

@mefellows when i run this i get error :
C:\tools\cygwin\cygwinsetup.exe : The term 'C:\tools\cygwin\cygwinsetup.exe' is not recognized as the name of
a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was include d, verify that the path is correct and try again.
At C:\Users\xx\Documents\GitHub\Vagrant\bootstrap.ps1:28 char:3

  • C:\tools\cygwin\cygwinsetup.exe --site http://mirror.internode.on.net/pub/cygw ...
  • CategoryInfo : ObjectNotFound: (C:\tools\cygwin\cygwinsetup.exe:String) [], CommandNotFoundExc
    eption
  • FullyQualifiedErrorId : CommandNotFoundException

@jpeckham
Copy link

jpeckham commented Apr 6, 2018

hyper v?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment