Skip to content

Instantly share code, notes, and snippets.

@jeebak
Forked from anthonysterling/Vagrantfile
Last active January 23, 2020 22:34
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jeebak/d13cbbb35a199ed4818a to your computer and use it in GitHub Desktop.
Save jeebak/d13cbbb35a199ed4818a to your computer and use it in GitHub Desktop.
A vagrant replacement for ievms (for Linux, and macOS hosts)
# Usage: vagrant up windowsVersion-IEversion
#
# Eg. vagrant up win10-edge
#
# Based off of: # https://gist.github.com/anthonysterling/7cb85670b36821122a4a
boxes = {
# http://www.vagrantbox.es/
"xp-6" => "http://aka.ms/ie6.xp.vagrant",
"xp-8" => "http://aka.ms/ie8.xp.vagrant",
"vista-7" => "http://aka.ms/ie7.vista.vagrant",
"win7-8" => "http://aka.ms/ie8.win7.vagrant",
"win7-9" => "http://aka.ms/ie9.win7.vagrant",
"win7-10" => "http://aka.ms/ie10.win7.vagrant",
"win7-11" => "http://aka.ms/ie11.win7.vagrant",
"win8-10" => "http://aka.ms/ie10.win8.vagrant",
"win8-11" => "http://aka.ms/ie11.win81.vagrant",
# Manually retrieve current from: https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/
"win10-edge" => "https://az792536.vo.msecnd.net/vms/VMBuild_20190311/Vagrant/MSEdge/MSEdge.Win10.Vagrant.zip",
# Since:
# curl -sIL http://aka.ms/msedge.win10.vagrant | grep -o -E 'VMBuild_[0-9]+'
# VMBuild_20150916
# The other old ones are fine
}
tmpdir = "#{ENV['HOME']}/.vagrant.d/tmp"
box_files = {
"xp-6" => "#{tmpdir}/IE6 - WinXP.box",
"xp-8" => "#{tmpdir}/IE8 - WinXP.box",
"vista-7" => "#{tmpdir}/IE7 - Vista.box",
"win7-8" => "#{tmpdir}/IE8 - Win7.box",
"win7-9" => "#{tmpdir}/IE9 - Win7.box",
"win7-10" => "#{tmpdir}/IE10 - Win7.box",
"win7-11" => "#{tmpdir}/IE11 - Win7.box",
"win8-10" => "#{tmpdir}/IE10 - Win8.box",
"win8-11" => "#{tmpdir}/IE11 - Win81.box",
"win10-edge" => "#{tmpdir}/MsEdge - Win10.box",
}
# required_plugins = %w( vagrant-triggers vagrant-vbox-snapshot )
required_plugins = %w( )
vagrant_root = File.dirname(__FILE__)
box_exists = false
if ARGV[0] == "up"
if ARGV.count == 1
puts "Yikes! Please specify one of these boxes:"
boxes.each_key do |name|
puts " vagrant up #{name}"
end
puts "Thanks!\n"
exit
end
if File.exist?("#{vagrant_root}/.vagrant/machines/#{ARGV[1]}/virtualbox/id")
box_exists = true
end
end
if ['halt', 'provision', 'reload', 'ssh', 'ssh-config'].include? ARGV[0]
puts "Sorry! The '#{ARGV[0]}' subcommand's not available for the '#{ARGV[1]}' machine."
exit
end
# The http://aka.ms/ URLs only provides .zip files, and vagrant can't unzip
# them into the .box files, afaict :/.
if File.exist?("#{vagrant_root}/.vagrant/machines/#{ARGV[1]}/virtualbox/id")
# Quick hack to delete .box file, "next" time
box_file = "#{box_files[ARGV[1]]}"
File.delete(box_file) if File.exist?(box_file)
else
boxes.each do |name, url|
if ARGV[1] == name
if ! File.exist?(box_files[name])
tmpfile = "#{tmpdir}/#{name}.zip"
puts "Running: curl -L #{url} > #{tmpfile}"
system( "curl -L #{url} > #{tmpfile}")
puts "Running: unzip -d #{tmpdir} #{tmpfile}"
system( "unzip -d #{tmpdir} #{tmpfile}")
puts "Running: rm #{tmpfile}"
system( "rm #{tmpfile}")
end
end
end
end
required_plugins.each do |plugin|
system "vagrant plugin install #{plugin}" unless Vagrant.has_plugin? plugin
end
Vagrant.configure("2") do |config|
box_files.each do |name, url|
config.vm.define name do |machine|
machine.vm.box = name
machine.vm.box_url = url
end
end
config.vm.guest = :windows
config.vm.boot_timeout = 1
config.vm.communicator = "winrm"
# No ssh on these
config.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", auto_correct: true, disabled: true
config.vm.network :forwarded_port, guest: 3389, host: 33389, id: "rdp", auto_correct: true, disabled: false
#config.vm.post_up_message = <<-EOT
# WIP: Do not be afraid of the red:
# "Timed out while waiting for the machine to boot...." message
#EOT
# "Vagrant exposes a way to call any command against VBoxManage *just prior to booting* the machine:..."
config.vm.provider "virtualbox" do |vm|
if box_exists == false
vm.customize ["snapshot", :id, "take", "Pre-first Boot (to revert to after 30-days)"]
#@machine.ui.info("Took initial Pre-boot snapshot")
end
vm.name = "vagrant - #{ARGV[1]}"
vm.gui = true
# Recently started getting:
# Stderr: VBoxManage: error: Machine '55e6b27a-920a-4705-8e7f-71b125b38d11' is not currently running
# so comemnting out:
# vm.customize ["controlvm", :id, "vrde", "on"]
vm.customize ["guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 10000]
vm.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
vm.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vm.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vm.customize ["modifyvm", :id, "--vram", "64"]
vm.customize ["setextradata", :id, "GUI/SuppressMessages", "all" ]
# https://forums.virtualbox.org/viewtopic.php?f=6&t=53684
# Gracefully shutdown virtuals when host shuts down?
vm.customize ["setextradata", :id, "GUI/DefaultCloseAction", "Shutdown"]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment