From f266404928b28faf4571fb8f0629904686c366ef Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Mon, 6 Jan 2020 01:17:21 -0600 Subject: [PATCH 1/7] Applied changes in README.md from daxgames/boxcutter_windows@357a5db532d904169c86bd4ee5d34eba92ccd9a6 for updating the Chef provisioner. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 573a3ec0..86751a7c 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,9 @@ the output of `make list` accordingly. Possible values for the CM variable are: * `nocm` - No configuration management tool -* `chef` - Install Chef +* `chef` - Install Chef Client +* `chefdk` - Install Chef Development Kit +* `chef-workstation` - Install Chef Workstation * `puppet` - Install Puppet * `salt` - Install Salt From b9c1098657f4911e030caa9b86879d16a877277a Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Mon, 6 Jan 2020 01:17:48 -0600 Subject: [PATCH 2/7] Applied changes in .gitignore from daxgames/boxcutter_windows@357a5db532d904169c86bd4ee5d34eba92ccd9a6 for updating the Chef provisioner. --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index d2d54406..468d08c6 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,7 @@ Makefile.local rspec_html_reports .DS_Store + +*.*.json +floppy/*.*.* +script/*.*.* From a73010222e17b704d21a6f1fac68b8179d0b878c Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Mon, 6 Jan 2020 01:17:58 -0600 Subject: [PATCH 3/7] Applied changes in Makefile from daxgames/boxcutter_windows@357a5db532d904169c86bd4ee5d34eba92ccd9a6 for updating the Chef provisioner. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0915e878..38e832c7 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ WIN81_X64_PRO_CHECKSUM ?= e50a6f0f08e933f25a71fbc843827fe752ed0365 WIN81_X86_PRO ?= iso/en_windows_8.1_professional_vl_with_update_x86_dvd_4065201.iso WIN81_X86_PRO_CHECKSUM ?= c2d6f5d06362b7cb17dfdaadfb848c760963b254 -# Possible values for CM: (nocm | chef | chefdk | salt | puppet) +# Possible values for CM: (nocm | chef | chefdk | chef-workstation | salt | puppet) CM ?= nocm # Possible values for CM_VERSION: (latest | x.y.z | x.y) CM_VERSION ?= From b12e7eab85b14ec65d59c974a5935994c5cb8cef Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Mon, 6 Jan 2020 01:44:56 -0600 Subject: [PATCH 4/7] Cleaned up changes to script/cmtool.bat from daxgames/boxcutter_windows@357a5db532d904169c86bd4ee5d34eba92ccd9a6 so that it only touches the Chef provisioners. --- script/cmtool.bat | 111 ++++++++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 49 deletions(-) diff --git a/script/cmtool.bat b/script/cmtool.bat index 6b15068d..4c9fff72 100644 --- a/script/cmtool.bat +++ b/script/cmtool.bat @@ -2,14 +2,17 @@ @for %%i in (a:\_packer_config*.cmd) do @call "%%~i" @if defined PACKER_DEBUG (@echo on) else (@echo off) +if not defined TEMP set TEMP=%LOCALAPPDATA%\Temp + if not defined CM echo ==^> ERROR: The "CM" variable was not found in the environment & goto exit1 if "%CM%" == "nocm" goto nocm if not defined CM_VERSION echo ==^> ERROR: The "CM_VERSION" variable was not found in the environment & set CM_VERSION=latest -if "%CM%" == "chef" goto chef -if "%CM%" == "chefdk" goto chefdk +if "%CM%" == "chef" goto chef +if "%CM%" == "chefdk" goto chef +if "%CM%" == "chef-workstation" goto chef if "%CM%" == "puppet" goto puppet if "%CM%" == "salt" goto salt @@ -20,15 +23,64 @@ goto exit1 :::::::::::: :chef :::::::::::: +if "%CM%" == "chef" ( + set "CHEF_PRODUCT_NAME=Chef Client" +) else if "%CM%" == "chefdk" ( + set "CHEF_PRODUCT_NAME=Chef DK" +) else if "%CM%" == "chef-workstation" ( + set "CHEF_PRODUCT_NAME=Chef Workstation" +) -if not defined CHEF_URL if "%CM_VERSION%" == "latest" set CM_VERSION=13.6.4 -if not defined CHEF_URL set CHEF_64_URL=https://packages.chef.io/files/stable/chef/%CM_VERSION%/windows/2008r2/chef-client-%CM_VERSION%-1-x64.msi -if not defined CHEF_URL set CHEF_32_URL=https://packages.chef.io/files/stable/chef/%CM_VERSION%/windows/2008r2/chef-client-%CM_VERSION%-1-x86.msi +set CHEF_PRODUCT_VER=%CM_VERSION% -if defined ProgramFiles(x86) ( - SET CHEF_URL=%CHEF_64_URL% +if not defined CHEF_URL if "%CHEF_PRODUCT_VER%" == "latest" ( + if "%CM%" == "chef-workstation" ( + set CHEF_PRODUCT_VER=0.2.48 + ) else if "%CM%" == "chefdk" ( + set CHEF_PRODUCT_VER=2.3.4 + ) else if "%CM%" == "chef" ( + set CHEF_PRODUCT_VER=13.6.4 + ) +) + +:: strip -1 if %CHEF_PRODUCT_VER% ends in -1 +set CHEF_PRODUCT_VER=%CHEF_PRODUCT_VER:-1=% + +if "%PROCESSOR_ARCHITECTURE%" == "x86" ( + set CHEF_ARCH=x86 ) else ( - SET CHEF_URL=%CHEF_32_URL% + set CHEF_ARCH=x64 +) + +if not defined CHEF_URL ( + echo ==^> Getting %CHEF_PRODUCT_NAME% %CHEF_PRODUCT_VER% %CHEF_ARCH% download URL + set url="https://omnitruck.chef.io/stable/%CM%/metadata?p=windows&pv=2012r2&m=%CHEF_ARCH%&v=%CHEF_PRODUCT_VER%" + set filename="%TEMP%\omnitruck.txt" + + echo "==^> Using Chef Omitruck API URL: !url!" + if defined http_proxy ( + if defined no_proxy ( + powershell -Command "$wc = (New-Object System.Net.WebClient); $wc.proxy = (new-object System.Net.WebProxy('%http_proxy%')) ; $wc.proxy.BypassList = (('%no_proxy%').split(',')) ; $wc.DownloadFile('!url!', '!filename!')" + ) else ( + powershell -Command "$wc = (New-Object System.Net.WebClient); $wc.proxy = (new-object System.Net.WebProxy('%http_proxy%')) ; $wc.DownloadFile('!url!', '!filename!')" + ) + ) else ( + powershell -command "(New-Object System.Net.WebClient).DownloadFile('!url!', '!filename!')" + ) + + if not exist "%TEMP%\omnitruck.txt" ( + echo Could not get %CHEF_PRODUCT_NAME% %CHEF_PRODUCT_VER% %CHEF_ARCH% download url... + ) else ( + for /f "tokens=2 usebackq" %%a in (`findstr "url" "%TEMP%\omnitruck.txt"`) do ( + set CHEF_URL=%%a + ) + ) + + if not defined CHEF_URL ( + echo Could not get %CHEF_PRODUCT_NAME% %CHEF_PRODUCT_VER% %CHEF_ARCH% download url... + goto exit1 + ) + echo "==^> Got %CHEF_PRODUCT_NAME% download URL: !CHEF_URL!" ) for %%i in ("%CHEF_URL%") do set CHEF_MSI=%%~nxi @@ -42,12 +94,12 @@ pushd "%CHEF_DIR%" if exist "%SystemRoot%\_download.cmd" ( call "%SystemRoot%\_download.cmd" "%CHEF_URL%" "%CHEF_PATH%" ) else ( - echo ==^> Downloading %CHEF_URL% to %CHEF_PATH% + echo ==^> Downloading %CHEF_PRODUCT_NAME% to %CHEF_PATH% powershell -Command "(New-Object System.Net.WebClient).DownloadFile(\"%CHEF_URL%\", '%CHEF_PATH%')" Installing Chef client %CM_VERSION% +echo ==^> Installing %CHEF_PRODUCT_NAME% %CHEF_PRODUCT_VER% %CHEF_ARCH% msiexec /qb /i "%CHEF_PATH%" /l*v "%CHEF_DIR%\chef.log" %CHEF_OPTIONS% @if errorlevel 1 echo ==^> WARNING: Error %ERRORLEVEL% was returned by: msiexec /qb /i "%CHEF_PATH%" /l*v "%CHEF_DIR%\chef.log" %CHEF_OPTIONS% @@ -55,45 +107,6 @@ ver>nul goto exit0 -:::::::::::: -:chefdk -:::::::::::: - -if not defined CHEFDK_URL if "%CM_VERSION%" == "latest" set CM_VERSION=2.3.4 -if not defined CHEFDK_URL set CHEFDK_64_URL=https://packages.chef.io/files/stable/chefdk/%CM_VERSION%/windows/2008r2/chefdk-%CM_VERSION%-1-x86.msi -if not defined CHEFDK_URL set CHEFDK_32_URL=https://packages.chef.io/files/stable/chefdk/%CM_VERSION%/windows/2008r2/chefdk-%CM_VERSION%-1-x86.msi - -if defined ProgramFiles(x86) ( - SET CHEFDK_URL=%CHEFDK_64_URL% -) else ( - SET CHEFDK_URL=%CHEFDK_32_URL% -) - -for %%i in ("%CHEFDK_URL%") do set CHEFDK_MSI=%%~nxi -set CHEFDK_DIR=%TEMP%\chefdk -set CHEFDK_PATH=%CHEFDK_DIR%\%CHEFDK_MSI% - -echo ==^> Creating "%CHEFDK_DIR%" -mkdir "%CHEFDK_DIR%" -pushd "%CHEFDK_DIR%" - -echo ==^> Downloading Chef DK to %CHEFDK_PATH% -if exist "%SystemRoot%\_download.cmd" ( - call "%SystemRoot%\_download.cmd" "%CHEFDK_URL%" "%CHEFDK_PATH%" -) else ( - echo ==^> Downloading %CHEFDK_URL% to %CHEFDK_PATH% - powershell -Command "(New-Object System.Net.WebClient).DownloadFile(\"%CHEFDK_URL%\", '%CHEFDK_PATH%')" Installing Chef Development Kit %CM_VERSION% -msiexec /qb /i "%CHEFDK_PATH%" /l*v "%CHEFDK_DIR%\chef.log" %CHEFDK_OPTIONS% - -@if errorlevel 1 echo ==^> WARNING: Error %ERRORLEVEL% was returned by: msiexec /qb /i "%CHEFDK_PATH%" /l*v "%CHEFDK_DIR%\chef.log" %CHEFDK_OPTIONS% -ver>nul - -goto exit0 - :::::::::::: :puppet :::::::::::: From 1d2e30a9f8fdce95602f1fff4770382a2dce710e Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Mon, 6 Jan 2020 01:47:51 -0600 Subject: [PATCH 5/7] Cleaning up PR #180 so that it only affects the chef provisioner. Revert "Applied changes in .gitignore from daxgames/boxcutter_windows@357a5db532d904169c86bd4ee5d34eba92ccd9a6 for updating the Chef provisioner." This reverts commit b9c1098657f4911e030caa9b86879d16a877277a. --- .gitignore | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.gitignore b/.gitignore index 468d08c6..d2d54406 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,3 @@ Makefile.local rspec_html_reports .DS_Store - -*.*.json -floppy/*.*.* -script/*.*.* From 70a20492a499a0a46d103212a3aba2afe4870fc5 Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Mon, 6 Jan 2020 02:38:38 -0600 Subject: [PATCH 6/7] Split up the Chef logic from the logic that uses Omnitruck to determine the URL. --- script/cmtool.bat | 103 +++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/script/cmtool.bat b/script/cmtool.bat index 4c9fff72..4e267208 100644 --- a/script/cmtool.bat +++ b/script/cmtool.bat @@ -10,9 +10,9 @@ if "%CM%" == "nocm" goto nocm if not defined CM_VERSION echo ==^> ERROR: The "CM_VERSION" variable was not found in the environment & set CM_VERSION=latest -if "%CM%" == "chef" goto chef -if "%CM%" == "chefdk" goto chef -if "%CM%" == "chef-workstation" goto chef +if "%CM%" == "chef" goto omnitruck +if "%CM%" == "chefdk" goto omnitruck +if "%CM%" == "chef-workstation" goto omnitruck if "%CM%" == "puppet" goto puppet if "%CM%" == "salt" goto salt @@ -21,67 +21,66 @@ echo ==^> ERROR: Unknown value for environment variable CM: "%CM%" goto exit1 :::::::::::: -:chef +:omnitruck :::::::::::: + +:: If we already have the CHEF_URL, then we don't need to use Omnitruck and we can move on +if defined CHEF_URL goto chef + +:: Determine each component for using the Omnitruck API to get the desired Chef component +if not defined OMNITRUCK_CHANNEL set OMNITRUCK_CHANNEL=stable + +:: Figure out the Omnitruck product if "%CM%" == "chef" ( - set "CHEF_PRODUCT_NAME=Chef Client" + set "OMNITRUCK_PRODUCT=chef" ) else if "%CM%" == "chefdk" ( - set "CHEF_PRODUCT_NAME=Chef DK" + set "OMNITRUCK_PRODUCT=chefdk" ) else if "%CM%" == "chef-workstation" ( - set "CHEF_PRODUCT_NAME=Chef Workstation" + set "OMNITRUCK_PRODUCT=chef-workstation" +) else ( + echo Unknown Chef Product: %CM% + goto exit1 ) -set CHEF_PRODUCT_VER=%CM_VERSION% +:: Deterine the other desired parameters here +if not defined OMNITRUCK_PLATFORM set OMNITRUCK_PLATFORM=windows +if not defined OMNITRUCK_MACHINE_ARCH set OMNITRUCK_MACHINE_ARCH=%PROCESSOR_ARCHITECTURE% +if not defined OMNITRUCK_VERSION set OMNITRUCK_VERSION=%CM_VERSION% -if not defined CHEF_URL if "%CHEF_PRODUCT_VER%" == "latest" ( - if "%CM%" == "chef-workstation" ( - set CHEF_PRODUCT_VER=0.2.48 - ) else if "%CM%" == "chefdk" ( - set CHEF_PRODUCT_VER=2.3.4 - ) else if "%CM%" == "chef" ( - set CHEF_PRODUCT_VER=13.6.4 - ) -) +:: We exclude the platform version as the Omnitruck API doesn't seem to use this +:: set OMNITRUCK_PLATFORM_VERSION= + +:: strip -1 if %OMNITRUCK_VERSION% ends in -1 +set OMNITRUCK_VERSION=%OMNITRUCK_VERSION:-1=% -:: strip -1 if %CHEF_PRODUCT_VER% ends in -1 -set CHEF_PRODUCT_VER=%CHEF_PRODUCT_VER:-1=% +:: Use the Omnitruck API to determine the CHEF_URL +echo ==^> Getting %OMNITRUCK_PRODUCT% %OMNITRUCK_VERSION% %OMNITRUCK_MACHINE_ARCH% download URL +set url="https://omnitruck.chef.io/%OMNITRUCK_CHANNEL%/%OMNITRUCK_PRODUCT%/metadata?p=%OMNITRUCK_PLATFORM%&m=%OMNITRUCK_MACHINE_ARCH%&v=%OMNITRUCK_VERSION%" +set filename="%TEMP%\omnitruck.txt" + +echo "==^> Using Chef Omnitruck API URL: !url!" +powershell -command "(New-Object System.Net.WebClient).DownloadFile('!url!', '!filename!')" + +if not exist "%TEMP%\omnitruck.txt" ( + echo Unable to download metadata for %OMNITRUCK_PRODUCT% %OMNITRUCK_VERSION% on the %OMNITRUCK_CHANNEL% channel for %OMNITRUCK_PLATFORM% %OMNITRUCK_MACHINE_ARCH% -if "%PROCESSOR_ARCHITECTURE%" == "x86" ( - set CHEF_ARCH=x86 ) else ( - set CHEF_ARCH=x64 + for /f "tokens=2 usebackq" %%a in (`findstr "url" "%TEMP%\omnitruck.txt"`) do ( + set CHEF_URL=%%a + ) ) if not defined CHEF_URL ( - echo ==^> Getting %CHEF_PRODUCT_NAME% %CHEF_PRODUCT_VER% %CHEF_ARCH% download URL - set url="https://omnitruck.chef.io/stable/%CM%/metadata?p=windows&pv=2012r2&m=%CHEF_ARCH%&v=%CHEF_PRODUCT_VER%" - set filename="%TEMP%\omnitruck.txt" - - echo "==^> Using Chef Omitruck API URL: !url!" - if defined http_proxy ( - if defined no_proxy ( - powershell -Command "$wc = (New-Object System.Net.WebClient); $wc.proxy = (new-object System.Net.WebProxy('%http_proxy%')) ; $wc.proxy.BypassList = (('%no_proxy%').split(',')) ; $wc.DownloadFile('!url!', '!filename!')" - ) else ( - powershell -Command "$wc = (New-Object System.Net.WebClient); $wc.proxy = (new-object System.Net.WebProxy('%http_proxy%')) ; $wc.DownloadFile('!url!', '!filename!')" - ) - ) else ( - powershell -command "(New-Object System.Net.WebClient).DownloadFile('!url!', '!filename!')" - ) - - if not exist "%TEMP%\omnitruck.txt" ( - echo Could not get %CHEF_PRODUCT_NAME% %CHEF_PRODUCT_VER% %CHEF_ARCH% download url... - ) else ( - for /f "tokens=2 usebackq" %%a in (`findstr "url" "%TEMP%\omnitruck.txt"`) do ( - set CHEF_URL=%%a - ) - ) - - if not defined CHEF_URL ( - echo Could not get %CHEF_PRODUCT_NAME% %CHEF_PRODUCT_VER% %CHEF_ARCH% download url... - goto exit1 - ) - echo "==^> Got %CHEF_PRODUCT_NAME% download URL: !CHEF_URL!" + echo Could not determine the %OMNITRUCK_PRODUCT% %OMNITRUCK_VERSION% download url... + goto exit1 ) +echo "==^> Got %OMNITRUCK_PRODUCT% download URL: !CHEF_URL!" + +goto chef + +:::::::::::: +:chef +:::::::::::: for %%i in ("%CHEF_URL%") do set CHEF_MSI=%%~nxi set CHEF_DIR=%TEMP%\chef @@ -94,12 +93,12 @@ pushd "%CHEF_DIR%" if exist "%SystemRoot%\_download.cmd" ( call "%SystemRoot%\_download.cmd" "%CHEF_URL%" "%CHEF_PATH%" ) else ( - echo ==^> Downloading %CHEF_PRODUCT_NAME% to %CHEF_PATH% + echo ==^> Downloading %CHEF_URL% to %CHEF_PATH% powershell -Command "(New-Object System.Net.WebClient).DownloadFile(\"%CHEF_URL%\", '%CHEF_PATH%')" Installing %CHEF_PRODUCT_NAME% %CHEF_PRODUCT_VER% %CHEF_ARCH% +echo ==^> Installing %CM% %CM_VERSION% msiexec /qb /i "%CHEF_PATH%" /l*v "%CHEF_DIR%\chef.log" %CHEF_OPTIONS% @if errorlevel 1 echo ==^> WARNING: Error %ERRORLEVEL% was returned by: msiexec /qb /i "%CHEF_PATH%" /l*v "%CHEF_DIR%\chef.log" %CHEF_OPTIONS% From 3ee90c2db098fa6e2a65c1d08ee3a2adaafb51e9 Mon Sep 17 00:00:00 2001 From: Ali Rizvi-Santiago Date: Mon, 6 Jan 2020 03:07:21 -0600 Subject: [PATCH 7/7] Apparently one can't be lazy with Chef's Omnitruck API..Fixed script/cmtool.bat to explicitly specify a lowercase OMNITRUCK_MACHINE_ARCH. --- script/cmtool.bat | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/script/cmtool.bat b/script/cmtool.bat index 4e267208..6886ed74 100644 --- a/script/cmtool.bat +++ b/script/cmtool.bat @@ -44,9 +44,16 @@ if "%CM%" == "chef" ( :: Deterine the other desired parameters here if not defined OMNITRUCK_PLATFORM set OMNITRUCK_PLATFORM=windows -if not defined OMNITRUCK_MACHINE_ARCH set OMNITRUCK_MACHINE_ARCH=%PROCESSOR_ARCHITECTURE% if not defined OMNITRUCK_VERSION set OMNITRUCK_VERSION=%CM_VERSION% +if not defined OMNITRUCK_MACHINE_ARCH ( + if "%PROCESSOR_ARCHITECTURE%" == "x86" ( + set OMNITRUCK_MACHINE_ARCH=x86 + ) else ( + set OMNITRUCK_MACHINE_ARCH=x64 + ) +) + :: We exclude the platform version as the Omnitruck API doesn't seem to use this :: set OMNITRUCK_PLATFORM_VERSION=