From c992ae3e218f4e898a8de45e9d18b386392bf524 Mon Sep 17 00:00:00 2001 From: Roger Luethi Date: Sat, 11 Apr 2015 09:16:16 +0200 Subject: [PATCH] labs: Automatically download install ISO in Windows With this patch, the Windows batch scripts attempt to automatically download the install ISO image (this is already the case on Linux, OS X). Change-Id: I080b593f2b627801845f18587521ad64d53b3504 --- labs/lib/wbatch/template-begin_base_bat | 15 ++++++++++++++- labs/wbatch/downloader.js | 12 ++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 labs/wbatch/downloader.js diff --git a/labs/lib/wbatch/template-begin_base_bat b/labs/lib/wbatch/template-begin_base_bat index fda2d0b5..80a09683 100644 --- a/labs/lib/wbatch/template-begin_base_bat +++ b/labs/lib/wbatch/template-begin_base_bat @@ -4,12 +4,25 @@ DEL /S /Q %LOGDIR% ECHO %time% Looking for %IMGDIR%\%INSTALLFILE% IF EXIST %IMGDIR%\%INSTALLFILE% goto got_install_iso + ECHO. ECHO %INSTALLFILE% not found in %IMGDIR%. ECHO. -ECHO To proceed, I need the install ISO from +ECHO Trying to download the install ISO from ECHO %ISOURL% ECHO. +ECHO Expect this to take several minutes or longer, depending on your +ECHO Internet connection. +ECHO. +cscript /nologo downloader.js %ISOURL% +RENAME downloaded.bin %INSTALLFILE% +MOVE %INSTALLFILE% %IMGDIR% +IF EXIST %IMGDIR%\%INSTALLFILE% goto got_install_iso +ECHO. +ECHO %INSTALLFILE% still not found in %IMGDIR%. +ECHO Aborting. +ECHO. + goto :terminate :got_install_iso diff --git a/labs/wbatch/downloader.js b/labs/wbatch/downloader.js new file mode 100644 index 00000000..9e0bbe7b --- /dev/null +++ b/labs/wbatch/downloader.js @@ -0,0 +1,12 @@ +/* Taken from http://superuser.com/a/536400 */ +/* Use: cscript /nologo downloader.js */ + +var WinHttpReq = new ActiveXObject("WinHttp.WinHttpRequest.5.1"); +WinHttpReq.Open("GET", WScript.Arguments(0), /*async=*/false); +WinHttpReq.Send(); + +BinStream = new ActiveXObject("ADODB.Stream"); +BinStream.Type = 1; +BinStream.Open(); +BinStream.Write(WinHttpReq.ResponseBody); +BinStream.SaveToFile("downloaded.bin");