Class: Mixlib::Install

Inherits:
Object
  • Object
show all
Defined in:
lib/mixlib/install.rb,
lib/mixlib/install/util.rb,
lib/mixlib/install/backend.rb,
lib/mixlib/install/options.rb,
lib/mixlib/install/product.rb,
lib/mixlib/install/version.rb,
lib/mixlib/install/generator.rb,
lib/mixlib/install/backend/base.rb,
lib/mixlib/install/artifact_info.rb,
lib/mixlib/install/generator/base.rb,
lib/mixlib/install/generator/bourne.rb,
lib/mixlib/install/script_generator.rb,
lib/mixlib/install/generator/powershell.rb,
lib/mixlib/install/backend/package_router.rb

Defined Under Namespace

Classes: ArtifactInfo, Backend, Generator, Options, Product, ProductMatrix, ScriptGenerator, Util

Constant Summary collapse

VERSION =
"2.1.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Install

Returns a new instance of Install.



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

def initialize(options = {})
  @options = Options.new(options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Class Method Details

.available_versions(product_name, channel) ⇒ Array<String>

List available versions

product_name and channel.

Parameters:

  • product (String)

    name

  • channel (String, Symbol)

Returns:

  • (Array<String>)

    list of available versions for the given



67
68
69
70
71
72
73
74
# File 'lib/mixlib/install.rb', line 67

def self.available_versions(product_name, channel)
  Backend.available_versions(
    Mixlib::Install::Options.new(
      product_name: product_name,
      channel: channel.to_sym
    )
  )
end

.detect_platformObject

Returns a Hash containing the platform info options



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/mixlib/install.rb', line 145

def self.detect_platform
  output = if Gem.win_platform?
             # For Windows we write the detect platform script and execute the
             # powershell.exe program with Mixlib::ShellOut
             Dir.mktmpdir do |d|
               File.open(File.join(d, "detect_platform.ps1"), "w+") do |f|
                 f.puts self.detect_platform_ps1
               end

               Mixlib::ShellOut.new("powershell.exe -file #{File.join(d, "detect_platform.ps1")}").run_command
             end
           else
             Mixlib::ShellOut.new(self.detect_platform_sh).run_command
           end

  platform_info = output.stdout.split

  {
    platform: platform_info[0],
    platform_version: platform_info[1],
    architecture: platform_info[2],
  }
end

.detect_platform_ps1Object

Returns the platform_detection.ps1 script



179
180
181
# File 'lib/mixlib/install.rb', line 179

def self.detect_platform_ps1
  Mixlib::Install::Generator::PowerShell.detect_platform_ps1
end

.detect_platform_shObject

Returns the platform_detection.sh script



172
173
174
# File 'lib/mixlib/install.rb', line 172

def self.detect_platform_sh
  Mixlib::Install::Generator::Bourne.detect_platform_sh
end

.install_ps1(context = {}) ⇒ Object

Returns the install.ps1 script Supported context parameters:


base_url [String]

url pointing to the omnitruck to be queried by the script.


201
202
203
# File 'lib/mixlib/install.rb', line 201

def self.install_ps1(context = {})
  Mixlib::Install::Generator::PowerShell.install_ps1(context)
end

.install_sh(context = {}) ⇒ Object

Returns the install.sh script Supported context parameters:


base_url [String]

url pointing to the omnitruck to be queried by the script.


190
191
192
# File 'lib/mixlib/install.rb', line 190

def self.install_sh(context = {})
  Mixlib::Install::Generator::Bourne.install_sh(context)
end

Instance Method Details

#artifact_infoArray<ArtifactInfo>, ArtifactInfo

Fetch artifact metadata information

channel, product name, and product version. channel, product name, product version and platform info

Returns:

  • (Array<ArtifactInfo>)

    list of fetched artifact data for the configured

  • (ArtifactInfo)

    fetched artifact data for the configured



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

def artifact_info
  Backend.info(options)
end

#available_versionsArray<String>

List available versions

product_name and channel.

Returns:

  • (Array<String>)

    list of available versions for the given



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

def available_versions
  self.class.available_versions(options.product_name, options.channel)
end

#current_versionObject

Returns the current version of the installed product. Returns nil if the product is not installed.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/mixlib/install.rb', line 104

def current_version
  # Note that this logic does not work for products other than
  # chef & chefdk since version-manifest is created under the
  # install directory which can be different than the product name (e.g.
  # chef-server -> /opt/opscode). But this is OK for now since
  # chef & chefdk are the only supported products.
  version_manifest_file = if options.for_ps1?
                            "$env:systemdrive\\opscode\\#{options.product_name}\\version-manifest.json"
                          else
                            "/opt/#{options.product_name}/version-manifest.json"
                          end

  if File.exist? version_manifest_file
    JSON.parse(File.read(version_manifest_file))["build_version"]
  end
end

#detect_platformObject

Automatically set the platform options



137
138
139
140
# File 'lib/mixlib/install.rb', line 137

def detect_platform
  options.set_platform_info(self.class.detect_platform)
  self
end

#install_commandString

Returns an install script for the given options

Returns:

  • (String)

    script for installing with given options



81
82
83
# File 'lib/mixlib/install.rb', line 81

def install_command
  Generator.install_command(options)
end

#rootString

Returns the base installation directory for the given options

Returns:

  • (String)

    the installation directory for the project



90
91
92
93
94
95
96
97
98
# File 'lib/mixlib/install.rb', line 90

def root
  # This only works for chef and chefdk but they are the only projects
  # we are supporting as of now.
  if options.for_ps1?
    "$env:systemdrive\\opscode\\#{options.product_name}"
  else
    "/opt/#{options.product_name}"
  end
end

#upgrade_available?Boolean

Returns true if an upgradable version is available, false otherwise.

Returns:

  • (Boolean)


124
125
126
127
128
129
130
131
132
# File 'lib/mixlib/install.rb', line 124

def upgrade_available?
  return true if current_version.nil?

  artifact = artifact_info
  artifact = artifact.first if artifact.is_a? Array
  available_ver = Mixlib::Versioning.parse(artifact.version)
  current_ver = Mixlib::Versioning.parse(current_version)
  (available_ver > current_ver)
end