forked from rgl/windows-vagrant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
203 lines (183 loc) · 8.84 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# Disable builtin rules and variables since they aren't used
# This makes the output of "make -d" much easier to follow and speeds up evaluation
# NB you can use make --print-data-base --dry-run to troubleshoot this Makefile.
MAKEFLAGS+= --no-builtin-rules
MAKEFLAGS+= --no-builtin-variables
# uncomment the next two lines to use the local development version of the
# windows-update packer plugin. you probably want to change the path too.
#export PACKER_CONFIG_DIR:= $(HOME)/Projects/packer-plugin-windows-update/dist/test
#export PACKER_PLUGIN_PATH:= $(HOME)/Projects/packer-plugin-windows-update/dist/test/plugins
# libvirt images.
IMAGES+= windows-2022
IMAGES+= windows-2022-uefi
IMAGES+= windows-2025
IMAGES+= windows-2025-uefi
IMAGES+= windows-11-24h2
IMAGES+= windows-11-24h2-uefi
# Proxmox images.
PROXMOX_IMAGES+= windows-2022
PROXMOX_IMAGES+= windows-2022-uefi
PROXMOX_IMAGES+= windows-2025
PROXMOX_IMAGES+= windows-2025-uefi
PROXMOX_IMAGES+= windows-11-24h2
PROXMOX_IMAGES+= windows-11-24h2-uefi
# Hyper-V images.
HYPERV_IMAGES+= windows-2022
HYPERV_IMAGES+= windows-2025
HYPERV_IMAGES+= windows-11-24h2
# vSphere images.
VSPHERE_IMAGES+= windows-2022
VSPHERE_IMAGES+= windows-2022-uefi
VSPHERE_IMAGES+= windows-2025
VSPHERE_IMAGES+= windows-2025-uefi
# Generate the build-* targets.
LIBVIRT_BUILDS= $(addsuffix -libvirt,$(addprefix build-,$(IMAGES)))
PROXMOX_BUILDS= $(addsuffix -proxmox,$(addprefix build-,$(PROXMOX_IMAGES)))
HYPERV_BUILDS= $(addsuffix -hyperv,$(addprefix build-,$(HYPERV_IMAGES)))
VSPHERE_BUILDS= $(addsuffix -vsphere,$(addprefix build-,$(VSPHERE_IMAGES)))
.PHONY: help always $(LIBVIRT_BUILDS) $(PROXMOX_BUILDS) $(VSPHERE_BUILDS)
help:
@echo Type one of the following commands to build a specific windows box.
@echo
@echo libvirt targets:
@$(addprefix echo make ,$(addsuffix ;,$(LIBVIRT_BUILDS)))
@echo
@echo Proxmox targets:
@$(addprefix echo make ,$(addsuffix ;,$(PROXMOX_BUILDS)))
@echo
@echo Hyper-V targets:
@$(addprefix echo make ,$(addsuffix ;,$(HYPERV_BUILDS)))
@echo
@echo vSphere targets:
@$(addprefix echo make ,$(addsuffix ;,$(VSPHERE_BUILDS)))
# Target specific pattern rules for build-* targets.
$(LIBVIRT_BUILDS): build-%-libvirt: %-amd64-libvirt.box
$(PROXMOX_BUILDS): build-%-proxmox: %-amd64-proxmox.box
$(HYPERV_BUILDS): build-%-hyperv: %-amd64-hyperv.box
$(VSPHERE_BUILDS): build-%-vsphere: %-amd64-vsphere.box
%-amd64-libvirt.box: %.pkr.hcl tmp/%/autounattend.xml Vagrantfile.template *.ps1 drivers
rm -f $@
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-amd64-libvirt-packer-init.log \
packer init $*.pkr.hcl
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-amd64-libvirt-packer.log PKR_VAR_vagrant_box=$@ \
packer build -only=qemu.$*-amd64 -on-error=abort $*.pkr.hcl
./get-windows-updates-from-packer-log.sh \
$*-amd64-libvirt-packer.log \
>$*-amd64-libvirt-windows-updates.log
@./box-metadata.sh libvirt $*-amd64 $@
%-amd64-proxmox.box: %.pkr.hcl tmp/%/autounattend.xml Vagrantfile.template *.ps1 drivers
rm -f $@
sed -E 's,<Path>E:\\</Path>,<Path>D:\\</Path>,g' -i tmp/$*/autounattend.xml
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-amd64-proxmox-packer-init.log \
packer init $*.pkr.hcl
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-amd64-proxmox-packer.log PKR_VAR_vagrant_box=$@ \
packer build -only=proxmox-iso.$*-amd64 -on-error=abort $*.pkr.hcl
./get-windows-updates-from-packer-log.sh \
$*-amd64-proxmox-packer.log \
>$*-amd64-proxmox-windows-updates.log
%-amd64-hyperv.box: %.pkr.hcl tmp/%-uefi/autounattend.xml Vagrantfile.template *.ps1
rm -f $@
sed -E '/<DriverPaths>/,/<\/DriverPaths>/d' -i tmp/$*-uefi/autounattend.xml
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-amd64-hyperv-packer-init.log \
packer init $*.pkr.hcl
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-amd64-hyperv-packer.log PKR_VAR_vagrant_box=$@ \
packer build -only=hyperv-iso.$*-amd64 -on-error=abort $*.pkr.hcl
./get-windows-updates-from-packer-log.sh \
$*-amd64-hyperv-packer.log \
>$*-amd64-hyperv-windows-updates.log
@./box-metadata.sh hyperv $*-amd64 $@
%-uefi-amd64-libvirt.box: %-uefi.pkr.hcl tmp/%-uefi/autounattend.xml Vagrantfile-uefi.template *.ps1 drivers
rm -f $@
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-uefi-amd64-libvirt-packer-init.log \
packer init $*-uefi.pkr.hcl
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-uefi-amd64-libvirt-packer.log PKR_VAR_vagrant_box=$@ \
packer build -only=qemu.$*-uefi-amd64 -on-error=abort $*-uefi.pkr.hcl
./get-windows-updates-from-packer-log.sh \
$*-uefi-amd64-libvirt-packer.log \
>$*-uefi-amd64-libvirt-windows-updates.log
@./box-metadata.sh libvirt $*-uefi-amd64 $@
%-uefi-amd64-proxmox.box: %-uefi.pkr.hcl tmp/%-uefi/autounattend.xml Vagrantfile-uefi.template *.ps1 drivers
rm -f $@
sed -E 's,<Path>E:\\</Path>,<Path>D:\\</Path>,g' -i tmp/$*-uefi/autounattend.xml
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-uefi-amd64-proxmox-packer-init.log \
packer init $*-uefi.pkr.hcl
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-uefi-amd64-proxmox-packer.log PKR_VAR_vagrant_box=$@ \
packer build -only=proxmox-iso.$*-uefi-amd64 -on-error=abort $*-uefi.pkr.hcl
./get-windows-updates-from-packer-log.sh \
$*-uefi-amd64-proxmox-packer.log \
>$*-uefi-amd64-proxmox-windows-updates.log
tmp/%-vsphere/autounattend.xml: %/autounattend.xml always
mkdir -p "$$(dirname $@)"
sed -E '/<DriverPaths>/,/<\/DriverPaths>/d' $< >$@
if [ -n '${PKR_VAR_windows_product_key}' ]; then \
sed -E 's,<!--<Key>.+</Key>-->,<Key>${PKR_VAR_windows_product_key}</Key>,g' -i $@; \
fi
tmp/%/autounattend.xml: %/autounattend.xml always
mkdir -p "$$(dirname $@)"
cp -f $< $@
if [ -n '${PKR_VAR_windows_product_key}' ]; then \
sed -E 's,<!--<Key>.+</Key>-->,<Key>${PKR_VAR_windows_product_key}</Key>,g' -i $@; \
fi
%-amd64-vsphere.box: %-vsphere.pkr.hcl tmp/%-vsphere/autounattend.xml Vagrantfile.template *.ps1
rm -f $@
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-amd64-vsphere-packer-init.log \
packer init $*-vsphere.pkr.hcl
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-amd64-vsphere-packer.log PKR_VAR_vagrant_box=$@ \
packer build -only=vsphere-iso.$*-amd64 -on-error=abort $*-vsphere.pkr.hcl
./get-windows-updates-from-packer-log.sh \
$*-amd64-vsphere-packer.log \
>$*-amd64-vsphere-windows-updates.log
@echo 'Removing all cd-roms (except the first)...'
govc device.ls "-vm.ipath=$$VSPHERE_TEMPLATE_IPATH" \
| grep ^cdrom- \
| tail -n+2 \
| awk '{print $$1}' \
| xargs -L1 govc device.remove "-vm.ipath=$$VSPHERE_TEMPLATE_IPATH"
@echo 'Converting to template...'
govc vm.markastemplate "$$VSPHERE_TEMPLATE_IPATH"
@echo 'Creating the local box file...'
rm -rf tmp/$@-contents
mkdir -p tmp/$@-contents
echo '{"provider":"vsphere"}' >tmp/$@-contents/metadata.json
cp Vagrantfile.template tmp/$@-contents/Vagrantfile
tar cvf $@ -C tmp/$@-contents .
@echo BOX successfully built!
@echo to add to local vagrant install do:
@echo vagrant box add -f $*-amd64 $@
%-uefi-amd64-vsphere.box: %-uefi-vsphere.pkr.hcl tmp/%-uefi-vsphere/autounattend.xml Vagrantfile-uefi.template *.ps1
rm -f $@
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-uefi-amd64-vsphere-packer-init.log \
packer init $*-uefi-vsphere.pkr.hcl
CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$*-uefi-amd64-vsphere-packer.log PKR_VAR_vagrant_box=$@ \
packer build -only=vsphere-iso.$*-uefi-amd64 -on-error=abort $*-uefi-vsphere.pkr.hcl
./get-windows-updates-from-packer-log.sh \
$*-uefi-amd64-vsphere-packer.log \
>$*-uefi-amd64-vsphere-windows-updates.log
@echo 'Removing all cd-roms (except the first)...'
govc device.ls "-vm.ipath=$$VSPHERE_TEMPLATE_IPATH" \
| grep ^cdrom- \
| tail -n+2 \
| awk '{print $$1}' \
| xargs -L1 govc device.remove "-vm.ipath=$$VSPHERE_TEMPLATE_IPATH"
@echo 'Converting to template...'
govc vm.markastemplate "$$VSPHERE_TEMPLATE_IPATH"
@echo 'Creating the local box file...'
rm -rf tmp/$@-contents
mkdir -p tmp/$@-contents
echo '{"provider":"vsphere"}' >tmp/$@-contents/metadata.json
cp Vagrantfile.template tmp/$@-contents/Vagrantfile
tar cvf $@ -C tmp/$@-contents .
@echo BOX successfully built!
@echo to add to local vagrant install do:
@echo vagrant box add -f $*-uefi-amd64 $@
drivers:
rm -rf drivers.tmp
mkdir -p drivers.tmp
@# see https://docs.fedoraproject.org/en-US/quick-docs/creating-windows-virtual-machines-using-virtio-drivers/index.html
@# see https://github.com/virtio-win/virtio-win-guest-tools-installer
@# see https://github.com/virtio-win/virtio-win-pkg-scripts
wget -P drivers.tmp https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.266-1/virtio-win-0.1.266.iso
7z x -odrivers.tmp drivers.tmp/virtio-win-*.iso
mv drivers.tmp drivers
clean:
rm -rf *.log *.box