Class: Mixlib::Install::ScriptGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/mixlib/install/script_generator.rb

Constant Summary collapse

VALID_INSTALL_OPTS =
%w{omnibus_url
endpoint
http_proxy
https_proxy
install_flags
install_msi_url
nightlies
prerelease
project
root
use_sudo
sudo_command}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, powershell = false, opts = {}) ⇒ ScriptGenerator

Returns a new instance of ScriptGenerator.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/mixlib/install/script_generator.rb', line 74

def initialize(version, powershell = false, opts = {})
  @version = (version || "latest").to_s.downcase
  @powershell = powershell
  @http_proxy = nil
  @https_proxy = nil
  @install_flags = nil
  @prerelease = false
  @nightlies = false
  @endpoint = "metadata"
  @omnibus_url = "https://www.chef.io/chef/install.sh"
  @use_sudo = true
  @sudo_command = "sudo -E"

  @root = if powershell
            "$env:systemdrive\\#{Mixlib::Install::Dist::WINDOWS_INSTALL_DIR}\\#{Mixlib::Install::Dist::DEFAULT_PRODUCT}"
          else
            "#{Mixlib::Install::Dist::LINUX_INSTALL_DIR}/#{Mixlib::Install::Dist::DEFAULT_PRODUCT}"
          end

  parse_opts(opts)
end

Instance Attribute Details

#endpointObject

Returns the value of attribute endpoint.



39
40
41
# File 'lib/mixlib/install/script_generator.rb', line 39

def endpoint
  @endpoint
end

#http_proxyObject

Returns the value of attribute http_proxy.



55
56
57
# File 'lib/mixlib/install/script_generator.rb', line 55

def http_proxy
  @http_proxy
end

#https_proxyObject

Returns the value of attribute https_proxy.



56
57
58
# File 'lib/mixlib/install/script_generator.rb', line 56

def https_proxy
  @https_proxy
end

#install_flagsObject

Returns the value of attribute install_flags.



37
38
39
# File 'lib/mixlib/install/script_generator.rb', line 37

def install_flags
  @install_flags
end

#install_msi_urlObject

Returns the value of attribute install_msi_url.



59
60
61
# File 'lib/mixlib/install/script_generator.rb', line 59

def install_msi_url
  @install_msi_url
end

#nightliesObject

Returns the value of attribute nightlies.



35
36
37
# File 'lib/mixlib/install/script_generator.rb', line 35

def nightlies
  @nightlies
end

#omnibus_urlObject

Returns the value of attribute omnibus_url.



58
59
60
# File 'lib/mixlib/install/script_generator.rb', line 58

def omnibus_url
  @omnibus_url
end

#powershellObject

Returns the value of attribute powershell.



31
32
33
# File 'lib/mixlib/install/script_generator.rb', line 31

def powershell
  @powershell
end

#prereleaseObject

Returns the value of attribute prerelease.



33
34
35
# File 'lib/mixlib/install/script_generator.rb', line 33

def prerelease
  @prerelease
end

#rootObject

Returns the value of attribute root.



41
42
43
# File 'lib/mixlib/install/script_generator.rb', line 41

def root
  @root
end

#sudo_commandObject

Returns the value of attribute sudo_command.



45
46
47
# File 'lib/mixlib/install/script_generator.rb', line 45

def sudo_command
  @sudo_command
end

#use_sudoObject

Returns the value of attribute use_sudo.



43
44
45
# File 'lib/mixlib/install/script_generator.rb', line 43

def use_sudo
  @use_sudo
end

#versionObject

Returns the value of attribute version.



29
30
31
# File 'lib/mixlib/install/script_generator.rb', line 29

def version
  @version
end

Instance Method Details

#install_commandObject



96
97
98
99
100
101
102
103
# File 'lib/mixlib/install/script_generator.rb', line 96

def install_command
  vars = if powershell
           install_command_vars_for_powershell
         else
           install_command_vars_for_bourne
         end
  shell_code_from_file(vars)
end

#install_command_from_omnitruck(url) ⇒ Object



105
106
107
108
109
110
111
112
113
114
# File 'lib/mixlib/install/script_generator.rb', line 105

def install_command_from_omnitruck(url)
  uri = URI.parse(url)
  response = Net::HTTP.get_response(uri)

  if response.code == "200"
    response.body
  else
    raise StandardError, "unable to fetch the install.sh"
  end
end