mixlib-install 0.7.1 → 0.8.0.alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/CONTRIBUTING.md +14 -0
  4. data/Gemfile +1 -0
  5. data/README.md +30 -21
  6. data/Rakefile +5 -1
  7. data/acceptance/.gitignore +2 -0
  8. data/acceptance/Gemfile +10 -0
  9. data/acceptance/Gemfile.lock +57 -0
  10. data/acceptance/current/.acceptance/acceptance-cookbook/.chef/config.rb +1 -0
  11. data/acceptance/current/.acceptance/acceptance-cookbook/metadata.rb +1 -0
  12. data/acceptance/current/.acceptance/acceptance-cookbook/recipes/destroy.rb +3 -0
  13. data/acceptance/current/.acceptance/acceptance-cookbook/recipes/provision.rb +1 -0
  14. data/acceptance/current/.acceptance/acceptance-cookbook/recipes/verify.rb +3 -0
  15. data/acceptance/current/.kitchen.yml +45 -0
  16. data/lib/mixlib/install.rb +50 -173
  17. data/lib/mixlib/install/artifact_info.rb +76 -0
  18. data/lib/mixlib/install/backend.rb +36 -0
  19. data/lib/mixlib/install/backend/artifactory.rb +90 -0
  20. data/lib/mixlib/install/backend/omnitruck.rb +76 -0
  21. data/lib/mixlib/install/generator.rb +28 -0
  22. data/lib/mixlib/install/generator/bourne.rb +62 -0
  23. data/lib/mixlib/install/generator/bourne/scripts/fetch_metadata.sh +47 -0
  24. data/lib/mixlib/install/generator/bourne/scripts/fetch_package.sh +53 -0
  25. data/lib/mixlib/install/generator/bourne/scripts/helpers.sh +335 -0
  26. data/lib/mixlib/install/generator/bourne/scripts/install_package.sh +33 -0
  27. data/lib/mixlib/install/generator/bourne/scripts/platform_detection.sh +157 -0
  28. data/lib/mixlib/install/options.rb +98 -0
  29. data/lib/mixlib/install/script_generator.rb +217 -0
  30. data/lib/mixlib/install/version.rb +1 -1
  31. data/mixlib-install.gemspec +5 -3
  32. data/support/install_command.ps1 +4 -4
  33. metadata +71 -5
@@ -0,0 +1,98 @@
1
+ #
2
+ # Author:: Patrick Wright (<patrick@chef.io>)
3
+ # Copyright:: Copyright (c) 2015 Chef, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ module Mixlib
20
+ class Install
21
+ class Options
22
+ class InvalidOptions < ArgumentError; end
23
+
24
+ attr_reader :options
25
+ attr_reader :errors
26
+
27
+ OMNITRUCK_CHANNELS = [:stable, :current]
28
+ ARTIFACTORY_CHANNELS = [:unstable]
29
+ ALL_SUPPORTED_CHANNELS = OMNITRUCK_CHANNELS + ARTIFACTORY_CHANNELS
30
+ SUPPORTED_PRODUCT_NAMES = %w[chef chefdk]
31
+ SUPPORTED_OPTIONS = [:channel, :product_name, :product_version,
32
+ :platform, :platform_version, :architecture]
33
+
34
+ def initialize(options)
35
+ @options = options
36
+ @errors = []
37
+ validate_options!
38
+ end
39
+
40
+ def validate_options!
41
+ validate_product_names
42
+ validate_channels
43
+ validate_unstable_version
44
+ validate_platform_info
45
+
46
+ unless errors.empty?
47
+ raise InvalidOptions, errors.join("\n")
48
+ end
49
+ end
50
+
51
+ SUPPORTED_OPTIONS.each do |option|
52
+ define_method option do
53
+ options[option] || options[option.to_s]
54
+ end
55
+ end
56
+
57
+ def for_artifactory?
58
+ ARTIFACTORY_CHANNELS.include?(channel)
59
+ end
60
+
61
+ def for_omnitruck?
62
+ OMNITRUCK_CHANNELS.include?(channel)
63
+ end
64
+
65
+ private
66
+
67
+ def validate_product_names
68
+ unless SUPPORTED_PRODUCT_NAMES.include? product_name
69
+ errors << "Unknown product name #{product_name}. \
70
+ Must be one of: #{SUPPORTED_PRODUCT_NAMES.join(", ")}"
71
+ end
72
+ end
73
+
74
+ def validate_channels
75
+ unless ALL_SUPPORTED_CHANNELS.include? channel
76
+ errors << "Unknown channel #{channel}. \
77
+ Must be one of: #{ALL_SUPPORTED_CHANNELS.join(", ")}"
78
+ end
79
+ end
80
+
81
+ def validate_unstable_version
82
+ if for_artifactory? && product_version !~ /^\d+.\d+.\d+\+[0-9]{14}$/
83
+ errors << "Version must match pattern '1.2.3+12345678901234' when \
84
+ using channels #{ARTIFACTORY_CHANNELS.join(", ")}"
85
+ end
86
+ end
87
+
88
+ def validate_platform_info
89
+ platform_opts = [platform, platform_version, architecture]
90
+ if (platform_opts.any?(&:nil?)) &&
91
+ (platform_opts.any? { |opt| !opt.nil? })
92
+ errors << "platform, platform version, and architecture are all \
93
+ required when specifying Platform options."
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,217 @@
1
+ #
2
+ # Author:: Thom May (<thom@chef.io>)
3
+ # Author:: Patrick Wright (<patrick@chef.io>)
4
+ # Copyright:: Copyright (c) 2015 Chef, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require "mixlib/install/util"
21
+ require "cgi"
22
+
23
+ module Mixlib
24
+ class Install
25
+ class ScriptGenerator
26
+ attr_accessor :version
27
+
28
+ attr_accessor :powershell
29
+
30
+ attr_accessor :prerelease
31
+
32
+ attr_accessor :nightlies
33
+
34
+ attr_accessor :install_flags
35
+
36
+ attr_accessor :endpoint
37
+
38
+ attr_accessor :root
39
+
40
+ attr_accessor :use_sudo
41
+
42
+ attr_reader :sudo_command
43
+
44
+ def sudo_command=(cmd)
45
+ if cmd.nil?
46
+ @use_sudo = false
47
+ else
48
+ @sudo_command = cmd
49
+ end
50
+ end
51
+
52
+ attr_accessor :http_proxy
53
+ attr_accessor :https_proxy
54
+
55
+ attr_accessor :omnibus_url
56
+ attr_accessor :install_msi_url
57
+
58
+ VALID_INSTALL_OPTS = %w[omnibus_url
59
+ endpoint
60
+ http_proxy
61
+ https_proxy
62
+ install_flags
63
+ install_msi_url
64
+ nightlies
65
+ prerelease
66
+ project
67
+ root
68
+ use_sudo
69
+ sudo_command]
70
+
71
+ def initialize(version, powershell = false, opts = {})
72
+ @version = version || "latest"
73
+ @powershell = powershell
74
+ @http_proxy = nil
75
+ @https_proxy = nil
76
+ @install_flags = nil
77
+ @prerelease = false
78
+ @nightlies = false
79
+ @endpoint = "metadata"
80
+ @omnibus_url = "https://www.chef.io/chef/install.sh"
81
+ @use_sudo = true
82
+ @sudo_command = "sudo -E"
83
+
84
+ @root = if powershell
85
+ "$env:systemdrive\\opscode\\chef"
86
+ else
87
+ "/opt/chef"
88
+ end
89
+
90
+ parse_opts(opts)
91
+ end
92
+
93
+ def install_command
94
+ vars = if powershell
95
+ install_command_vars_for_powershell
96
+ else
97
+ install_command_vars_for_bourne
98
+ end
99
+ shell_code_from_file(vars)
100
+ end
101
+
102
+ private
103
+
104
+ # Generates the install command variables for Bourne shell-based
105
+ # platforms.
106
+ #
107
+ # @return [String] shell variable lines
108
+ # @api private
109
+ def install_command_vars_for_bourne
110
+ flags = %w[latest true nightlies].include?(version) ? "" : "-v #{CGI.escape(version)}"
111
+ flags << " " << "-n" if nightlies
112
+ flags << " " << "-p" if prerelease
113
+ flags << " " << install_flags if install_flags
114
+
115
+ [
116
+ shell_var("chef_omnibus_root", root),
117
+ shell_var("chef_omnibus_url", omnibus_url),
118
+ shell_var("install_flags", flags.strip),
119
+ shell_var("pretty_version", Util.pretty_version(version)),
120
+ shell_var("sudo_sh", sudo("sh")),
121
+ shell_var("version", version)
122
+ ].join("\n")
123
+ end
124
+
125
+ # Generates the install command variables for PowerShell-based platforms.
126
+ #
127
+ # @param version [String] version string
128
+ # @param metadata_url [String] The metadata URL for the Chef Omnitruck API server
129
+ # @param omnibus_root [String] The base directory the project is installed to
130
+ # @return [String] shell variable lines
131
+ # @api private
132
+ def install_command_vars_for_powershell
133
+ [
134
+ shell_var("chef_omnibus_root", root),
135
+ shell_var("msi", "$env:TEMP\\chef-#{version}.msi")
136
+ ].tap { |vars|
137
+ if install_msi_url
138
+ vars << shell_var("chef_msi_url", install_msi_url)
139
+ else
140
+ vars << shell_var("chef_metadata_url", windows_metadata_url)
141
+ vars << shell_var("pretty_version", Util.pretty_version(version))
142
+ vars << shell_var("version", version)
143
+ end
144
+ }.join("\n")
145
+ end
146
+
147
+ def validate_opts!(opt)
148
+ err_msg = ["#{opt} is not a valid option",
149
+ "valid options are #{VALID_INSTALL_OPTS.join(" ")}"].join(",")
150
+ fail ArgumentError, err_msg unless VALID_INSTALL_OPTS.include?(opt.to_s)
151
+ end
152
+
153
+ def parse_opts(opts)
154
+ opts.each do |opt, setting|
155
+ validate_opts!(opt)
156
+ case opt.to_s
157
+ when "project", "endpoint"
158
+ self.endpoint = metadata_endpoint_from_project(setting)
159
+ else
160
+ send("#{opt.to_sym}=", setting)
161
+ end
162
+ end
163
+ end
164
+
165
+ def shell_code_from_file(vars)
166
+ fn = File.join(
167
+ File.dirname(__FILE__),
168
+ %w[.. .. .. support],
169
+ "install_command"
170
+ )
171
+ Util.shell_code_from_file(vars, fn, powershell,
172
+ http_proxy: http_proxy, https_proxy: https_proxy)
173
+ end
174
+
175
+ # Builds a shell variable assignment string for the required shell type.
176
+ #
177
+ # @param name [String] variable name
178
+ # @param value [String] variable value
179
+ # @return [String] shell variable assignment
180
+ # @api private
181
+ def shell_var(name, value)
182
+ Util.shell_var(name, value, powershell)
183
+ end
184
+
185
+ # @return the correct Chef Omnitruck API metadata endpoint, based on project
186
+ def metadata_endpoint_from_project(project = nil)
187
+ if project.nil? || project.downcase == "chef"
188
+ "metadata"
189
+ else
190
+ "metadata-#{project.downcase}"
191
+ end
192
+ end
193
+
194
+ def windows_metadata_url
195
+ base = if omnibus_url =~ %r{/install.sh$}
196
+ "#{File.dirname(omnibus_url)}/"
197
+ end
198
+
199
+ url = "#{base}#{endpoint}"
200
+ url << "?p=windows&m=x86_64&pv=2008r2" # same package for all versions
201
+ url << "&v=#{CGI.escape(version.to_s.downcase)}"
202
+ url << "&prerelease=true" if prerelease
203
+ url << "&nightlies=true" if nightlies
204
+ url
205
+ end
206
+
207
+ # Conditionally prefixes a command with a sudo command.
208
+ #
209
+ # @param command [String] command to be prefixed
210
+ # @return [String] the command, conditionaly prefixed with sudo
211
+ # @api private
212
+ def sudo(script)
213
+ use_sudo ? "#{sudo_command} #{script}" : script
214
+ end
215
+ end
216
+ end
217
+ end
@@ -1,5 +1,5 @@
1
1
  module Mixlib
2
2
  class Install
3
- VERSION = "0.7.1"
3
+ VERSION = "0.8.0.alpha.0"
4
4
  end
5
5
  end
@@ -6,8 +6,8 @@ require "mixlib/install/version"
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "mixlib-install"
8
8
  spec.version = Mixlib::Install::VERSION
9
- spec.authors = ["Thom May"]
10
- spec.email = ["thom@chef.io"]
9
+ spec.authors = ["Thom May", "Patrick Wright"]
10
+ spec.email = ["thom@chef.io", "patrick@chef.io"]
11
11
  spec.license = "Apache-2.0"
12
12
 
13
13
  spec.summary = "A mixin to help with omnitruck installs"
@@ -17,9 +17,11 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- # spec.required_ruby_version = ">= 2.0.0"
20
+ spec.add_dependency "artifactory", "~> 2.3.0"
21
+ spec.add_dependency "mixlib-versioning", "~> 1.1.0"
21
22
 
22
23
  spec.add_development_dependency "bundler"
23
24
  spec.add_development_dependency "rake", "~> 10.0"
24
25
  spec.add_development_dependency "rspec", "~> 3.3"
26
+ spec.add_development_dependency "pry"
25
27
  end
@@ -3,13 +3,13 @@ Function Check-UpdateChef($root, $version) {
3
3
  elseif ("$version" -eq "true") { return $false }
4
4
  elseif ("$version" -eq "latest") { return $true }
5
5
 
6
- Try { $chef_version = (Get-Content $root\version-manifest.txt | select-object -first 1) }
6
+ Try { $chef_version = Get-Content $root\version-manifest.txt | select-object -1}
7
7
  Catch {
8
- Try { $chef_version = (& $root\bin\chef-solo.bat -v) }
9
- Catch { $chef_version = " " }
8
+ Try { $chef_version = (& $root\bin\chef-solo.bat -v).split(" ", 2)[1] }
9
+ Catch { $chef_version = "" }
10
10
  }
11
11
 
12
- if ($chef_version.split(" ", 2)[1].StartsWith($version)) { return $false }
12
+ if ($chef_version.StartsWith($version)) { return $false }
13
13
  else { return $true }
14
14
  }
15
15
 
metadata CHANGED
@@ -1,15 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixlib-install
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0.alpha.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thom May
8
+ - Patrick Wright
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2016-01-19 00:00:00.000000000 Z
12
+ date: 2015-12-01 00:00:00.000000000 Z
12
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: artifactory
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 2.3.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 2.3.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: mixlib-versioning
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 1.1.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 1.1.0
13
42
  - !ruby/object:Gem::Dependency
14
43
  name: bundler
15
44
  requirement: !ruby/object:Gem::Requirement
@@ -52,9 +81,24 @@ dependencies:
52
81
  - - "~>"
53
82
  - !ruby/object:Gem::Version
54
83
  version: '3.3'
84
+ - !ruby/object:Gem::Dependency
85
+ name: pry
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
55
98
  description:
56
99
  email:
57
100
  - thom@chef.io
101
+ - patrick@chef.io
58
102
  executables: []
59
103
  extensions: []
60
104
  extra_rdoc_files: []
@@ -63,11 +107,34 @@ files:
63
107
  - ".rspec"
64
108
  - ".rubocop.yml"
65
109
  - ".travis.yml"
110
+ - CONTRIBUTING.md
66
111
  - Gemfile
67
112
  - LICENSE
68
113
  - README.md
69
114
  - Rakefile
115
+ - acceptance/.gitignore
116
+ - acceptance/Gemfile
117
+ - acceptance/Gemfile.lock
118
+ - acceptance/current/.acceptance/acceptance-cookbook/.chef/config.rb
119
+ - acceptance/current/.acceptance/acceptance-cookbook/metadata.rb
120
+ - acceptance/current/.acceptance/acceptance-cookbook/recipes/destroy.rb
121
+ - acceptance/current/.acceptance/acceptance-cookbook/recipes/provision.rb
122
+ - acceptance/current/.acceptance/acceptance-cookbook/recipes/verify.rb
123
+ - acceptance/current/.kitchen.yml
70
124
  - lib/mixlib/install.rb
125
+ - lib/mixlib/install/artifact_info.rb
126
+ - lib/mixlib/install/backend.rb
127
+ - lib/mixlib/install/backend/artifactory.rb
128
+ - lib/mixlib/install/backend/omnitruck.rb
129
+ - lib/mixlib/install/generator.rb
130
+ - lib/mixlib/install/generator/bourne.rb
131
+ - lib/mixlib/install/generator/bourne/scripts/fetch_metadata.sh
132
+ - lib/mixlib/install/generator/bourne/scripts/fetch_package.sh
133
+ - lib/mixlib/install/generator/bourne/scripts/helpers.sh
134
+ - lib/mixlib/install/generator/bourne/scripts/install_package.sh
135
+ - lib/mixlib/install/generator/bourne/scripts/platform_detection.sh
136
+ - lib/mixlib/install/options.rb
137
+ - lib/mixlib/install/script_generator.rb
71
138
  - lib/mixlib/install/util.rb
72
139
  - lib/mixlib/install/version.rb
73
140
  - mixlib-install.gemspec
@@ -88,9 +155,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
155
  version: '0'
89
156
  required_rubygems_version: !ruby/object:Gem::Requirement
90
157
  requirements:
91
- - - ">="
158
+ - - ">"
92
159
  - !ruby/object:Gem::Version
93
- version: '0'
160
+ version: 1.3.1
94
161
  requirements: []
95
162
  rubyforge_project:
96
163
  rubygems_version: 2.4.8
@@ -98,4 +165,3 @@ signing_key:
98
165
  specification_version: 4
99
166
  summary: A mixin to help with omnitruck installs
100
167
  test_files: []
101
- has_rdoc: