mixlib-install 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b89b0d8d2bffd7bc3cafb4544212a1a2a661fc6b
4
+ data.tar.gz: 2e8b09b8f17e26880b4fecd164defed7806b9552
5
+ SHA512:
6
+ metadata.gz: ea21b2c07f490044dfe49db5f220ae10d58a6c9cb8cc891160745a7fce04e80d25077b8614e8f0d9752e843371f712a85bc8a73d969ccf30425fe1aee3c5afbb
7
+ data.tar.gz: 274d20b1fef9661ba297b6ab7c065408e47d481508baeb6dd72c2e10bb6017d93e707dcd222d31ac1609c44e06ac9aefc8e01bfdfce43511853a4a7c3587b0fc
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ tags
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,10 @@
1
+ AllCops:
2
+ Exclude:
3
+ - mixlib-install.gemspec
4
+ Style/AlignParameters:
5
+ EnforcedStyle: with_first_parameter
6
+ Style/HashSyntax:
7
+ EnforcedStyle: ruby19
8
+ Metrics/LineLength:
9
+ Exclude:
10
+ - spec/**/*.rb
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "finstyle"
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,39 @@
1
+ # Mixlib::Install
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mixlib/install`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'mixlib-install'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mixlib-install
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/mixlib-install/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
@@ -0,0 +1,15 @@
1
+ require "bundler/gem_tasks"
2
+ require "finstyle"
3
+ require "rubocop/rake_task"
4
+ require "rspec/core/rake_task"
5
+
6
+ task default: :spec
7
+
8
+ desc "Run specs"
9
+ RSpec::Core::RakeTask.new(:spec) do |spec|
10
+ spec.pattern = "spec/**/*_spec.rb"
11
+ end
12
+
13
+ RuboCop::RakeTask.new do |task|
14
+ task.options << "--display-cop-names"
15
+ end
@@ -0,0 +1,186 @@
1
+ #
2
+ # Author:: Thom May (<thom@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
+ require "mixlib/install/util"
20
+
21
+ module Mixlib
22
+ class Install
23
+ attr_accessor :version
24
+
25
+ attr_accessor :powershell
26
+
27
+ attr_accessor :prerelease
28
+
29
+ attr_accessor :nightlies
30
+
31
+ attr_accessor :endpoint
32
+
33
+ attr_accessor :root
34
+
35
+ attr_accessor :use_sudo
36
+ attr_accessor :sudo_command
37
+
38
+ attr_accessor :http_proxy
39
+ attr_accessor :https_proxy
40
+
41
+ attr_accessor :base_url
42
+
43
+ def initialize(version, powershell = false, opts = {})
44
+ @version = version
45
+ @powershell = powershell
46
+ @http_proxy = nil
47
+ @https_proxy = nil
48
+ @prerelease = false
49
+ @nightly = false
50
+ @endpoint = "metadata"
51
+ @base_url = "https://www.chef.io/chef/install.sh"
52
+ @use_sudo = true
53
+ @sudo_command = "sudo -E"
54
+
55
+ @root = if powershell
56
+ "$env:systemdrive\\opscode\\chef"
57
+ else
58
+ "/opt/chef"
59
+ end
60
+
61
+ parse_opts(opts)
62
+ end
63
+
64
+ def install
65
+ vars = if powershell
66
+ install_command_vars_for_powershell
67
+ else
68
+ install_command_vars_for_bourne
69
+ end
70
+ shell_code_from_file(vars)
71
+ end
72
+
73
+ private
74
+
75
+ # Generates the install command variables for Bourne shell-based
76
+ # platforms.
77
+ #
78
+ # @return [String] shell variable lines
79
+ # @api private
80
+ def install_command_vars_for_bourne
81
+ install_flags = %w[latest true].include?(version) ? "" : "-v #{version}"
82
+ install_flags << " " << "-n" if nightlies
83
+ install_flags << " " << "-p" if prerelease
84
+
85
+ [
86
+ shell_var("chef_omnibus_root", root),
87
+ shell_var("chef_omnibus_url", base_url),
88
+ shell_var("install_flags", install_flags.strip),
89
+ shell_var("pretty_version", Util.pretty_version(version)),
90
+ shell_var("sudo_sh", sudo("sh")),
91
+ shell_var("version", version)
92
+ ].join("\n")
93
+ end
94
+
95
+ # Generates the install command variables for PowerShell-based platforms.
96
+ #
97
+ # @param version [String] version string
98
+ # @param metadata_url [String] The metadata URL for the Chef Omnitruck API server
99
+ # @param omnibus_root [String] The base directory the project is installed to
100
+ # @return [String] shell variable lines
101
+ # @api private
102
+ def install_command_vars_for_powershell
103
+ [
104
+ shell_var("chef_metadata_url", windows_metadata_url),
105
+ shell_var("chef_omnibus_root", root),
106
+ shell_var("msi", "$env:TEMP\\chef-#{version}.msi"),
107
+ shell_var("pretty_version", Util.pretty_version(version)),
108
+ shell_var("version", version)
109
+ ].join("\n")
110
+ end
111
+
112
+ # rubocop:disable Metrics/CyclomaticComplexity
113
+ def parse_opts(opts)
114
+ opts.each do |opt, setting|
115
+ case opt.to_s
116
+ when "http_proxy"
117
+ self.http_proxy = setting
118
+ when "https_proxy"
119
+ self.https_proxy = setting
120
+ when "prerelease"
121
+ self.prerelease = setting
122
+ when "endpoint"
123
+ self.endpoint = metadata_endpoint_from_project(setting)
124
+ when "base"
125
+ self.base_url = setting
126
+ when "nightlies"
127
+ self.nightlies = setting
128
+ when "sudo_command"
129
+ self.use_sudo = true
130
+ self.sudo_command = setting
131
+ end
132
+ end
133
+ end
134
+
135
+ def shell_code_from_file(vars)
136
+ fn = File.join(
137
+ File.dirname(__FILE__),
138
+ %w[.. .. support],
139
+ "install_command"
140
+ )
141
+ Util.shell_code_from_file(vars, fn, powershell,
142
+ http_proxy: http_proxy, https_proxy: https_proxy)
143
+ end
144
+
145
+ # Builds a shell variable assignment string for the required shell type.
146
+ #
147
+ # @param name [String] variable name
148
+ # @param value [String] variable value
149
+ # @return [String] shell variable assignment
150
+ # @api private
151
+ def shell_var(name, value)
152
+ Util.shell_var(name, value, powershell)
153
+ end
154
+
155
+ # @return the correct Chef Omnitruck API metadata endpoint, based on project
156
+ def metadata_endpoint_from_project(project = nil)
157
+ if project.nil? || project.downcase == "chef"
158
+ "metadata"
159
+ else
160
+ "metadata-#{project.downcase}"
161
+ end
162
+ end
163
+
164
+ def windows_metadata_url
165
+ base = if base_url =~ %r{/install.sh$}
166
+ "#{File.dirname(base_url)}"
167
+ end
168
+
169
+ url = "#{base}#{endpoint}"
170
+ url << "?p=windows&m=x86_64&pv=2008r2" # same package for all versions
171
+ url << "&v=#{version.to_s.downcase}"
172
+ url << "&prerelease=true" if prerelease
173
+ url << "&nightlies=true" if nightlies
174
+ url
175
+ end
176
+
177
+ # Conditionally prefixes a command with a sudo command.
178
+ #
179
+ # @param command [String] command to be prefixed
180
+ # @return [String] the command, conditionaly prefixed with sudo
181
+ # @api private
182
+ def sudo(script)
183
+ use_sudo ? "#{sudo_command} #{script}" : script
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,124 @@
1
+ #
2
+ # Author:: Thom May (<thom@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 Util
22
+ class << self
23
+ # @return [String] a pretty/helpful representation of a Chef Omnibus
24
+ # package version
25
+ # @api private
26
+ def pretty_version(version)
27
+ case version
28
+ when "true" then "install only if missing"
29
+ when "latest" then "always install latest version"
30
+ else version
31
+ end
32
+ end
33
+
34
+ # Builds a complete command given a variables String preamble and a file
35
+ # containing shell code.
36
+ #
37
+ # @param vars [String] shell variables, as a String
38
+ # @param file [String] file basename (without extension) containing
39
+ # shell code
40
+ # @param powershell [Boolean] for powershell
41
+ # @return [String] command
42
+ # @api private
43
+ def shell_code_from_file(vars, file, powershell, opts = {})
44
+ src_file = file + (powershell ? ".ps1" : ".sh")
45
+
46
+ Util.wrap_shell([vars, "", IO.read(src_file)].join("\n"),
47
+ powershell, opts)
48
+ end
49
+
50
+ # Wraps a body of shell code with common context appropriate for the type
51
+ # of shell.
52
+ #
53
+ # @param code [String] the shell code to be wrapped
54
+ # @param opts [Hash] options
55
+ # @param opts[:http_proxy] [String] http proxy url
56
+ # @param opts[:https_proxy] [String] https proxy url
57
+ # @return [String] wrapped shell code
58
+ # @api private
59
+ def wrap_shell(code, powershell = false, opts = {})
60
+ env = []
61
+ if opts[:http_proxy]
62
+ env << Util.shell_env_var("http_proxy", opts[:http_proxy], powershell)
63
+ env << Util.shell_env_var("HTTP_PROXY", opts[:http_proxy], powershell)
64
+ end
65
+ if opts[:https_proxy]
66
+ env << Util.shell_env_var("https_proxy", opts[:https_proxy], powershell)
67
+ env << Util.shell_env_var("HTTPS_PROXY", opts[:https_proxy], powershell)
68
+ end
69
+ if powershell
70
+ env.join("\n").concat("\n").concat(code)
71
+ else
72
+ Util.wrap_command(env.join("\n").concat("\n").concat(code))
73
+ end
74
+ end
75
+
76
+ # Builds a shell environment variable assignment string for the
77
+ # required shell type.
78
+ #
79
+ # @param name [String] variable name
80
+ # @param value [String] variable value
81
+ # @return [String] shell variable assignment
82
+ # @api private
83
+ def shell_env_var(name, value, powershell = false)
84
+ if powershell
85
+ shell_var("env:#{name}", value, true)
86
+ else
87
+ "#{shell_var(name, value)}; export #{name}"
88
+ end
89
+ end
90
+
91
+ # Builds a shell variable assignment string for the required shell type.
92
+ #
93
+ # @param name [String] variable name
94
+ # @param value [String] variable value
95
+ # @param powershell [Boolean] for powershell
96
+ # @return [String] shell variable assignment
97
+ def shell_var(name, value, powershell = false)
98
+ if powershell
99
+ %{$#{name} = "#{value}"}
100
+ else
101
+ %{#{name}="#{value}"}
102
+ end
103
+ end
104
+
105
+ # Generates a command (or series of commands) wrapped so that it can be
106
+ # invoked on a remote instance or locally.
107
+ #
108
+ # This method uses the Bourne shell (/bin/sh) to maximize the chance of
109
+ # cross platform portability on Unixlike systems.
110
+ #
111
+ # @param [String] the command
112
+ # @return [String] a wrapped command string
113
+ def wrap_command(cmd)
114
+ cmd = "false" if cmd.nil?
115
+ cmd = "true" if cmd.to_s.empty?
116
+ cmd = cmd.sub(/\n\Z/, "") if cmd =~ /\n\Z/
117
+
118
+ "sh -c '\n#{cmd}\n'"
119
+ end
120
+
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,5 @@
1
+ module Mixlib
2
+ class Install
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "mixlib/install/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mixlib-install"
8
+ spec.version = Mixlib::Install::VERSION
9
+ spec.authors = ["Thom May"]
10
+ spec.email = ["thom@chef.io"]
11
+
12
+ spec.summary = "A mixin to help with omnitruck installs"
13
+ spec.homepage = "https://chef.io"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.9"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ end
@@ -0,0 +1,76 @@
1
+ Function Check-UpdateChef($root, $version) {
2
+ if (-Not (Test-Path $root)) { return $true }
3
+ elseif ("$version" -eq "true") { return $false }
4
+ elseif ("$version" -eq "latest") { return $true }
5
+
6
+ Try { $chef_version = (& $root\bin\chef-solo.bat -v).split(" ", 2)[1] }
7
+ Catch { $chef_version = "" }
8
+
9
+ if ($chef_version.StartsWith($version)) { return $false }
10
+ else { return $true }
11
+ }
12
+
13
+ Function Get-ChefMetadata($url) {
14
+ Try { $response = ($c = Make-WebClient).DownloadString($url) }
15
+ Finally { if ($c -ne $null) { $c.Dispose() } }
16
+
17
+ $md = ConvertFrom-StringData $response.Replace("`t", "=")
18
+ return @($md.url, $md.md5)
19
+ }
20
+
21
+ Function Get-MD5Sum($src) {
22
+ Try {
23
+ $c = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
24
+ $bytes = $c.ComputeHash(($in = (Get-Item $src).OpenRead()))
25
+ return ([System.BitConverter]::ToString($bytes)).Replace("-", "").ToLower()
26
+ } Finally { if (($c -ne $null) -and ($c.GetType().GetMethod("Dispose") -ne $null)) { $c.Dispose() }; if ($in -ne $null) { $in.Dispose() } }
27
+ }
28
+
29
+ Function Download-Chef($md_url, $dst) {
30
+ $url, $md5 = Get-ChefMetadata $md_url
31
+
32
+ Try {
33
+ Log "Downloading package from $url"
34
+ ($c = Make-WebClient).DownloadFile($url, $dst)
35
+ Log "Download complete."
36
+ } Finally { if ($c -ne $null) { $c.Dispose() } }
37
+
38
+ if (($dmd5 = Get-MD5Sum $dst) -eq $md5) { Log "Successfully verified $dst" }
39
+ else { throw "MD5 for $dst $dmd5 does not match $md5" }
40
+ }
41
+
42
+ Function Install-Chef($msi) {
43
+ Log "Installing Chef Omnibus package $msi"
44
+ $p = Start-Process -FilePath "msiexec.exe" -ArgumentList "/qn /i $msi" -Passthru -Wait
45
+
46
+ if ($p.ExitCode -ne 0) { throw "msiexec was not successful. Received exit code $($p.ExitCode)" }
47
+
48
+ Remove-Item $msi -Force
49
+ Log "Installation complete"
50
+ }
51
+
52
+ Function Log($m) { Write-Host " $m`n" }
53
+
54
+ Function Make-WebClient {
55
+ $proxy = New-Object -TypeName System.Net.WebProxy
56
+ $proxy.Address = $env:http_proxy
57
+ $client = New-Object -TypeName System.Net.WebClient
58
+ $client.Proxy = $proxy
59
+ return $client
60
+ }
61
+
62
+ Function Unresolve-Path($p) {
63
+ if ($p -eq $null) { return $null }
64
+ else { return $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($p) }
65
+ }
66
+
67
+ $chef_omnibus_root = Unresolve-Path $chef_omnibus_root
68
+ $msi = Unresolve-Path $msi
69
+
70
+ if (Check-UpdateChef $chef_omnibus_root $version) {
71
+ Write-Host "-----> Installing Chef Omnibus ($pretty_version)`n"
72
+ Download-Chef "$chef_metadata_url" $msi
73
+ Install-Chef $msi
74
+ } else {
75
+ Write-Host "-----> Chef Omnibus installation detected ($pretty_version)`n"
76
+ }
@@ -0,0 +1,220 @@
1
+ tmp_stderr="/tmp/stderr";
2
+
3
+ # capture_tmp_stderr SOURCE
4
+ capture_tmp_stderr() {
5
+ # spool up $tmp_stderr from all the commands we called
6
+ if test -f "$tmp_stderr"; then
7
+ output="`cat $tmp_stderr`";
8
+ stderr_results="${stderr_results}\nSTDERR from $1:\n\n${output}\n";
9
+ rm $tmp_stderr;
10
+ fi
11
+ }
12
+
13
+ # do_curl URL FILENAME
14
+ do_curl() {
15
+ echo "Trying curl...";
16
+ curl -sL -D "$tmp_stderr" "$1" > "$2";
17
+ ec=$?;
18
+ # check for 404
19
+ grep "404 Not Found" "$tmp_stderr" 2>&1 >/dev/null;
20
+ if test $? -eq 0; then
21
+ http_404_error "$1";
22
+ fi
23
+
24
+ # check for bad return status or empty output
25
+ if test $ec -ne 0 || test ! -s "$2"; then
26
+ capture_tmp_stderr "curl";
27
+ return 1;
28
+ else
29
+ echo "Download complete.";
30
+ return 0;
31
+ fi
32
+ }
33
+
34
+ # do_download URL FILENAME
35
+ do_download() {
36
+ echo "Downloading ${1} to file ${2}";
37
+
38
+ exists wget;
39
+ if test $? -eq 0; then
40
+ do_wget "$1" "$2" && return 0;
41
+ fi
42
+
43
+ exists curl;
44
+ if test $? -eq 0; then
45
+ do_curl "$1" "$2" && return 0;
46
+ fi
47
+
48
+ exists fetch;
49
+ if test $? -eq 0; then
50
+ do_fetch "$1" "$2" && return 0;
51
+ fi
52
+
53
+ exists python;
54
+ if test $? -eq 0; then
55
+ do_python "$1" "$2" && return 0;
56
+ fi
57
+
58
+ exists perl;
59
+ if test $? -eq 0; then
60
+ do_perl "$1" "$2" && return 0;
61
+ fi
62
+
63
+ unable_to_download "$1" "$2";
64
+ }
65
+
66
+ # do_fetch URL FILENAME
67
+ do_fetch() {
68
+ echo "Trying fetch...";
69
+ fetch -o "$2" "$1" 2>"$tmp_stderr";
70
+ ec=$?;
71
+ # check for 404
72
+ grep "Not Found" "$tmp_stderr" 2>&1 >/dev/null;
73
+ if test $? -eq 0; then
74
+ http_404_error "$1";
75
+ fi
76
+
77
+ # check for bad return status or empty output
78
+ if test $ec -ne 0 || test ! -s "$2"; then
79
+ capture_tmp_stderr "fetch";
80
+ return 1;
81
+ else
82
+ echo "Download complete.";
83
+ return 0;
84
+ fi
85
+ }
86
+
87
+ # do_perl URL FILENAME
88
+ do_perl() {
89
+ echo "Trying perl...";
90
+ perl -e "use LWP::Simple; getprint(\$ARGV[0]);" "$1" > "$2" 2>"$tmp_stderr";
91
+ ec=$?;
92
+ # check for 404
93
+ grep "404 Not Found" "$tmp_stderr" 2>&1 >/dev/null;
94
+ if test $? -eq 0; then
95
+ http_404_error "$1";
96
+ fi
97
+
98
+ # check for bad return status or empty output
99
+ if test $ec -ne 0 || test ! -s "$2"; then
100
+ capture_tmp_stderr "perl";
101
+ return 1;
102
+ else
103
+ echo "Download complete.";
104
+ return 0;
105
+ fi
106
+ }
107
+
108
+ # do_python URL FILENAME
109
+ do_python() {
110
+ echo "Trying python...";
111
+ python -c "import sys,urllib2 ; sys.stdout.write(urllib2.urlopen(sys.argv[1]).read())" "$1" > "$2" 2>"$tmp_stderr";
112
+ ec=$?;
113
+ # check for 404
114
+ grep "HTTP Error 404" "$tmp_stderr" 2>&1 >/dev/null;
115
+ if test $? -eq 0; then
116
+ http_404_error "$1";
117
+ fi
118
+
119
+ # check for bad return status or empty output
120
+ if test $ec -ne 0 || test ! -s "$2"; then
121
+ capture_tmp_stderr "python";
122
+ return 1;
123
+ else
124
+ echo "Download complete.";
125
+ return 0;
126
+ fi
127
+ }
128
+
129
+ # do_wget URL FILENAME
130
+ do_wget() {
131
+ echo "Trying wget...";
132
+ wget -O "$2" "$1" 2>"$tmp_stderr";
133
+ ec=$?;
134
+ # check for 404
135
+ grep "ERROR 404" "$tmp_stderr" 2>&1 >/dev/null;
136
+ if test $? -eq 0; then
137
+ http_404_error "$1";
138
+ fi
139
+
140
+ # check for bad return status or empty output
141
+ if test $ec -ne 0 || test ! -s "$2"; then
142
+ capture_tmp_stderr "wget";
143
+ return 1;
144
+ else
145
+ echo "Download complete.";
146
+ return 0;
147
+ fi
148
+ }
149
+
150
+ # exists COMMAND
151
+ exists() {
152
+ if command -v "$1" >/dev/null 2>&1; then
153
+ return 0;
154
+ else
155
+ return 1;
156
+ fi
157
+ }
158
+
159
+ # http_404_error URL
160
+ http_404_error() {
161
+ echo ">>>>>> Downloading ${1} resulted in an HTTP/404, aborting";
162
+ exit 40;
163
+ }
164
+
165
+ # should_update_chef ROOT VERSION
166
+ should_update_chef() {
167
+ if test ! -d "$1"; then
168
+ return 0;
169
+ elif test "$2" = "true"; then
170
+ return 1;
171
+ elif test "$2" = "latest"; then
172
+ return 0;
173
+ fi
174
+
175
+ chef_version="`${1}/bin/chef-solo -v | cut -d \" \" -f 2`";
176
+
177
+ echo "$chef_version" | grep "^${2}" 2>&1 >/dev/null;
178
+ if test $? -eq 0; then
179
+ return 1;
180
+ else
181
+ return 0;
182
+ fi
183
+ }
184
+
185
+ # unable_to_download URL FILE
186
+ unable_to_download() {
187
+ echo "Unable to download $1 to $2, aborting";
188
+
189
+ if test "x${stderr_results}" != "x"; then
190
+ echo "\nDEBUG OUTPUT FOLLOWS:\n${stderr_results}";
191
+ fi
192
+
193
+ exit 10;
194
+ }
195
+
196
+ # main
197
+ main() {
198
+ should_update_chef "$chef_omnibus_root" "$version"
199
+ if test $? -eq 0; then
200
+ echo "-----> Installing Chef Omnibus (${pretty_version})";
201
+
202
+ # solaris 10 lacks recent enough credentials, so http url is used
203
+ platform="`/usr/bin/uname -s 2>/dev/null`";
204
+ platform_version="`/usr/bin/uname -r 2>/dev/null`";
205
+ if test "x${platform}" = "xSunOS" && test "x${platform_version}" = "x5.10"; then
206
+ chef_omnibus_url=`echo "$chef_omnibus_url" | sed -e "s/https/http/"`;
207
+ fi
208
+
209
+ do_download "$chef_omnibus_url" /tmp/install.sh;
210
+ $sudo_sh /tmp/install.sh $install_flags;
211
+ else
212
+ echo "-----> Chef Omnibus installation detected (${pretty_version})";
213
+ fi
214
+ }
215
+
216
+ # augment path in an attempt to find a download program
217
+ PATH="${PATH}:/opt/local/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/sfw/bin";
218
+ export PATH;
219
+
220
+ main
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mixlib-install
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Thom May
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - thom@chef.io
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".rubocop.yml"
51
+ - ".travis.yml"
52
+ - Gemfile
53
+ - LICENSE
54
+ - README.md
55
+ - Rakefile
56
+ - lib/mixlib/install.rb
57
+ - lib/mixlib/install/util.rb
58
+ - lib/mixlib/install/version.rb
59
+ - mixlib-install.gemspec
60
+ - support/install_command.ps1
61
+ - support/install_command.sh
62
+ homepage: https://chef.io
63
+ licenses: []
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.4.5
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: A mixin to help with omnitruck installs
85
+ test_files: []
86
+ has_rdoc: