Skip to content

Commit 2e8892b

Browse files
committed
Add Vagrant environment.
1 parent aa7c472 commit 2e8892b

File tree

4 files changed

+239
-1
lines changed

4 files changed

+239
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ out/
22
vendor/*
33
*.exe
44
*.jar
5-
*.dll
5+
*.dll
6+
.vagrant/
7+
.vscode/

Vagrantfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Vagrant.configure(2) do |config|
2+
# you first need to build the base image with:
3+
# git clone https://github.com/joefitzgerald/packer-windows
4+
# cd packer-windows
5+
# # this will take ages so leave it running over night...
6+
# packer build windows_2012_r2.json
7+
# vagrant box add windows_2012_r2 windows_2012_r2_virtualbox.box
8+
# cd ..
9+
# then finally you vagrant up this vagrant environment.
10+
config.vm.box = "windows_2012_r2"
11+
config.vm.provider "virtualbox" do |vb|
12+
vb.linked_clone = true
13+
vb.memory = 4096
14+
vb.customize ["modifyvm", :id, "--vram", 64]
15+
vb.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
16+
vb.customize ["modifyvm", :id, "--draganddrop", "bidirectional"]
17+
end
18+
config.vm.provision "shell", inline: "$env:chocolateyVersion='0.10.0'; iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex", name: "Install Chocolatey"
19+
config.vm.provision "shell", path: "Vagrantfile-locale.ps1"
20+
config.vm.provision "shell", path: "Vagrantfile-provision.ps1"
21+
end

Vagrantfile-locale.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
$ErrorActionPreference = 'Stop'
2+
3+
# set keyboard layout.
4+
# NB you can get the name from the list:
5+
# [Globalization.CultureInfo]::GetCultures('InstalledWin32Cultures') | Out-GridView
6+
Set-WinUserLanguageList pt-PT -Force
7+
8+
# set the date format, number format, etc.
9+
Set-Culture pt-PT
10+
11+
# set the timezone.
12+
# tzutil /l lists all available timezone ids
13+
& $env:windir\system32\tzutil /s "GMT Standard Time"

Vagrantfile-provision.ps1

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
$ErrorActionPreference = 'Stop'
2+
3+
# install useful applications and dependencies.
4+
choco install -y googlechrome
5+
choco install -y notepad2
6+
choco install -y baretail
7+
choco install -y --allow-empty-checksums dependencywalker
8+
choco install -y procexp
9+
choco install -y phantomjs
10+
choco install -y --allow-empty-checksums innosetup
11+
# for building the setup-helper.dll we need the 32-bit version
12+
# of the win32 libraries, for having them we have to force the
13+
# installation of the 32-bit mingw package.
14+
$env:chocolateyForceX86 = 'true'
15+
choco install -y mingw -params '/threads:win32'
16+
del env:chocolateyForceX86
17+
choco install -y git --params '/GitOnlyOnPath /NoAutoCrlf'
18+
choco install -y gitextensions
19+
choco install -y meld
20+
21+
# update $env:PATH with the recently installed Chocolatey packages.
22+
Import-Module C:\ProgramData\chocolatey\helpers\chocolateyInstaller.psm1
23+
Update-SessionEnvironment
24+
25+
# configure git.
26+
# see http://stackoverflow.com/a/12492094/477532
27+
git config --global user.name 'Rui Lopes'
28+
git config --global user.email '[email protected]'
29+
git config --global push.default simple
30+
git config --global diff.guitool meld
31+
git config --global difftool.meld.path 'C:/Program Files (x86)/Meld/Meld.exe'
32+
git config --global difftool.meld.cmd '\"C:/Program Files (x86)/Meld/Meld.exe\" \"$LOCAL\" \"$REMOTE\"'
33+
git config --global merge.tool meld
34+
git config --global mergetool.meld.path 'C:/Program Files (x86)/Meld/Meld.exe'
35+
git config --global mergetool.meld.cmd '\"C:/Program Files (x86)/Meld/Meld.exe\" --diff \"$LOCAL\" \"$BASE\" \"$REMOTE\" --output \"$MERGED\"'
36+
#git config --list --show-origin
37+
38+
# we have to manually build another version of the msys2 package
39+
# because the current one is broken.
40+
Push-Location $env:TEMP
41+
$p = Start-Process git 'clone','-b','update_to_20160719','https://github.com/petemounce/choco-packages' -PassThru -Wait
42+
if ($p.ExitCode) {
43+
throw "git failed with exit code $($p.ExitCode)"
44+
}
45+
cd choco-packages/msys2
46+
choco pack
47+
choco install -y msys2 -Source $PWD
48+
Pop-Location
49+
50+
# configure the msys2 launcher to let the shell inherith the PATH.
51+
$msys2BasePath = 'C:\tools\msys64'
52+
$msys2ConfigPath = "$msys2BasePath\msys2.ini"
53+
[IO.File]::WriteAllText(
54+
$msys2ConfigPath,
55+
([IO.File]::ReadAllText($msys2ConfigPath) `
56+
-replace '#?(MSYS2_PATH_TYPE=).+','$1inherit')
57+
)
58+
59+
# define a function for easying the execution of bash scripts.
60+
$bashPath = "$msys2BasePath\usr\bin\bash.exe"
61+
function Bash($script) {
62+
$eap = $ErrorActionPreference
63+
$ErrorActionPreference = 'Continue'
64+
try {
65+
# we also redirect the stderr to stdout because PowerShell
66+
# oddly interleaves them.
67+
# see https://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
68+
echo 'exec 2>&1;set -eu;export PATH="/usr/bin:$PATH"' $script | &$bashPath
69+
if ($LASTEXITCODE) {
70+
throw "bash execution failed with exit code $LASTEXITCODE"
71+
}
72+
} finally {
73+
$ErrorActionPreference = $eap
74+
}
75+
}
76+
77+
# install the remaining dependencies.
78+
Bash 'pacman --noconfirm -Sy make unzip tar'
79+
80+
# configure the shell.
81+
Bash @'
82+
pacman --noconfirm -Sy vim
83+
84+
cat>~/.bash_history<<"EOF"
85+
cd /c/vagrant
86+
cd /c/vagrant && make clean all
87+
make clean all
88+
tail -f /c/Program\ Files/Elasticsearch/logs/elasticsearch.log
89+
net start elasticsearch
90+
curl localhost:9200/_cluster/state?pretty
91+
curl localhost:9200/_cluster/health?pretty
92+
curl localhost:9200/_cluster/pending_tasks?pretty
93+
curl localhost:9200/_cat/indices?v
94+
net stop elasticsearch
95+
EOF
96+
97+
cat>~/.bashrc<<"EOF"
98+
# If not running interactively, don't do anything
99+
[[ "$-" != *i* ]] && return
100+
101+
export EDITOR=vim
102+
export PAGER=less
103+
104+
alias l='ls -lF --color'
105+
alias ll='l -a'
106+
alias h='history 25'
107+
alias j='jobs -l'
108+
EOF
109+
110+
cat>~/.inputrc<<"EOF"
111+
"\e[A": history-search-backward
112+
"\e[B": history-search-forward
113+
"\eOD": backward-word
114+
"\eOC": forward-word
115+
set show-all-if-ambiguous on
116+
set completion-ignore-case on
117+
EOF
118+
119+
cat>~/.vimrc<<"EOF"
120+
syntax on
121+
set background=dark
122+
set esckeys
123+
set ruler
124+
set laststatus=2
125+
set nobackup
126+
127+
autocmd BufNewFile,BufRead Vagrantfile set ft=ruby
128+
autocmd BufNewFile,BufRead *.config set ft=xml
129+
130+
" Usefull setting for working with Ruby files.
131+
autocmd FileType ruby set tabstop=2 shiftwidth=2 smarttab expandtab softtabstop=2 autoindent
132+
autocmd FileType ruby set smartindent cinwords=if,elsif,else,for,while,try,rescue,ensure,def,class,module
133+
134+
" Usefull setting for working with Python files.
135+
autocmd FileType python set tabstop=4 shiftwidth=4 smarttab expandtab softtabstop=4 autoindent
136+
" Automatically indent a line that starts with the following words (after we press ENTER).
137+
autocmd FileType python set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
138+
139+
" Usefull setting for working with Go files.
140+
autocmd FileType go set tabstop=4 shiftwidth=4 smarttab expandtab softtabstop=4 autoindent
141+
" Automatically indent a line that starts with the following words (after we press ENTER).
142+
autocmd FileType go set smartindent cinwords=if,else,switch,for,func
143+
EOF
144+
'@
145+
146+
# build the setup.
147+
Bash 'cd /c/vagrant && make clean all'
148+
149+
# install and start elasticsearch.
150+
Start-Process `
151+
(dir C:\vagrant\elasticsearch-*-setup*.exe).FullName `
152+
'/VERYSILENT','/SUPPRESSMSGBOXES' `
153+
-Wait
154+
net start elasticsearch
155+
156+
# remove the default desktop shortcuts.
157+
del C:\Users\Public\Desktop\*.lnk
158+
159+
# add MSYS2 shortcut to the Desktop and Start Menu.
160+
Install-ChocolateyShortcut `
161+
-ShortcutFilePath "$env:USERPROFILE\Desktop\MSYS2 Bash.lnk" `
162+
-TargetPath "$msys2BasePath\msys2.exe"
163+
Install-ChocolateyShortcut `
164+
-ShortcutFilePath "C:\Users\All Users\Microsoft\Windows\Start Menu\Programs\MSYS2 Bash.lnk" `
165+
-TargetPath "$msys2BasePath\msys2.exe"
166+
167+
# add Services shortcut to the Desktop.
168+
Install-ChocolateyShortcut `
169+
-ShortcutFilePath "$env:USERPROFILE\Desktop\Services.lnk" `
170+
-TargetPath "$env:windir\system32\services.msc" `
171+
-Description 'Windows Services'
172+
173+
# add Elasticsearch shortcut to the Desktop.
174+
Install-ChocolateyShortcut `
175+
-ShortcutFilePath "$env:USERPROFILE\Desktop\Elasticsearch.lnk" `
176+
-TargetPath 'C:\Program Files\Elasticsearch' `
177+
-Description 'Elasticsearch installation directory'
178+
179+
# add Local Elasticsearch HTTP endpoint shortcut to the Desktop.
180+
Install-ChocolateyShortcut `
181+
-ShortcutFilePath "$env:USERPROFILE\Desktop\Elasticsearch Endpoint.lnk" `
182+
-TargetPath 'http://localhost:9200' `
183+
-IconLocation 'C:\vagrant\elasticsearch.ico' `
184+
-Description 'Local Elasticsearch HTTP endpoint'
185+
186+
# add Elasticsearch Logs shortcut to the Desktop.
187+
Install-ChocolateyShortcut `
188+
-ShortcutFilePath "$env:USERPROFILE\Desktop\Elasticsearch Logs.lnk" `
189+
-TargetPath 'C:\ProgramData\chocolatey\lib\baretail\tools\baretail.exe' `
190+
-Arguments '"C:\Program Files\Elasticsearch\logs\elasticsearch.log"' `
191+
-Description 'Local Elasticsearch HTTP endpoint'
192+
193+
# enable show window content while dragging.
194+
Set-ItemProperty -Path 'HKCU:Control Panel\Desktop' -Name DragFullWindows -Value 1
195+
196+
# never combine the taskbar buttons.
197+
#
198+
# possibe values:
199+
# 0: always combine and hide labels (default)
200+
# 1: combine when taskbar is full
201+
# 2: never combine
202+
Set-ItemProperty -Path HKCU:Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name TaskbarGlomLevel -Value 2

0 commit comments

Comments
 (0)