Skip to content
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?=
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
117 changes: 68 additions & 49 deletions script/cmtool.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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 omnitruck
if "%CM%" == "chefdk" goto omnitruck
if "%CM%" == "chef-workstation" goto omnitruck
if "%CM%" == "puppet" goto puppet
if "%CM%" == "salt" goto salt

Expand All @@ -18,19 +21,74 @@ echo ==^> ERROR: Unknown value for environment variable CM: "%CM%"
goto exit1

::::::::::::
:chef
:omnitruck
::::::::::::

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
:: 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

if defined ProgramFiles(x86) (
SET CHEF_URL=%CHEF_64_URL%
:: 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 "OMNITRUCK_PRODUCT=chef"
) else if "%CM%" == "chefdk" (
set "OMNITRUCK_PRODUCT=chefdk"
) else if "%CM%" == "chef-workstation" (
set "OMNITRUCK_PRODUCT=chef-workstation"
) else (
SET CHEF_URL=%CHEF_32_URL%
echo Unknown Chef Product: %CM%
goto exit1
)

:: Deterine the other desired parameters here
if not defined OMNITRUCK_PLATFORM set OMNITRUCK_PLATFORM=windows
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=

:: strip -1 if %OMNITRUCK_VERSION% ends in -1
set OMNITRUCK_VERSION=%OMNITRUCK_VERSION:-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%

) 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 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
set CHEF_PATH=%CHEF_DIR%\%CHEF_MSI%
Expand All @@ -47,53 +105,14 @@ if exist "%SystemRoot%\_download.cmd" (
)
if not exist "%CHEF_PATH%" goto exit1

echo ==^> Installing Chef client %CM_VERSION%
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%
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%')" <NUL
)
if not exist "%CHEFDK_PATH%" goto exit1

echo ==^> 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
::::::::::::
Expand Down