diff --git a/README.md b/README.md index 86751a7c..d3c0866b 100644 --- a/README.md +++ b/README.md @@ -77,16 +77,21 @@ Possible values for the CM variable are: * `puppet` - Install Puppet * `salt` - Install Salt -You can also specify a variable `CM_VERSION`, if supported by the -configuration management tool, to override the default of `latest`. -The value of `CM_VERSION` should have the form `x.y` or `x.y.z`, -such as `CM_VERSION := 11.12.4` +You can also specify a variable `CM_VERSION` for all configuration management +tools to override the default of `latest`. The value of `CM_VERSION` should +have the form `x.y` or `x.y.z`, such as `CM_VERSION := 11.12.4` It is also possible to specify a `HW_VERSION` if a specific hardware version is to be used for build. This is commonly used to provide compatibility with newer versions of VMware Workstation. For example, you may indicate version 14 of Workstation: `HW_VERSION := 14`. +For configuration management tools (such as Salt), you can specify a +variable `CM_OPTIONS`. This variable will be passed to the installer for +the configuration management tool. For information on possible values +please read the documentation for the respective configuration management +tool. + Another use for `Makefile.local` is to override the default locations for the Windows install ISO files. diff --git a/script/cmtool.bat b/script/cmtool.bat index 182a91d5..242e3361 100644 --- a/script/cmtool.bat +++ b/script/cmtool.bat @@ -2,13 +2,30 @@ @for %%i in (a:\_packer_config*.cmd) do @call "%%~i" @if defined PACKER_DEBUG (@echo on) else (@echo off) +:: Get the PlatformVersion from SystemInfo +for /f "delims=:; tokens=1,2" %%a in ('systeminfo') do ( + if "%%a" == "OS Version" set PlatformVersionRow=%%b +) + +:: Extract the major/minor version (stripped) +for /f "delims=.; tokens=1,2" %%a in ("%PlatformVersionRow%") do ( + for /f "tokens=*" %%v in ("%%a") do set PlatformVersionMajor=%%v + for /f "tokens=*" %%v in ("%%b") do set PlatformVersionMinor=%%v +) + +echo ==^> Detected Windows Platform Version: %PlatformVersionMajor%.%PlatformVersionMinor% + +:: Set some reasonable defaults if not defined TEMP set TEMP=%LOCALAPPDATA%\Temp +:: Figure out which configuration management tool to use 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 not defined CM_VERSION ( + echo ==^> ERROR: The "CM_VERSION" variable was not found in the environment + set CM_VERSION=latest +) if "%CM%" == "chef" goto omnitruck if "%CM%" == "chefdk" goto omnitruck @@ -160,36 +177,76 @@ goto exit0 :salt :::::::::::: if not defined SALT_OPTIONS set SALT_OPTIONS=%CM_OPTIONS% +if not defined SALT_REVISION set SALT_REVISION=stable + +set SALT_DIR=%TEMP%\salt +echo ==^> Creating "%SALT_DIR%" +mkdir "%SALT_DIR%" +pushd "%SALT_DIR%" -if "%CM_VERSION%" == "latest" set CM_VERSION=2015.8.8-2 +:: If we're on a platform where salt-bootstrap is buggy, then fall back to just +:: using the regular salt-repository method. +if "%PlatformVersionMajor%" == "6" if "%PlatformVersionMinor%" == "0" goto saltrepository +if "%PlatformVersionMajor%" == "6" if "%PlatformVersionMinor%" == "1" goto saltrepository -if not defined SALT_64_URL set SALT_64_URL=https://repo.saltstack.com/windows/Salt-Minion-%CM_VERSION%-AMD64-Setup.exe -if not defined SALT_32_URL set SALT_32_URL=https://repo.saltstack.com/windows/Salt-Minion-%CM_VERSION%-x86-Setup.exe +:::::::::::: +:saltbootstrap +:::::::::::: -if defined ProgramFiles(x86) ( - set SALT_URL=%SALT_64_URL% +:: We hardcode the CM_VERSION here to workaround saltstack/salt-bootstrap#1394 +if "%CM_VERSION%" == "latest" set CM_VERSION=2019.2.2 + +set SALT_URL=http://raw.githubusercontent.com/saltstack/salt-bootstrap/%SALT_REVISION%/bootstrap-salt.ps1 + +set SALT_PATH=%SALT_DIR%\bootstrap-salt.ps1 +set SALT_DOWNLOAD=%SALT_DIR%\bootstrap-salt.download.ps1 + +echo ==^> Downloading %SALT_URL% to %SALT_DOWNLOAD% +powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%SALT_URL%', '%SALT_DOWNLOAD%')" Patching bootstrap-salt.ps1 at %SALT_DOWNLOAD% +powershell -command "(get-content \"%SALT_DOWNLOAD%\") -replace \"'Tls,Tls11,Tls12'\", \"0xc0,0x300,0xc00\" | set-content \"%SALT_PATH%\"" + +echo ==^> Installing Salt minion with %SALT_PATH% +if "%CM_VERSION%" == "latest" ( + powershell "%SALT_PATH%" %SALT_OPTIONS% ) else ( - set SALT_URL=%SALT_32_URL% + powershell "%SALT_PATH%" -version "%CM_VERSION%" %SALT_OPTIONS% ) -for %%i in ("%SALT_URL%") do set SALT_EXE=%%~nxi -set SALT_DIR=%TEMP%\salt -set SALT_PATH=%SALT_DIR%\%SALT_EXE% +@if errorlevel 1 echo ==^> WARNING: Error %ERRORLEVEL% was returned by: "%SALT_PATH%" -version "%CM_VERSION%" %SALT_OPTIONS% +ver>nul -echo ==^> Creating "%SALT_DIR%" -mkdir "%SALT_DIR%" -pushd "%SALT_DIR%" +goto exit0 -if exist "%SystemRoot%\_download.cmd" ( - call "%SystemRoot%\_download.cmd" "%SALT_URL%" "%SALT_PATH%" +:::::::::::: +:saltrepository +:::::::::::: + +if not defined SALT_PYTHONVERSION set SALT_PYTHONVERSION=Py3 + +if not defined SALT_ARCH ( + if "%PROCESSOR_ARCHITECTURE%" == "x86" ( + set SALT_ARCH=x86 + ) else ( + set SALT_ARCH=AMD64 + ) +) + +if "%CM_VERSION%" == "latest" ( + set SALT_URL=http://repo.saltstack.com/windows/Salt-Minion-Latest-%SALT_PYTHONVERSION%-%SALT_ARCH%-Setup.exe ) else ( - echo ==^> Downloading %SALT_URL% to %SALT_PATH% - powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%SALT_URL%', '%SALT_PATH%')" Installing Salt minion -:: see http://docs.saltstack.com/en/latest/topics/installation/windows.html +set SALT_PATH=%SALT_DIR%\Salt-Minion-Setup.exe + +echo ==^> Downloading %SALT_URL% to %SALT_PATH% +powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%SALT_URL%', '%SALT_PATH%')" Installing Salt minion %CM_VERSION%-%SALT_PYTHONVERSION% with %SALT_PATH% + "%SALT_PATH%" /S %SALT_OPTIONS% @if errorlevel 1 echo ==^> WARNING: Error %ERRORLEVEL% was returned by: "%SALT_PATH%" /S %SALT_OPTIONS%