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

updating install.bat to allow installation from local path on windows #111

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/vagrant-omnibus/action/install_chef.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def fetch_or_create_install_script(env)
set version=%1
set dest=%~dp0chef-client-%version%-1.windows.msi
echo Downloading Chef %version% for Windows...
powershell -command "(New-Object System.Net.WebClient).DownloadFile('#{url}?v=%version%', '%dest%')"
powershell -command "if(test-path '#{url}/chef-client*%version%*.msi'){[array]$tempstore = dir #{url} | ?{$_.name -like 'chef-client*%version%*.msi'};copy $tempstore[0].fullname %dest%}else{(New-Object System.Net.WebClient).DownloadFile('#{url}?v=%version%', '%dest%')}"

Choose a reason for hiding this comment

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

I would do something like

[uri]$uri='#{url}';switch -regex ($uri.scheme){('http(s*)'{$source='#{url}v=%version%'}'default{[$source=(resolve-path (join-path '#{url}' 'chef-client*%version%*.msi')).path)} };(new-object Net.Webclient).DownloadFile(([uri]$source).absoluteuri, '%dest%')}

for the PowerShell command. Casting it to a URI allows you to determine if it is http(s) or a file path (or no scheme if it is a partial path), then you can determine how to append the version details. Using join-path and resolve-path can assemble the file or unc path appropriately and the casting the result of that to a uri allows either the http or file scheme to be used with webclient (no need to switch back and forth between copy or webclient download.

Copy link
Author

Choose a reason for hiding this comment

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

URI exactly what I was looking for. I figured there is a single construct that allows for both. Big thanks, I'll play with it and amend the pull request. Also, I didnt know web-client can download local files via URI :) live and learn.

echo Installing Chef %version%
msiexec /q /i %dest%
EOH
Expand Down