Skip to content

Instantly share code, notes, and snippets.

@TonyApuzzo
Created November 7, 2018 21:06
Show Gist options
  • Save TonyApuzzo/a56763310821fc2a9826664400ded9cb to your computer and use it in GitHub Desktop.
Save TonyApuzzo/a56763310821fc2a9826664400ded9cb to your computer and use it in GitHub Desktop.
Vagrantfile that fails with w10e 1809
# -*- mode: ruby; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*-
# vim: set ft=ruby sw=2 ts=2 smartindent expandtab :
# Flatirons Digital Innovations Windows 10 Enterprise - Baseline
VMNAME = 'w10e'
require 'fileutils'
require 'yaml'
# Verify pre-requisites
abort " ERROR Must run from the directory containing 'Vagrantfile'" unless File.exist?('./Vagrantfile')
#
# Get the Default and User Settings
#
dir = File.dirname(File.expand_path(__FILE__))
settings = YAML.load_file("#{dir}/SETTINGS.yml") if File.exist?("#{dir}/SETTINGS.yml")
settings = {} unless settings
# Override
settings_local = YAML.load_file("#{dir}/SETTINGS_LOCAL.yml") if File.exist?("#{dir}/SETTINGS_LOCAL.yml")
settings_local = {} unless settings_local
settings.merge!(settings_local)
# Override anything set in config files with Environment
settings.merge!(ENV)
Vagrant.configure("2") do |config|
config.vm.box = "gusztavvargadr/w10e"
#config.vm.box_version = "1808.0.0"
config.vm.boot_timeout = 200
if settings['VAGRANT_NETWORK_BRIDGE']
config.vm.network "public_network", bridge: settings['VAGRANT_NETWORK_BRIDGE']
end
config.vm.provider "virtualbox" do |vb|
vb.name = VMNAME
# Display the VirtualBox GUI when booting the machine
vb.gui = true
# Customize the amount of memory and CPUs on the VM:
vb.memory = 4096
vb.cpus = 2
vb.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
vb.customize ["modifyvm", :id, "--draganddrop", "bidirectional"]
vb.customize ["modifyvm", :id, "--vram", "32"]
end
config.vm.provider "hyperv" do |h|
h.vmname = VMNAME
h.cpus = 2
h.memory = 4096
h.ip_address_timeout = 200
h.enable_virtualization_extensions = false
h.auto_start_action = 'Nothing'
h.auto_stop_action = 'ShutDown'
h.vm_integration_services = {
guest_service_interface: true,
heartbeat: true,
key_value_pair_exchange: true,
shutdown: true,
time_synchronization: true,
vss: true
}
# Hacky way of avoiding a bunch of deprecation warnings
begin
Vagrant.require_version "> 2.1.1"
h.linked_clone = true
rescue
h.differencing_disk = true
end
end
# Shell provision
# This Vagrant Box has Chocolatey preinstalled
# Note: use of interpolation #{...} below instead of using arguments.
# use of double-backslashes since we're in a Ruby heredoc
config.vm.provision "shell", inline: <<~INSTALL
echo "Basic Configuration..."
Set-Timezone -Name "Mountain Standard Time"
echo "Installing Tools..."
# Install Google Chrome
cinst -y --no-progress --ignore-checksums GoogleChrome
# Install git for Windows
cinst -y --no-progress git --params="'/GitAndUnixToolsOnPath /NoAutoCrlf'"
# Get git in the PATH
refreshenv
# Chocolatey Install with generic settings
cinst -y --no-progress\
7zip\
Firefox\
adobereader adobereader-update\
cmder\
curl\
cyberduck\
fzf\
git-credential-manager-for-windows\
git-flow-hooks\
git-lfs\
gitflow-avh\
grepwin\
hackfont\
hxd\
irfanview irfanviewplugins\
jdk8\
jq\
kdiff3\
meld\
notepadplusplus\
putty\
ripgrep\
shadowspawn\
sysinternals\
vim\
vlc\
vscode\
winscp
INSTALL
# Use the installed stuff to configure things
config.vm.provision "shell", inline: <<~PROVISION
echo "Configuring git..."
git config --global user.name '#{settings['VAGRANT_GIT_USER_NAME']}'
git config --global user.email '#{settings['VAGRANT_GIT_USER_EMAIL']}'
# Set up default Windows PowerShell environment
$windowsPowerShellDir = $PROFILE.CurrentUserCurrentHost -replace '\\\\[^\\\\]+$', ''
if( -Not (Test-Path -Path "$windowsPowerShellDir" ) ) {
echo "Configuring Windows PowerShell Profile at $windowsPowerShellDir"
New-Item -ItemType directory -Path "$windowsPowerShellDir"
pushd "$windowsPowerShellDir"
git clone "https://github.com/TonyApuzzo/WindowsPowerShell.git" .
git pull
popd
} else {
echo "Existing Profile at $windowsPowerShellDir left unchanged."
}
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Repository PSGallery -Name posh-git
function ConfigureDeveloperSettings()
{
# Enable Windows Developer Mode
# Create AppModelUnlock if it doesn't exist, required for enabling Developer Mode
$RegistryKeyPath = "HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppModelUnlock"
if (-not(Test-Path -Path $RegistryKeyPath)) {
New-Item -Path $RegistryKeyPath -ItemType Directory -Force
}
# Add registry value to enable Developer Mode
New-ItemProperty -Path $RegistryKeyPath -Name AllowDevelopmentWithoutDevLicense -PropertyType DWORD -Value 1 -Force
# Set developer-friendly settings
Push-Location
Set-Location 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced'
Set-ItemProperty . HideFileExt -Value 0 -Type DWord
Set-ItemProperty . HideDrivesWithNoMedia -Value 1 -Type DWord
Set-ItemProperty . NavPaneExpandToCurrentFolder -Value 1 -Type DWord
Set-ItemProperty . NavPaneShowAllFolders -Value 1 -Type DWord
Set-ItemProperty . ShowSuperHidden -Value 1 -Type DWord
Set-Location 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced'
Set-ItemProperty . ShowRunAsDifferentUserInStart -Value 1 -Type DWord
Pop-Location
}
echo "Configuring Developer Settings..."
&ConfigureDeveloperSettings
echo "Configuring VS Code"
code --install-extension 'shinnn.stylelint' --force
code --install-extension 'eg2.tslint' --force
code --install-extension 'eamodio.gitlens' --force
code --install-extension 'christian-kohler.path-intellisense' --force
code --install-extension 'pranaygp.vscode-css-peek' --force
code --install-extension 'dbankier.vscode-instant-markdown' --force
echo "Reducing Annoyances..."
# Turn on font smoothing, etc
Set-ItemProperty -Path 'HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\VisualEffects' -Name 'VisualFXSetting' -Value 1
# Don't require CTRL + ALT + DEL to logon
Set-ItemProperty -Path 'HKLM:\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System' -Name 'DisableCAD' -Value 1
# Set Local Policy overrides
Install-Module -Name PolicyFileEditor
Import-Module -name "PolicyFileEditor"
$MachineDir = "${env:windir}\\system32\\GroupPolicy\\Machine\\registry.pol"
$MachinePols = Import-Clixml -Path 'C:\\vagrant\\MachinePol.xml'
foreach ($MachinePol in $MachinePols)
{
$MachinePol | Set-PolicyFileEntry -Path $MachineDir
}
echo "Enabling BGInfo"
#Set-ItemProperty -Path 'HKU\.DEFAULT\Software\Sysinternals\BGInfo' -Name 'EulaAccepted' -Value 1
$cmd = Get-Command bginfo.exe | Select-Object -ExpandProperty Source
$taskName = "RunBGInfo"
$description = "Run BG Info"
$action = New-ScheduledTaskAction -Execute "$cmd" -Argument "c:\\vagrant\\bginfo.bgi /timer:00 /silent /nolicprompt"
$runLevel = "Highest"
$trigger = New-ScheduledTaskTrigger -AtLogOn -User "$env:USERNAME" -RandomDelay $(New-TimeSpan -Seconds 10)
Register-ScheduledTask -Action $action -RunLevel $runLevel -TaskName $taskName -Description $description -Trigger $trigger -Force
PROVISION
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment