boxcutter / windows

Virtual machine templates for Windows written in legacy JSON and Batch Scripting/JScript
Apache License 2.0
753 stars 266 forks source link

Refactor _download.cmd so that Powershell is tried first before falling back to the other download methods. #239

Closed arizvisa closed 4 years ago

arizvisa commented 4 years ago

This PR tampers with all of the scripts so that they explicitly depend on _download.cmd. Technically they were doing that before, but they'd always fall back to using Powershell when failing which would also fail because _download.cmd was doing the exact same thing. Now we just fail the scripts at their beginning if we're unable to find the cached file and are unable download it.

The _download.cmd script was also refactored to change the order of the downloads that are tried. Now we give powershell priority, fallback to wget.exe, and then try bitsadmin.exe as a last resort. The powershell downloader also requires and sets the minimum security protocol version to Tls 1.2. This is due to the reason that most of tools that we're downloading are now being hosted on a Tls 1.2-only webserver which had broken most of the templates.

This closes issue #238.

arizvisa commented 4 years ago

This seems to work on the following so far. Going to test win7 and then merge it if those work too. eval-win81x86-enterprise.json eval-win81x64-enterprise.json

arizvisa commented 4 years ago

Wow. So it seems that there isn't a way to tell if a BitsAdmin job has failed. If it gets incorrect parameters, a badly formed url, or the download fails, it returns an errorlevel of 0. If you try using /info, /geterror, or /geterrorcount. Regardless if it was successful or not, the job is done and doesn't exist anymore...so it always fails.

I thought maybe because /geterror displays a number, we could parse the command output if we could silence it. I tried but I couldn't figure out how to disable its logo to parse it. It seems like we could use findstring to filter its output and then parse it like that, but spinning in a loop and It seems I couldn't figure out how to disable its logo to parse it.

arizvisa commented 4 years ago

Seems like on the eval-win7x64-enterprise.json template, 7-zip can't be installed due to error code 1620. Looking more into what this error is actually based on....

arizvisa commented 4 years ago

Turns out that this error was due to the 7-zip url being a redirect and it being downloaded instead of redirecting to the correct url. This is fixed by a command-line option which was added in PR #240.