From 357a5db532d904169c86bd4ee5d34eba92ccd9a6 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sat, 23 Mar 2019 03:54:21 -0400 Subject: [PATCH] add chef-wokstation, use omnitruck, reduce code duplication cleanup ignore *.*.* ignore *.*.* cleanup README.md cleanup cleanup cleanup cleanup add chef workstation fixes --- .gitignore | 4 ++ Makefile | 2 +- README.md | 4 +- script/cmtool.bat | 123 +++++++++++++++++++++++++--------------------- 4 files changed, 76 insertions(+), 57 deletions(-) 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/*.*.* diff --git a/Makefile b/Makefile index fc505b67..2f7b9aeb 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 ?= diff --git a/README.md b/README.md index c43c5f05..6e2cf94f 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 diff --git a/script/cmtool.bat b/script/cmtool.bat index 6b15068d..d9934664 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=%USERPROFILE%\AppData\Local\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-cm +if "%CM%" == "chefdk" goto chef-cm +if "%CM%" == "chef-workstation" goto chef-cm if "%CM%" == "puppet" goto puppet if "%CM%" == "salt" goto salt @@ -18,36 +21,86 @@ echo ==^> ERROR: Unknown value for environment variable CM: "%CM%" goto exit1 :::::::::::: -:chef +:chef-cm :::::::::::: +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_KEY=%CM% +set CHEF_PRODUCT_VER=%CM_VERSION% + +if not defined CHEF_URL if "%CHEF_PRODUCT_VER%" == "latest" ( + if "%CHEF_PRODUCT_KEY%" == "chef-workstation" ( + set CHEF_PRODUCT_VER=0.2.48 + ) else if "%CHEF_PRODUCT_KEY%" == "chefdk" ( + set CHEF_PRODUCT_VER=2.3.4 + ) else if "%CHEF_PRODUCT_KEY%" == "chef" ( + set CHEF_PRODUCT_VER=13.6.4 + ) +) -if defined ProgramFiles(x86) ( - SET CHEF_URL=%CHEF_64_URL% +:: srtrip -1 if %CHEF_PRODUCT_VER% ends in -1 +set CHEF_PRODUCT_VER=%CHEF_PRODUCT_VER:-1=% + +if defined ProgramFiles^(x86^) ( + set WINDOWS_ARCH=x64 ) else ( - SET CHEF_URL=%CHEF_32_URL% + set WINDOWS_ARCH=x86 +) + +if not defined CHEF_URL ( + echo ==^> Getting %CHEF_PRODUCT_NAME% %CHEF_PRODUCT_VER% %WINDOWS_ARCH% download URL + set url="https://omnitruck.chef.io/stable/%CHEF_PRODUCT_KEY%/metadata?p=windows&pv=2012r2&m=%WINDOWS_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% %WINDOWS_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% %WINDOWS_ARCH% download url... + goto exit1 + ) + echo "==^> Got %CHEF_PRODUCT_NAME% download URL: !CHEF_URL!" ) for %%i in ("%CHEF_URL%") do set CHEF_MSI=%%~nxi -set CHEF_DIR=%TEMP%\chef +set CHEF_DIR=%TEMP%\%CHEF_PRODUCT_KEY% set CHEF_PATH=%CHEF_DIR%\%CHEF_MSI% echo ==^> Creating "%CHEF_DIR%" mkdir "%CHEF_DIR%" pushd "%CHEF_DIR%" +echo ==^> Downloading %CHEF_PRODUCT_NAME% to %CHEF_PATH% if exist "%SystemRoot%\_download.cmd" ( call "%SystemRoot%\_download.cmd" "%CHEF_URL%" "%CHEF_PATH%" ) else ( - echo ==^> Downloading %CHEF_URL% 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% %WINDOWS_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 +108,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 :::::::::::: @@ -122,7 +136,7 @@ if exist "%SystemRoot%\_download.cmd" ( call "%SystemRoot%\_download.cmd" "%PUPPET_URL%" "%PUPPET_PATH%" ) else ( echo ==^> Downloading %PUPPET_URL% to %PUPPET_PATH% - powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%PUPPET_URL%', '%PUPPET_PATH%')" Downloading %SALT_URL% to %SALT_PATH% - powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%SALT_URL%', '%SALT_PATH%')"