Skip to content

Commit

Permalink
add chef-wokstation, use omnitruck, reduce code duplication
Browse files Browse the repository at this point in the history
cleanup

ignore *.*.*

ignore *.*.*

cleanup

README.md

cleanup

cleanup

cleanup

cleanup

add chef workstation

fixes
  • Loading branch information
Dax T. Games committed Jan 5, 2020
1 parent f32a0a5 commit 357a5db
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 57 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ Makefile.local
rspec_html_reports

.DS_Store

*.*.json
floppy/*.*.*
script/*.*.*
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
123 changes: 68 additions & 55 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=%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

Expand All @@ -18,82 +21,93 @@ 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%')" <NUL
call _packer_config.cmd ps1_download "%CHEF_URL%" "%CHEF_PATH%"
)
if not exist "%CHEF_PATH%" goto exit1

echo ==^> 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%
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 Expand Up @@ -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%')" <NUL
call _packer_config.cmd ps1_download "%PUPPET_URL%" "%PUPPET_PATH%"
)
if not exist "%PUPPET_PATH%" goto exit1

Expand Down Expand Up @@ -161,8 +175,7 @@ pushd "%SALT_DIR%"
if exist "%SystemRoot%\_download.cmd" (
call "%SystemRoot%\_download.cmd" "%SALT_URL%" "%SALT_PATH%"
) else (
echo ==^> Downloading %SALT_URL% to %SALT_PATH%
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%SALT_URL%', '%SALT_PATH%')" <NUL
call _packer_config.cmd ps1_download "%SALT_URL%" "%SALT_PATH%"
)
if not exist "%SALT_PATH%" goto exit1

Expand Down

0 comments on commit 357a5db

Please sign in to comment.