Class: Mixlib::Install::Util
- Inherits:
-
Object
- Object
- Mixlib::Install::Util
- Defined in:
- lib/mixlib/install/util.rb
Class Method Summary collapse
-
.pretty_version(version) ⇒ String
private
A pretty/helpful representation of a Chef Omnibus package version.
-
.shell_code_from_file(vars, file, powershell, opts = {}) ⇒ String
private
Builds a complete command given a variables String preamble and a file containing shell code.
-
.shell_env_var(name, value, powershell = false) ⇒ String
private
Builds a shell environment variable assignment string for the required shell type.
-
.shell_var(name, value, powershell = false) ⇒ String
Builds a shell variable assignment string for the required shell type.
-
.wrap_command(cmd) ⇒ String
Generates a command (or series of commands) wrapped so that it can be invoked on a remote instance or locally.
-
.wrap_shell(code, powershell = false, opts = {}) ⇒ String
private
Wraps a body of shell code with common context appropriate for the type of shell.
Class Method Details
.pretty_version(version) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a pretty/helpful representation of a Chef Omnibus package version.
26 27 28 29 30 31 32 |
# File 'lib/mixlib/install/util.rb', line 26 def pretty_version(version) case version when "true" then "install only if missing" when "latest" then "always install latest version" else version end end |
.shell_code_from_file(vars, file, powershell, opts = {}) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Builds a complete command given a variables String preamble and a file containing shell code.
43 44 45 46 47 48 |
# File 'lib/mixlib/install/util.rb', line 43 def shell_code_from_file(vars, file, powershell, opts = {}) src_file = file + (powershell ? ".ps1" : ".sh") Util.wrap_shell([vars, "", IO.read(src_file)].join("\n"), powershell, opts) end |
.shell_env_var(name, value, powershell = false) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Builds a shell environment variable assignment string for the required shell type.
83 84 85 86 87 88 89 |
# File 'lib/mixlib/install/util.rb', line 83 def shell_env_var(name, value, powershell = false) if powershell shell_var("env:#{name}", value, true) else "#{shell_var(name, value)}; export #{name}" end end |
.shell_var(name, value, powershell = false) ⇒ String
Builds a shell variable assignment string for the required shell type.
97 98 99 100 101 102 103 |
# File 'lib/mixlib/install/util.rb', line 97 def shell_var(name, value, powershell = false) if powershell %{$#{name} = "#{value}"} else %{#{name}="#{value}"} end end |
.wrap_command(cmd) ⇒ String
Generates a command (or series of commands) wrapped so that it can be invoked on a remote instance or locally.
This method uses the Bourne shell (/bin/sh) to maximize the chance of cross platform portability on Unixlike systems.
113 114 115 116 117 118 119 |
# File 'lib/mixlib/install/util.rb', line 113 def wrap_command(cmd) cmd = "false" if cmd.nil? cmd = "true" if cmd.to_s.empty? cmd = cmd.sub(/\n\Z/, "") if cmd =~ /\n\Z/ "sh -c '\n#{cmd}\n'" end |
.wrap_shell(code, powershell = false, opts = {}) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Wraps a body of shell code with common context appropriate for the type of shell.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mixlib/install/util.rb', line 59 def wrap_shell(code, powershell = false, opts = {}) env = [] if opts[:http_proxy] env << Util.shell_env_var("http_proxy", opts[:http_proxy], powershell) env << Util.shell_env_var("HTTP_PROXY", opts[:http_proxy], powershell) end if opts[:https_proxy] env << Util.shell_env_var("https_proxy", opts[:https_proxy], powershell) env << Util.shell_env_var("HTTPS_PROXY", opts[:https_proxy], powershell) end if powershell env.join("\n").concat("\n").concat(code) else Util.wrap_command(env.join("\n").concat("\n").concat(code)) end end |