lib/mixlib/install.rb in mixlib-install-0.3.0 vs lib/mixlib/install.rb in mixlib-install-0.4.0
- old
+ new
@@ -15,10 +15,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
require "mixlib/install/util"
+require "cgi"
module Mixlib
class Install
attr_accessor :version
@@ -39,10 +40,11 @@
attr_accessor :http_proxy
attr_accessor :https_proxy
attr_accessor :base_url
+ attr_accessor :install_msi_url
def initialize(version, powershell = false, opts = {})
@version = version
@powershell = powershell
@http_proxy = nil
@@ -62,11 +64,11 @@
end
parse_opts(opts)
end
- def install
+ def install_command
vars = if powershell
install_command_vars_for_powershell
else
install_command_vars_for_bourne
end
@@ -79,11 +81,11 @@
# platforms.
#
# @return [String] shell variable lines
# @api private
def install_command_vars_for_bourne
- flags = %w[latest true].include?(version) ? "" : "-v #{version}"
+ flags = %w[latest true].include?(version) ? "" : "-v #{CGI.escape(version)}"
flags << " " << "-n" if nightlies
flags << " " << "-p" if prerelease
flags << " " << install_flags if install_flags
[
@@ -103,16 +105,21 @@
# @param omnibus_root [String] The base directory the project is installed to
# @return [String] shell variable lines
# @api private
def install_command_vars_for_powershell
[
- shell_var("chef_metadata_url", windows_metadata_url),
shell_var("chef_omnibus_root", root),
shell_var("msi", "$env:TEMP\\chef-#{version}.msi"),
- shell_var("pretty_version", Util.pretty_version(version)),
- shell_var("version", version)
- ].join("\n")
+ ].tap { |vars|
+ if install_msi_url
+ vars << shell_var("chef_msi_url", install_msi_url)
+ else
+ vars << shell_var("chef_metadata_url", windows_metadata_url)
+ vars << shell_var("pretty_version", Util.pretty_version(version))
+ vars << shell_var("version", version)
+ end
+ }.join("\n")
end
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
def parse_opts(opts)
opts.each do |opt, setting|
@@ -134,10 +141,12 @@
when "sudo"
self.use_sudo = setting
when "sudo_command"
self.use_sudo = true
self.sudo_command = setting
+ when "install_msi_url"
+ self.install_msi_url = setting
end
end
end
def shell_code_from_file(vars)
@@ -174,10 +183,10 @@
"#{File.dirname(base_url)}/"
end
url = "#{base}#{endpoint}"
url << "?p=windows&m=x86_64&pv=2008r2" # same package for all versions
- url << "&v=#{version.to_s.downcase}"
+ url << "&v=#{CGI.escape(version.to_s.downcase)}"
url << "&prerelease=true" if prerelease
url << "&nightlies=true" if nightlies
url
end