Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy support for Initial install and shell provisioners #229

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ floppy/_packer_config_*.cmd
*.*.json
floppy/*.*.*
script/*.*.*

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stray new-line is unnecessary.

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This newline is also unnecessary.

# Packer templates for Windows

### Overview
Expand Down Expand Up @@ -146,6 +147,19 @@ You can add additional `floppy/_packer_config_*.cmd` files. These files will be

`floppy/_packer_config*.cmd` will be executed in alpabetical order during initial install and at the beginning of each shell provisioner script if the script supports loading them.

#### Proxy Configuration using `floppy/_packer_config_proxy.cmd`

Create a file called `floppy/_packer_config_proxy.cmd` with the below contents:

```
set http_proxy_user=[proxy_user]
set http_proxy_password=[proxy_password]
set ftp_proxy=http://[proxy_host]:[proxy_port]
set http_proxy=http://[proxy_host]:[proxy_port]
set https_proxy=http://[proxy_host]:[proxy_port]
set no_proxy=127.0.0.1,localhost,[no_proxy_hosts]
```

### Acknowledgments

[Parallels](http://www.parallels.com/) provides a Business Edition license of
Expand Down
12 changes: 0 additions & 12 deletions floppy/01-install-wget.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,12 @@ if not defined WGET_URL set WGET_URL=https://eternallybored.org/misc/wget/curren

for %%i in ("%WGET_URL%") do set filename=%SystemRoot%\%%~nxi

if not exist "%~dp0\_download.cmd" goto _download_cmd_not_found

copy /y "%~dp0\_download.cmd" "%SystemRoot%\"

call "%~dp0\_download.cmd" "%WGET_URL%" "%filename%"

if exist "%filename%" goto exit0

:_download_cmd_not_found

echo ==^> Downloading "%WGET_URL%" to "%filename%"

:powershell

powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%WGET_URL%', '%filename%')" <NUL

if exist "%filename%" goto exit0

if defined DISABLE_BITS (
if "%DISABLE_BITS%" == "1" if not exist "%filename%" goto exit1
)
Expand Down
36 changes: 30 additions & 6 deletions floppy/_download.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

if not defined PACKER_SEARCH_PATHS set PACKER_SEARCH_PATHS="%USERPROFILE%" a: b: c: d: e: f: g: h: i: j: k: l: m: n: o: p: q: r: s: t: u: v: w: x: y: z:

set url=%~1
set "url=%~1"

set filename=%~2
set "filename=%~2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for properly quoting these. It's good style.


if not defined url echo ==^> ERROR: _download.cmd called without URL parameter. & goto exit1

Expand All @@ -31,8 +31,8 @@ echo ==^> Copying "%found%" to "%filename%", skipping download.
copy /y "%found%" "%filename%" && goto exit0

:download

echo ==^> Downloading "%url%" to "%filename%"
REM IT IS JUST CLEANER WITH THIS WGET IS REALLY PICKY. POWERSHELL - NOT SO MUCH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to justify this with a comment.. Can be removed as well.

if defined http_proxy goto powershell

set wget=

Expand All @@ -46,15 +46,37 @@ if defined wget goto wget

if not exist "%wget%" goto powershell

echo ==^> Downloading "%url%" to "%filename%" using "%wget%"...

if not defined PACKER_DEBUG set WGET_OPTS=--no-verbose

if defined http_proxy (
if defined http_proxy_user if defined http_proxy_password (
set WGET_OPTS=%WGET_OPTS% --proxy-user='%http_proxy_user%' --proxy-passwd='%http_proxy_password%'
)
)

"%wget%" --no-check-certificate %WGET_OPTS% -O "%filename%" "%url%"

if not errorlevel 1 if exist "%filename%" goto exit0

:powershell
echo ==^> Downloading "%url%" to "%filename%" using "Powershell"...

powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%url%', '%filename%')" <NUL
if defined http_proxy (
set "ps1_proxy=$wc.proxy = (new-object System.Net.WebProxy('%http_proxy%')) ;"
if defined http_proxy_user if defined http_proxy_password (
set "ps1_proxy_auth=$wc.proxy.Credentials = (New-Object System.Net.NetworkCredential('%http_proxy_user%', '%http_proxy_password%')) ;"
)

if defined no_proxy (
set "ps1_no_proxy=$wc.proxy.BypassList = (('%no_proxy%').split(',')) ;"
)
)

set ps1_script="$wc = (New-Object System.Net.WebClient) ; %ps1_proxy% %ps1_proxy_auth% %ps1_no_proxy% $wc.DownloadFile('%url%', '%filename%')"

powershell -command %ps1_script% >nul

if not errorlevel 1 if exist "%filename%" goto exit0

Expand All @@ -70,7 +92,9 @@ for %%i in (bitsadmin.exe) do set bitsadmin=%%~$PATH:i

if not defined bitsadmin set bitsadmin=%SystemRoot%\System32\bitsadmin.exe

if not exist "%bitsadmin%" goto powershell
if not exist "%bitsadmin%" goto exit 1

echo ==^> Downloading "%url%" to "%filename%" using "BITS"...

for %%i in ("%filename%") do set jobname=%%~nxi

Expand Down
3 changes: 0 additions & 3 deletions floppy/bitvisessh.bat
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ pushd "%BITVISE_DIR%"

if exist "%SystemRoot%\_download.cmd" (
call "%SystemRoot%\_download.cmd" "%BITVISE_URL%" "%BITVISE_PATH%"
) else (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These conditionals are used to detect if there's some kind of issue with the existence of the download script. If you're going to remove the "else" case, you might as well remove the whole conditional.

Ideally, though, you could emit an error and terminate the script if the download.cmd script is not found. However, either way is fine.

echo ==^> Downloading "%BITVISE_URL%" to "%BITVISE_PATH%"
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%BITVISE_URL%', '%BITVISE_PATH%')" <NUL
)
if not exist "%BITVISE_PATH%" goto exit1

Expand Down
3 changes: 0 additions & 3 deletions floppy/cygwin.bat
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ pushd "%CYGWIN_DIR%"

if exist "%SystemRoot%\_download.cmd" (
call "%SystemRoot%\_download.cmd" "%CYGWIN_URL%" "%CYGWIN_PATH%"
) else (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(See comment for floppy/bitvisessh.bat)

echo ==^> Downloading "%CYGWIN_URL%" to "%CYGWIN_PATH%"
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%CYGWIN_URL%', '%CYGWIN_PATH%')" <NUL
)
if errorlevel 1 goto exit1

Expand Down
3 changes: 0 additions & 3 deletions floppy/hotfix-KB2842230.bat
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ pushd "%HOTFIX_2842230_DIR%"

if exist "%SystemRoot%\_download.cmd" (
call "%SystemRoot%\_download.cmd" "%HOTFIX_2842230_URL%" "%HOTFIX_2842230_PATH%"
) else (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(See comment for floppy/bitvisessh.bat)

echo ==^> Downloading "%HOTFIX_2842230_URL%" to "%HOTFIX_2842230_PATH%"
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%HOTFIX_2842230_URL%', '%HOTFIX_2842230_PATH%')" <NUL
)
if errorlevel 1 goto exit1

Expand Down
3 changes: 0 additions & 3 deletions floppy/openssh.bat
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ pushd "%OPENSSH_DIR%"

if exist "%SystemRoot%\_download.cmd" (
call "%SystemRoot%\_download.cmd" "%OPENSSH_URL%" "%OPENSSH_PATH%"
) else (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(See comment for floppy/bitvisessh.bat)

echo ==^> Downloading "%OPENSSH_URL%" to "%OPENSSH_PATH%"
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%OPENSSH_URL%', '%OPENSSH_PATH%')" <NUL
)
if not exist "%OPENSSH_PATH%" goto exit1

Expand Down
3 changes: 0 additions & 3 deletions floppy/upgrade-wua.bat
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ mkdir "%WUA_DIR%"

if exist "%SystemRoot%\_download.cmd" (
call "%SystemRoot%\_download.cmd" "%WUA_URL%" "%WUA_PATH%"
) else (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(See comment for floppy/bitvisessh.bat)

echo ==^> Downloading "%WUA_URL%" to "%WUA_PATH%"
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%WUA_URL%', '%WUA_PATH%')" <NUL
)
if not exist "%WUA_PATH%" goto exit1

Expand Down
3 changes: 0 additions & 3 deletions script/01-install-handle.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ pushd "%HANDLE_DIR%"

if exist "%SystemRoot%\_download.cmd" (
call "%SystemRoot%\_download.cmd" "%HANDLE_URL%" "%HANDLE_PATH%"
) else (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(See comment for floppy/bitvisessh.bat)

echo ==^> Downloading "%HANDLE_URL%" to "%HANDLE_PATH%"
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%HANDLE_URL%', '%HANDLE_PATH%')" <NUL
)
if not exist "%HANDLE_PATH%" goto exit1

Expand Down
15 changes: 5 additions & 10 deletions script/cmtool.bat
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ set url="https://omnitruck.chef.io/%OMNITRUCK_CHANNEL%/%OMNITRUCK_PRODUCT%/metad
set filename="%TEMP%\omnitruck.txt"

echo ==^> Using Chef Omnitruck API URL: !url!
powershell -command "(New-Object System.Net.WebClient).DownloadFile('!url!', '!filename!')"
call "%SystemRoot%\_download.cmd" !url! !filename!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per my comment for floppy/bitvisessh.bat, it's likely better that we check for the existence of _download.cmd at the top of the script and emit the error there if you chose to not do them in the conditional.


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%
Expand Down Expand Up @@ -136,9 +136,6 @@ pushd "%CHEF_DIR%"

if exist "%SystemRoot%\_download.cmd" (
call "%SystemRoot%\_download.cmd" "%CHEF_URL%" "%CHEF_PATH%"
) else (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(See prior comment)

echo ==^> Downloading %CHEF_URL% to %CHEF_PATH%
powershell -Command "(New-Object System.Net.WebClient).DownloadFile(\"%CHEF_URL%\", '%CHEF_PATH%')" <NUL
)
if not exist "%CHEF_PATH%" goto exit1

Expand Down Expand Up @@ -215,9 +212,6 @@ pushd "%PUPPET_DIR%"
:: todo support CM_VERSION variable
if exist "%SystemRoot%\_download.cmd" (
call "%SystemRoot%\_download.cmd" "%PUPPET_URL%" "%PUPPET_PATH%"
) else (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(See prior comment)

echo ==^> Downloading %PUPPET_URL% to %PUPPET_PATH%
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%PUPPET_URL%', '%PUPPET_PATH%')" <NUL
)
if not exist "%PUPPET_PATH%" goto exit1

Expand Down Expand Up @@ -259,8 +253,9 @@ set SALT_URL=http://raw.githubusercontent.com/saltstack/salt-bootstrap/%SALT_REV
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%')" <NUL
if exist "%SystemRoot%\_download.cmd" (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(See prior comment)

call "%SystemRoot%\_download.cmd" "%SALT_URL%" "%SALT_DOWNLOAD%"
)

if not exist "%SALT_DOWNLOAD%" goto exit1
echo ==^> Patching bootstrap-salt.ps1 at %SALT_DOWNLOAD%
Expand Down Expand Up @@ -301,7 +296,7 @@ if "%CM_VERSION%" == "latest" (
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%')" <NUL
call "%SystemRoot%\_download.cmd" %SALT_URL% %SALT_PATH%
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(See prior comment)


echo ==^> Installing Salt minion %CM_VERSION%-%SALT_PYTHONVERSION% with %SALT_PATH%

Expand Down
3 changes: 0 additions & 3 deletions script/sdelete.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ pushd "%SDELETE_DIR%"

if exist "%SystemRoot%\_download.cmd" (
call "%SystemRoot%\_download.cmd" "%SDELETE_URL%" "%SDELETE_PATH%"
) else (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(See comment for floppy/bitvisessh.bat)

echo ==^> Downloading "%SDELETE_URL%" to "%SDELETE_PATH%"
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%SDELETE_URL%', '%SDELETE_PATH%')" <NUL
)
if not exist "%SDELETE_PATH%" goto exit1

Expand Down
6 changes: 0 additions & 6 deletions script/ultradefrag.bat
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ cd /d "%SEVENZIP_DIR%"

if exist "%SystemRoot%\_download.cmd" (
call "%SystemRoot%\_download.cmd" "%SEVENZIP_URL%" "%SEVENZIP_PATH%"
) else (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(See comment for floppy/bitvisessh.bat)

echo ==^> Downloading "%SEVENZIP_URL%" to "%SEVENZIP_PATH%"
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%SEVENZIP_URL%', '%SEVENZIP_PATH%')" <NUL
)
if not exist "%SEVENZIP_PATH%" goto return1

Expand Down Expand Up @@ -131,9 +128,6 @@ pushd "%ULTRADEFRAG_DIR%"

if exist "%SystemRoot%\_download.cmd" (
call "%SystemRoot%\_download.cmd" "%ULTRADEFRAG_URL%" "%ULTRADEFRAG_PATH%"
) else (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(See comment for floppy/bitvisessh.bat)

echo ==^> Downloading "%ULTRADEFRAG_URL%" to "%ULTRADEFRAG_PATH%"
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%ULTRADEFRAG_URL%', '%ULTRADEFRAG_PATH%')" <NUL
)
if not exist "%ULTRADEFRAG_PATH%" goto exit1

Expand Down
3 changes: 0 additions & 3 deletions script/vagrant.bat
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ pushd "%VAGRANT_DIR%"

if exist "%SystemRoot%\_download.cmd" (
call "%SystemRoot%\_download.cmd" "%VAGRANT_PUB_URL%" "%VAGRANT_PATH%"
) else (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(See comment for floppy/bitvisessh.bat)

echo ==^> Downloading "%VAGRANT_PUB_URL%" to "%VAGRANT_PATH%"
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%VAGRANT_PUB_URL%', '%VAGRANT_PATH%')" <NUL
)
if not exist "%VAGRANT_PATH%" goto exit1

Expand Down
23 changes: 5 additions & 18 deletions script/vmtool.bat
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ set SEVENZIP_PATH=%SEVENZIP_DIR%\%SEVENZIP_MSI%
echo ==^> Creating "%SEVENZIP_DIR%"
mkdir "%SEVENZIP_DIR%"
cd /d "%SEVENZIP_DIR%"
if exist "%SystemRoot%\_download.cmd" (
call "%SystemRoot%\_download.cmd" "%SEVENZIP_URL%" "%SEVENZIP_PATH%"
) else (
echo ==^> Downloading "%SEVENZIP_URL%" to "%SEVENZIP_PATH%"
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%SEVENZIP_URL%', '%SEVENZIP_PATH%')" <NUL
)
call "%SystemRoot%\_download.cmd" "%SEVENZIP_URL%" "%SEVENZIP_PATH%"
if not exist "%SEVENZIP_PATH%" goto return1
echo ==^> Installing "%SEVENZIP_PATH%"
msiexec /qb /i "%SEVENZIP_PATH%"
Expand Down Expand Up @@ -126,12 +121,8 @@ if defined VMWARE_TOOLS_ISO_PATH for %%i in (%VMWARE_TOOLS_ISO_PATH%) do set _VM
if %_VMWARE_TOOLS_SIZE% EQU 0 set VMWARE_TOOLS_ISO_PATH=

if defined VMWARE_TOOLS_ISO_PATH goto install_vmware_tools_from_iso
if exist "%SystemRoot%\_download.cmd" (
call "%SystemRoot%\_download.cmd" "%VMWARE_TOOLS_TAR_URL%" "%VMWARE_TOOLS_TAR_PATH%"
) else (
echo ==^> Downloading "%VMWARE_TOOLS_TAR_URL%" to "%VMWARE_TOOLS_TAR_PATH%"
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%VMWARE_TOOLS_TAR_URL%', '%VMWARE_TOOLS_TAR_PATH%')" <NUL
)
call "%SystemRoot%\_download.cmd" "%VMWARE_TOOLS_TAR_URL%" "%VMWARE_TOOLS_TAR_PATH%"

if not exist "%VMWARE_TOOLS_TAR_PATH%" goto exit1
call :install_sevenzip
if errorlevel 1 goto exit1
Expand Down Expand Up @@ -202,12 +193,8 @@ set _VBOX_ISO_SIZE=0
if exist "%VBOX_ISO_PATH%" for %%i in (%VBOX_ISO_PATH%) do set _VBOX_ISO_SIZE=%%~zi
if %_VBOX_ISO_SIZE% GTR 0 goto install_vbox_guest_additions_from_iso

if exist "%SystemRoot%\_download.cmd" (
call "%SystemRoot%\_download.cmd" "%VBOX_ISO_URL%" "%VBOX_ISO_PATH%"
) else (
echo ==^> Downloading "%VBOX_ISO_URL%" to "%VBOX_ISO_PATH%"
powershell -Command "(New-Object System.Net.WebClient).DownloadFile('%VBOX_ISO_URL%', '%VBOX_ISO_PATH%')" <NUL
)
call "%SystemRoot%\_download.cmd" "%VBOX_ISO_URL%" "%VBOX_ISO_PATH%"

if not exist "%VBOX_ISO_PATH%" goto exit1

:install_vbox_guest_additions_from_iso
Expand Down