Skip to content

Commit 04f55e6

Browse files
author
Mischa Taylor
committed
Experiment with automated Windows Updates in eval Win2012R2
1 parent 6f8bd8e commit 04f55e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+292
-90
lines changed

Makefile

+9-2
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,17 @@ ifndef CM_VERSION
5353
endif
5454
endif
5555
BOX_VERSION ?= $(shell cat VERSION)
56+
UPDATE ?= false
5657
ifeq ($(CM),nocm)
5758
BOX_SUFFIX := -$(CM)-$(BOX_VERSION).box
5859
else
5960
BOX_SUFFIX := -$(CM)$(CM_VERSION)-$(BOX_VERSION).box
6061
endif
6162
# Packer does not allow empty variables, so only pass variables that are defined
6263
ifdef CM_VERSION
63-
PACKER_VARS := -var 'cm=$(CM)' -var 'cm_version=$(CM_VERSION)' -var 'version=$(BOX_VERSION)'
64+
PACKER_VARS := -var 'cm=$(CM)' -var 'cm_version=$(CM_VERSION)' -var 'version=$(BOX_VERSION)' -var 'update=$(UPDATE)'
6465
else
65-
PACKER_VARS := -var 'cm=$(CM)' -var 'version=$(BOX_VERSION)'
66+
PACKER_VARS := -var 'cm=$(CM)' -var 'version=$(BOX_VERSION)' -var 'update=$(UPDATE)'
6667
endif
6768
ifdef PACKER_DEBUG
6869
PACKER := PACKER_LOG=1 packer --debug
@@ -696,6 +697,12 @@ list:
696697
echo $$shortcut_target ; \
697698
done
698699

700+
validate:
701+
@for template_filename in $(TEMPLATE_FILENAMES) ; do \
702+
echo Checking $$template_filename ; \
703+
packer validate $$template_filename ; \
704+
done
705+
699706
clean: clean-builders clean-output clean-packer-cache
700707

701708
clean-builders:

eval-win2008r2-datacenter.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"cm": "chef",
55
"cm_version": "",
66
"iso_url": "http://download.microsoft.com/download/7/5/E/75EC4E54-5B02-42D6-8879-D8D3A25FBEF7/7601.17514.101119-1850_x64fre_server_eval_en-us-GRMSXEVAL_EN_DVD.iso",
7-
"iso_checksum": "beed231a34e90e1dd9a04b3afabec31d62ce3889"
7+
"iso_checksum": "beed231a34e90e1dd9a04b3afabec31d62ce3889",
8+
"update": true
89
},
910
"builders": [
1011
{
@@ -75,7 +76,8 @@
7576
"remote_path": "/tmp/script.bat",
7677
"environment_vars": [
7778
"CM={{user `cm`}}",
78-
"CM_VERSION={{user `cm_version`}}"
79+
"CM_VERSION={{user `cm_version`}}",
80+
"UPDATE={{user `update`}}"
7981
],
8082
"execute_command": "{{.Vars}} cmd /c C:/Windows/Temp/script.bat",
8183
"scripts": [

eval-win2012r2-datacenter.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"cm": "chef",
55
"cm_version": "",
66
"iso_url": "http://download.microsoft.com/download/6/2/A/62A76ABB-9990-4EFC-A4FE-C7D698DAEB96/9600.16384.WINBLUE_RTM.130821-1623_X64FRE_SERVER_EVAL_EN-US-IRM_SSS_X64FREE_EN-US_DV5.ISO",
7-
"iso_checksum": "7e3f89dbff163e259ca9b0d1f078daafd2fed513"
7+
"iso_checksum": "7e3f89dbff163e259ca9b0d1f078daafd2fed513",
8+
"update": true
89
},
910
"builders": [
1011
{
@@ -77,10 +78,12 @@
7778
"remote_path": "/tmp/script.bat",
7879
"environment_vars": [
7980
"CM={{user `cm`}}",
80-
"CM_VERSION={{user `cm_version`}}"
81+
"CM_VERSION={{user `cm_version`}}",
82+
"UPDATE={{user `update`}}"
8183
],
8284
"execute_command": "{{.Vars}} cmd /c C:/Windows/Temp/script.bat",
8385
"scripts": [
86+
"script/update.bat",
8487
"script/vagrant.bat",
8588
"script/cmtool.bat",
8689
"script/vmtool.bat",

eval-win7x64-enterprise.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"cm_version": "",
66
"iso_url": "http://care.dlservice.microsoft.com/dl/download/evalx/win7/x64/EN/7600.16385.090713-1255_x64fre_enterprise_en-us_EVAL_Eval_Enterprise-GRMCENXEVAL_EN_DVD.iso",
77
"iso_checksum": "15ddabafa72071a06d5213b486a02d5b55cb7070",
8-
"shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c 'Packer Shutdown'"
8+
"shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c 'Packer Shutdown'",
9+
"update": true
910
},
1011
"builders": [
1112
{
@@ -87,7 +88,8 @@
8788
"remote_path": "/tmp/script.bat",
8889
"environment_vars": [
8990
"CM={{user `cm`}}",
90-
"CM_VERSION={{user `cm_version`}}"
91+
"CM_VERSION={{user `cm_version`}}",
92+
"UPDATE={{user `update`}}"
9193
],
9294
"execute_command": "{{.Vars}} cmd /c C:/Windows/Temp/script.bat",
9395
"scripts": [

eval-win81x64-enterprise.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"cm": "chef",
55
"cm_version": "",
66
"iso_url": "http://download.microsoft.com/download/B/9/9/B999286E-0A47-406D-8B3D-5B5AD7373A4A/9600.16384.WINBLUE_RTM.130821-1623_X64FRE_ENTERPRISE_EVAL_EN-US-IRM_CENA_X64FREE_EN-US_DV5.ISO",
7-
"iso_checksum": "73321fa912305e5a16096ef62380a91ee1f112da"
7+
"iso_checksum": "73321fa912305e5a16096ef62380a91ee1f112da",
8+
"update": true
89
},
910
"builders": [
1011
{
@@ -77,7 +78,8 @@
7778
"remote_path": "/tmp/script.bat",
7879
"environment_vars": [
7980
"CM={{user `cm`}}",
80-
"CM_VERSION={{user `cm_version`}}"
81+
"CM_VERSION={{user `cm_version`}}",
82+
"UPDATE={{user `update`}}"
8183
],
8284
"execute_command": "{{.Vars}} cmd /c C:/Windows/Temp/script.bat",
8385
"scripts": [

script/update.bat

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<!-- :
2+
if NOT "%UPDATE%" == "true" exit
3+
echo ==^> Running Windows Update
4+
cscript //nologo "%~f0?.wsf"
5+
6+
exit /b
7+
8+
----- Begin wsf script --->
9+
<job><script language="VBScript">
10+
Set updateSession = CreateObject("Microsoft.Update.Session")
11+
updateSession.ClientApplicationID = "Packer"
12+
13+
Set updateSearcher = updateSession.CreateUpdateSearcher()
14+
WScript.Echo "Searching for updates..." & vbCRLF
15+
16+
Set searchResult = _
17+
updateSearcher.Search("IsInstalled=0 and Type='Software' and IsHidden=0")
18+
19+
WScript.Echo "List of applicable items on the machine:"
20+
For I = 0 To SearchResult.Updates.Count-1
21+
Set update = searchResult.Updates.Item(I)
22+
WScript.Echo I + 1 & "> " & update.Title
23+
Next
24+
If searchResult.Updates.Count = 0 Then
25+
WScript.Echo "There are no applicable updates."
26+
WScript.Quit
27+
End If
28+
29+
WScript.Echo vbCRLF & "Creating collection of updates to download:"
30+
Set updatesToDownload = CreateObject("Microsoft.Update.UpdateColl")
31+
For I = 0 to searchResult.Updates.Count-1
32+
Set update = searchResult.Updates.Item(I)
33+
addThisUpdate = false
34+
If update.InstallationBehavior.CanRequestUserInput = true Then
35+
WScript.Echo I + 1 & "> skipping: " & update.Title & _
36+
" because it requires user input"
37+
Else
38+
If update.EulaAccepted = false Then
39+
update.AcceptEula()
40+
addThisUpdate = true
41+
Else
42+
addThisUpdate = true
43+
End If
44+
End If
45+
If addThisUpdate = true Then
46+
WScript.Echo I + 1 & "> adding: " & update.Title
47+
updatesToDownload.Add(update)
48+
End If
49+
Next
50+
51+
If updatesToDownload.Count = 0 Then
52+
WScript.Echo "All applicable updates were skipped."
53+
WScript.Quit
54+
End If
55+
56+
WScript.Echo vbCRLF & "Downloading updates..."
57+
58+
59+
Set downloader = updateSession.CreateUpdateDownloader()
60+
downloader.Updates = updatesToDownload
61+
downloader.Download()
62+
63+
Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
64+
rebootMayBeRequired = false
65+
WScript.Echo vbCRLF & "Successfully downloaded updates:"
66+
67+
For I = 0 To searchResult.Updates.Count-1
68+
set update = searchResult.Updates.Item(I)
69+
If update.IsDownloaded = true Then
70+
WScript.Echo I + 1 & "> " & update.Title
71+
updatesToInstall.Add(update)
72+
If update.InstallationBehavior.RebootBehavior > 0 Then
73+
rebootMayBeRequired = true
74+
End If
75+
End If
76+
Next
77+
78+
If updatesToInstall.Count = 0 Then
79+
WScript.Echo "No updates were sucessfully downloaded."
80+
WScript.Quit
81+
End If
82+
83+
WScript.Echo "Installing updates..."
84+
Set installer = updateSession.CreateUpdateInstaller()
85+
installer.Updates = updatesToInstall
86+
Set installationResult = installer.Install()
87+
88+
WScript.Echo "Installation Result: " & _
89+
installationResult.ResultCode
90+
WScript.Echo "Reboot Required: " & _
91+
installationResult.RebootRequired & vbCRLF
92+
WScript.Echo "Listing of updates installed " & _
93+
"and individual installation results:"
94+
95+
For I = 0 to updatesToInstall.Count - 1
96+
WScript.Echo I + 1 & "> " & _
97+
updatesToInstall.Item(I).Title & _
98+
": " & installationResult.GetUpdateResult(I).ResultCode
99+
Next
100+
101+
If rebootMayBeRequired Then
102+
Set objShell = WScript.CreateObject("wscript.shell")
103+
objShell.Run "shutdown.exe /r /t 00"
104+
WScript.Sleep 60
105+
End If
106+
</script></job>

win2008r2-datacenter-cygwin.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"cm": "chef",
55
"cm_version": "",
66
"iso_url": "iso/en_windows_server_2008_r2_with_sp1_vl_build_x64_dvd_617403.iso",
7-
"iso_checksum": "7e7e9425041b3328ccf723a0855c2bc4f462ec57"
7+
"iso_checksum": "7e7e9425041b3328ccf723a0855c2bc4f462ec57",
8+
"update": true
89
},
910
"builders": [
1011
{
@@ -73,7 +74,8 @@
7374
"remote_path": "/tmp/script.bat",
7475
"environment_vars": [
7576
"CM={{user `cm`}}",
76-
"CM_VERSION={{user `cm_version`}}"
77+
"CM_VERSION={{user `cm_version`}}",
78+
"UPDATE={{user `update`}}"
7779
],
7880
"execute_command": "{{.Vars}} cmd /c $(/bin/cygpath -m '{{.Path}}')",
7981
"scripts": [

win2008r2-datacenter.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"cm": "chef",
55
"cm_version": "",
66
"iso_url": "iso/en_windows_server_2008_r2_with_sp1_vl_build_x64_dvd_617403.iso",
7-
"iso_checksum": "7e7e9425041b3328ccf723a0855c2bc4f462ec57"
7+
"iso_checksum": "7e7e9425041b3328ccf723a0855c2bc4f462ec57",
8+
"update": true
89
},
910
"builders": [
1011
{
@@ -75,7 +76,8 @@
7576
"remote_path": "/tmp/script.bat",
7677
"environment_vars": [
7778
"CM={{user `cm`}}",
78-
"CM_VERSION={{user `cm_version`}}"
79+
"CM_VERSION={{user `cm_version`}}",
80+
"UPDATE={{user `update`}}"
7981
],
8082
"execute_command": "{{.Vars}} cmd /c C:/Windows/Temp/script.bat",
8183
"scripts": [

win2008r2-enterprise-cygwin.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"cm": "chef",
55
"cm_version": "",
66
"iso_url": "so/en_windows_server_2008_r2_with_sp1_vl_build_x64_dvd_617403.iso",
7-
"iso_checksum": "7e7e9425041b3328ccf723a0855c2bc4f462ec57"
7+
"iso_checksum": "7e7e9425041b3328ccf723a0855c2bc4f462ec57",
8+
"update": true
89
},
910
"builders": [
1011
{
@@ -73,7 +74,8 @@
7374
"remote_path": "/tmp/script.bat",
7475
"environment_vars": [
7576
"CM={{user `cm`}}",
76-
"CM_VERSION={{user `cm_version`}}"
77+
"CM_VERSION={{user `cm_version`}}",
78+
"UPDATE={{user `update`}}"
7779
],
7880
"execute_command": "{{.Vars}} cmd /c $(/bin/cygpath -m '{{.Path}}')",
7981
"scripts": [

win2008r2-enterprise.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"cm": "chef",
55
"cm_version": "",
66
"iso_url": "iso/en_windows_server_2008_r2_with_sp1_vl_build_x64_dvd_617403.iso",
7-
"iso_checksum": "7e7e9425041b3328ccf723a0855c2bc4f462ec57"
7+
"iso_checksum": "7e7e9425041b3328ccf723a0855c2bc4f462ec57",
8+
"update": true
89
},
910
"builders": [
1011
{
@@ -75,7 +76,8 @@
7576
"remote_path": "/tmp/script.bat",
7677
"environment_vars": [
7778
"CM={{user `cm`}}",
78-
"CM_VERSION={{user `cm_version`}}"
79+
"CM_VERSION={{user `cm_version`}}",
80+
"UPDATE={{user `update`}}"
7981
],
8082
"execute_command": "{{.Vars}} cmd /c C:/Windows/Temp/script.bat",
8183
"scripts": [

win2008r2-standard-cygwin.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"cm": "chef",
55
"cm_version": "",
66
"iso_url": "iso/en_windows_server_2008_r2_with_sp1_vl_build_x64_dvd_617403.iso",
7-
"iso_checksum": "7e7e9425041b3328ccf723a0855c2bc4f462ec57"
7+
"iso_checksum": "7e7e9425041b3328ccf723a0855c2bc4f462ec57",
8+
"update": true
89
},
910
"builders": [
1011
{
@@ -73,7 +74,8 @@
7374
"remote_path": "/tmp/script.bat",
7475
"environment_vars": [
7576
"CM={{user `cm`}}",
76-
"CM_VERSION={{user `cm_version`}}"
77+
"CM_VERSION={{user `cm_version`}}",
78+
"UPDATE={{user `update`}}"
7779
],
7880
"execute_command": "{{.Vars}} cmd /c $(/bin/cygpath -m '{{.Path}}')",
7981
"scripts": [

win2008r2-standard.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"cm": "chef",
55
"cm_version": "",
66
"iso_url": "iso/en_windows_server_2008_r2_with_sp1_vl_build_x64_dvd_617403.iso",
7-
"iso_checksum": "7e7e9425041b3328ccf723a0855c2bc4f462ec57"
7+
"iso_checksum": "7e7e9425041b3328ccf723a0855c2bc4f462ec57",
8+
"update": true
89
},
910
"builders": [
1011
{
@@ -75,7 +76,8 @@
7576
"remote_path": "/tmp/script.bat",
7677
"environment_vars": [
7778
"CM={{user `cm`}}",
78-
"CM_VERSION={{user `cm_version`}}"
79+
"CM_VERSION={{user `cm_version`}}",
80+
"UPDATE={{user `update`}}"
7981
],
8082
"execute_command": "{{.Vars}} cmd /c C:/Windows/Temp/script.bat",
8183
"scripts": [

win2008r2-web-cygwin.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"cm": "chef",
55
"cm_version": "",
66
"iso_url": "iso/en_windows_server_2008_r2_with_sp1_vl_build_x64_dvd_617403.iso",
7-
"iso_checksum": "7e7e9425041b3328ccf723a0855c2bc4f462ec57"
7+
"iso_checksum": "7e7e9425041b3328ccf723a0855c2bc4f462ec57",
8+
"update": true
89
},
910
"builders": [
1011
{
@@ -73,7 +74,8 @@
7374
"remote_path": "/tmp/script.bat",
7475
"environment_vars": [
7576
"CM={{user `cm`}}",
76-
"CM_VERSION={{user `cm_version`}}"
77+
"CM_VERSION={{user `cm_version`}}",
78+
"UPDATE={{user `update`}}"
7779
],
7880
"execute_command": "{{.Vars}} cmd /c $(/bin/cygpath -m '{{.Path}}')",
7981
"scripts": [

win2008r2-web.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"cm": "chef",
55
"cm_version": "",
66
"iso_url": "iso/en_windows_server_2008_r2_with_sp1_vl_build_x64_dvd_617403.iso",
7-
"iso_checksum": "7e7e9425041b3328ccf723a0855c2bc4f462ec57"
7+
"iso_checksum": "7e7e9425041b3328ccf723a0855c2bc4f462ec57",
8+
"update": true
89
},
910
"builders": [
1011
{
@@ -75,7 +76,8 @@
7576
"remote_path": "/tmp/script.bat",
7677
"environment_vars": [
7778
"CM={{user `cm`}}",
78-
"CM_VERSION={{user `cm_version`}}"
79+
"CM_VERSION={{user `cm_version`}}",
80+
"UPDATE={{user `update`}}"
7981
],
8082
"execute_command": "{{.Vars}} cmd /c C:/Windows/Temp/script.bat",
8183
"scripts": [

0 commit comments

Comments
 (0)