[DRE-commits] [ruby-mixlib-install] 01/05: Imported Upstream version 0.7.1
Hleb Valoshka
tsfgnu-guest at moszumanska.debian.org
Sat Mar 5 16:53:48 UTC 2016
This is an automated email from the git hooks/post-receive script.
tsfgnu-guest pushed a commit to branch master
in repository ruby-mixlib-install.
commit 3aea87a080d84289b7ee4f644d9a93dd0c2f313b
Author: Hleb Valoshka <375gnu at gmail.com>
Date: Sat Mar 5 19:19:02 2016 +0300
Imported Upstream version 0.7.1
---
.gitignore | 10 ++
.rspec | 2 +
.rubocop.yml | 10 ++
.travis.yml | 7 ++
Gemfile | 4 +
LICENSE | 201 ++++++++++++++++++++++++++++++++++++
README.md | 39 +++++++
Rakefile | 15 +++
lib/mixlib/install.rb | 215 +++++++++++++++++++++++++++++++++++++++
lib/mixlib/install/util.rb | 124 +++++++++++++++++++++++
lib/mixlib/install/version.rb | 5 +
metadata.yml | 101 +++++++++++++++++++
mixlib-install.gemspec | 25 +++++
support/install_command.ps1 | 84 ++++++++++++++++
support/install_command.sh | 229 ++++++++++++++++++++++++++++++++++++++++++
15 files changed, 1071 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8b1df34
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,10 @@
+/.bundle/
+/.yardoc
+/Gemfile.lock
+/_yardoc/
+/coverage/
+/doc/
+/pkg/
+/spec/reports/
+/tmp/
+tags
diff --git a/.rspec b/.rspec
new file mode 100644
index 0000000..8c18f1a
--- /dev/null
+++ b/.rspec
@@ -0,0 +1,2 @@
+--format documentation
+--color
diff --git a/.rubocop.yml b/.rubocop.yml
new file mode 100644
index 0000000..1d19853
--- /dev/null
+++ b/.rubocop.yml
@@ -0,0 +1,10 @@
+AllCops:
+ Exclude:
+ - mixlib-install.gemspec
+Style/AlignParameters:
+ EnforcedStyle: with_first_parameter
+Style/HashSyntax:
+ EnforcedStyle: ruby19
+Metrics/LineLength:
+ Exclude:
+ - spec/**/*.rb
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..c89cdb4
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,7 @@
+language: ruby
+sudo: false
+rvm:
+ - 2.2
+ - 2.1
+ - 1.9.3
+ - ruby-head
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..0d8bff4
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,4 @@
+source "https://rubygems.org"
+
+gem "finstyle"
+gemspec
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..11069ed
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+Copyright [yyyy] [name of copyright owner]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..4e95d40
--- /dev/null
+++ b/README.md
@@ -0,0 +1,39 @@
+# Mixlib::Install
+
+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.
+
+TODO: Delete this and the text above, and describe your gem
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+```ruby
+gem 'mixlib-install'
+```
+
+And then execute:
+
+ $ bundle
+
+Or install it yourself as:
+
+ $ gem install mixlib-install
+
+## Usage
+
+TODO: Write usage instructions here
+
+## Development
+
+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.
+
+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).
+
+## Contributing
+
+1. Fork it ( https://github.com/[my-github-username]/mixlib-install/fork )
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Add some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create a new Pull Request
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000..b938783
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,15 @@
+require "bundler/gem_tasks"
+require "finstyle"
+require "rubocop/rake_task"
+require "rspec/core/rake_task"
+
+task default: :spec
+
+desc "Run specs"
+RSpec::Core::RakeTask.new(:spec) do |spec|
+ spec.pattern = "spec/**/*_spec.rb"
+end
+
+RuboCop::RakeTask.new do |task|
+ task.options << "--display-cop-names"
+end
diff --git a/lib/mixlib/install.rb b/lib/mixlib/install.rb
new file mode 100644
index 0000000..c86b447
--- /dev/null
+++ b/lib/mixlib/install.rb
@@ -0,0 +1,215 @@
+#
+# Author:: Thom May (<thom at chef.io>)
+# Copyright:: Copyright (c) 2015 Chef, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require "mixlib/install/util"
+require "cgi"
+
+module Mixlib
+ class Install
+ attr_accessor :version
+
+ attr_accessor :powershell
+
+ attr_accessor :prerelease
+
+ attr_accessor :nightlies
+
+ attr_accessor :install_flags
+
+ attr_accessor :endpoint
+
+ attr_accessor :root
+
+ attr_accessor :use_sudo
+
+ attr_reader :sudo_command
+
+ def sudo_command=(cmd)
+ if cmd.nil?
+ @use_sudo = false
+ else
+ @sudo_command = cmd
+ end
+ end
+
+ attr_accessor :http_proxy
+ attr_accessor :https_proxy
+
+ attr_accessor :omnibus_url
+ attr_accessor :install_msi_url
+
+ VALID_INSTALL_OPTS = %w(omnibus_url
+ endpoint
+ http_proxy
+ https_proxy
+ install_flags
+ install_msi_url
+ nightlies
+ prerelease
+ project
+ root
+ use_sudo
+ sudo_command)
+
+ def initialize(version, powershell = false, opts = {})
+ @version = version || "latest"
+ @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\\opscode\\chef"
+ else
+ "/opt/chef"
+ end
+
+ parse_opts(opts)
+ end
+
+ def install_command
+ vars = if powershell
+ install_command_vars_for_powershell
+ else
+ install_command_vars_for_bourne
+ end
+ shell_code_from_file(vars)
+ end
+
+ private
+
+ # Generates the install command variables for Bourne shell-based
+ # platforms.
+ #
+ # @return [String] shell variable lines
+ # @api private
+ def install_command_vars_for_bourne
+ flags = %w[latest true nightlies].include?(version) ? "" : "-v #{CGI.escape(version)}"
+ flags << " " << "-n" if nightlies
+ flags << " " << "-p" if prerelease
+ flags << " " << install_flags if install_flags
+
+ [
+ shell_var("chef_omnibus_root", root),
+ shell_var("chef_omnibus_url", omnibus_url),
+ shell_var("install_flags", flags.strip),
+ shell_var("pretty_version", Util.pretty_version(version)),
+ shell_var("sudo_sh", sudo("sh")),
+ shell_var("version", version)
+ ].join("\n")
+ end
+
+ # Generates the install command variables for PowerShell-based platforms.
+ #
+ # @param version [String] version string
+ # @param metadata_url [String] The metadata URL for the Chef Omnitruck API server
+ # @param omnibus_root [String] The base directory the project is installed to
+ # @return [String] shell variable lines
+ # @api private
+ def install_command_vars_for_powershell
+ [
+ shell_var("chef_omnibus_root", root),
+ shell_var("msi", "$env:TEMP\\chef-#{version}.msi"),
+ ].tap { |vars|
+ if install_msi_url
+ vars << shell_var("chef_msi_url", install_msi_url)
+ else
+ vars << shell_var("chef_metadata_url", windows_metadata_url)
+ vars << shell_var("pretty_version", Util.pretty_version(version))
+ vars << shell_var("version", version)
+ end
+ }.join("\n")
+ end
+
+ def validate_opts!(opt)
+ err_msg = ["#{opt} is not a valid option",
+ "valid options are #{VALID_INSTALL_OPTS.join(' ')}"].join(',')
+ fail ArgumentError, err_msg unless VALID_INSTALL_OPTS.include?(opt.to_s)
+ end
+
+ # rubocop:disable Metrics/MethodLength
+ def parse_opts(opts)
+ opts.each do |opt, setting|
+ validate_opts!(opt)
+ case opt.to_s
+ when 'project', 'endpoint'
+ self.endpoint = metadata_endpoint_from_project(setting)
+ else
+ send("#{opt.to_sym}=", setting)
+ end
+ end
+ end
+
+ def shell_code_from_file(vars)
+ fn = File.join(
+ File.dirname(__FILE__),
+ %w[.. .. support],
+ "install_command"
+ )
+ Util.shell_code_from_file(vars, fn, powershell,
+ http_proxy: http_proxy, https_proxy: https_proxy)
+ end
+
+ # Builds a shell variable assignment string for the required shell type.
+ #
+ # @param name [String] variable name
+ # @param value [String] variable value
+ # @return [String] shell variable assignment
+ # @api private
+ def shell_var(name, value)
+ Util.shell_var(name, value, powershell)
+ end
+
+ # @return the correct Chef Omnitruck API metadata endpoint, based on project
+ def metadata_endpoint_from_project(project = nil)
+ if project.nil? || project.downcase == "chef"
+ "metadata"
+ else
+ "metadata-#{project.downcase}"
+ end
+ end
+
+ def windows_metadata_url
+ base = if omnibus_url =~ %r{/install.sh$}
+ "#{File.dirname(omnibus_url)}/"
+ end
+
+ url = "#{base}#{endpoint}"
+ url << "?p=windows&m=x86_64&pv=2008r2" # same package for all versions
+ url << "&v=#{CGI.escape(version.to_s.downcase)}"
+ url << "&prerelease=true" if prerelease
+ url << "&nightlies=true" if nightlies
+ url
+ end
+
+ # Conditionally prefixes a command with a sudo command.
+ #
+ # @param command [String] command to be prefixed
+ # @return [String] the command, conditionaly prefixed with sudo
+ # @api private
+ def sudo(script)
+ use_sudo ? "#{sudo_command} #{script}" : script
+ end
+ end
+end
diff --git a/lib/mixlib/install/util.rb b/lib/mixlib/install/util.rb
new file mode 100644
index 0000000..9aeab28
--- /dev/null
+++ b/lib/mixlib/install/util.rb
@@ -0,0 +1,124 @@
+#
+# Author:: Thom May (<thom at chef.io>)
+# Copyright:: Copyright (c) 2015 Chef, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+module Mixlib
+ class Install
+ class Util
+ class << self
+ # @return [String] a pretty/helpful representation of a Chef Omnibus
+ # package version
+ # @api private
+ def pretty_version(version)
+ case version
+ when "true" then "install only if missing"
+ when "latest" then "always install latest version"
+ else version
+ end
+ end
+
+ # Builds a complete command given a variables String preamble and a file
+ # containing shell code.
+ #
+ # @param vars [String] shell variables, as a String
+ # @param file [String] file basename (without extension) containing
+ # shell code
+ # @param powershell [Boolean] for powershell
+ # @return [String] command
+ # @api private
+ 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
+
+ # Wraps a body of shell code with common context appropriate for the type
+ # of shell.
+ #
+ # @param code [String] the shell code to be wrapped
+ # @param opts [Hash] options
+ # @param opts[:http_proxy] [String] http proxy url
+ # @param opts[:https_proxy] [String] https proxy url
+ # @return [String] wrapped shell code
+ # @api private
+ 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
+
+ # Builds a shell environment variable assignment string for the
+ # required shell type.
+ #
+ # @param name [String] variable name
+ # @param value [String] variable value
+ # @return [String] shell variable assignment
+ # @api private
+ 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
+
+ # Builds a shell variable assignment string for the required shell type.
+ #
+ # @param name [String] variable name
+ # @param value [String] variable value
+ # @param powershell [Boolean] for powershell
+ # @return [String] shell variable assignment
+ def shell_var(name, value, powershell = false)
+ if powershell
+ %{$#{name} = "#{value}"}
+ else
+ %{#{name}="#{value}"}
+ end
+ end
+
+ # 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.
+ #
+ # @param [String] the command
+ # @return [String] a wrapped command string
+ 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
+
+ end
+ end
+ end
+end
diff --git a/lib/mixlib/install/version.rb b/lib/mixlib/install/version.rb
new file mode 100644
index 0000000..9007f28
--- /dev/null
+++ b/lib/mixlib/install/version.rb
@@ -0,0 +1,5 @@
+module Mixlib
+ class Install
+ VERSION = "0.7.1"
+ end
+end
diff --git a/metadata.yml b/metadata.yml
new file mode 100644
index 0000000..9a75bc3
--- /dev/null
+++ b/metadata.yml
@@ -0,0 +1,101 @@
+--- !ruby/object:Gem::Specification
+name: mixlib-install
+version: !ruby/object:Gem::Version
+ version: 0.7.1
+platform: ruby
+authors:
+- Thom May
+autorequire:
+bindir: bin
+cert_chain: []
+date: 2016-01-19 00:00:00.000000000 Z
+dependencies:
+- !ruby/object:Gem::Dependency
+ name: bundler
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: '0'
+ type: :development
+ prerelease: false
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: '0'
+- !ruby/object:Gem::Dependency
+ name: rake
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
+ - - "~>"
+ - !ruby/object:Gem::Version
+ version: '10.0'
+ type: :development
+ prerelease: false
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - "~>"
+ - !ruby/object:Gem::Version
+ version: '10.0'
+- !ruby/object:Gem::Dependency
+ name: rspec
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
+ - - "~>"
+ - !ruby/object:Gem::Version
+ version: '3.3'
+ type: :development
+ prerelease: false
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - "~>"
+ - !ruby/object:Gem::Version
+ version: '3.3'
+description:
+email:
+- thom at chef.io
+executables: []
+extensions: []
+extra_rdoc_files: []
+files:
+- ".gitignore"
+- ".rspec"
+- ".rubocop.yml"
+- ".travis.yml"
+- Gemfile
+- LICENSE
+- README.md
+- Rakefile
+- lib/mixlib/install.rb
+- lib/mixlib/install/util.rb
+- lib/mixlib/install/version.rb
+- mixlib-install.gemspec
+- support/install_command.ps1
+- support/install_command.sh
+homepage: https://chef.io
+licenses:
+- Apache-2.0
+metadata: {}
+post_install_message:
+rdoc_options: []
+require_paths:
+- lib
+required_ruby_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: '0'
+required_rubygems_version: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: '0'
+requirements: []
+rubyforge_project:
+rubygems_version: 2.4.8
+signing_key:
+specification_version: 4
+summary: A mixin to help with omnitruck installs
+test_files: []
+has_rdoc:
diff --git a/mixlib-install.gemspec b/mixlib-install.gemspec
new file mode 100644
index 0000000..a805b93
--- /dev/null
+++ b/mixlib-install.gemspec
@@ -0,0 +1,25 @@
+# coding: utf-8
+lib = File.expand_path("../lib", __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+require "mixlib/install/version"
+
+Gem::Specification.new do |spec|
+ spec.name = "mixlib-install"
+ spec.version = Mixlib::Install::VERSION
+ spec.authors = ["Thom May"]
+ spec.email = ["thom at chef.io"]
+ spec.license = "Apache-2.0"
+
+ spec.summary = "A mixin to help with omnitruck installs"
+ spec.homepage = "https://chef.io"
+
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
+ spec.require_paths = ["lib"]
+
+ # spec.required_ruby_version = ">= 2.0.0"
+
+ spec.add_development_dependency "bundler"
+ spec.add_development_dependency "rake", "~> 10.0"
+ spec.add_development_dependency "rspec", "~> 3.3"
+end
diff --git a/support/install_command.ps1 b/support/install_command.ps1
new file mode 100644
index 0000000..345b1a0
--- /dev/null
+++ b/support/install_command.ps1
@@ -0,0 +1,84 @@
+Function Check-UpdateChef($root, $version) {
+ if (-Not (Test-Path $root)) { return $true }
+ elseif ("$version" -eq "true") { return $false }
+ elseif ("$version" -eq "latest") { return $true }
+
+ Try { $chef_version = (Get-Content $root\version-manifest.txt | select-object -first 1) }
+ Catch {
+ Try { $chef_version = (& $root\bin\chef-solo.bat -v) }
+ Catch { $chef_version = " " }
+ }
+
+ if ($chef_version.split(" ", 2)[1].StartsWith($version)) { return $false }
+ else { return $true }
+}
+
+Function Get-ChefMetadata($url) {
+ Try { $response = ($c = Make-WebClient).DownloadString($url) }
+ Finally { if ($c -ne $null) { $c.Dispose() } }
+
+ $md = ConvertFrom-StringData $response.Replace("`t", "=")
+ return @($md.url, $md.md5)
+}
+
+Function Get-MD5Sum($src) {
+ Try {
+ $c = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
+ $bytes = $c.ComputeHash(($in = (Get-Item $src).OpenRead()))
+ return ([System.BitConverter]::ToString($bytes)).Replace("-", "").ToLower()
+ } Finally { if (($c -ne $null) -and ($c.GetType().GetMethod("Dispose") -ne $null)) { $c.Dispose() }; if ($in -ne $null) { $in.Dispose() } }
+}
+
+Function Download-Chef($url, $md5, $dst) {
+ Try {
+ Log "Downloading package from $url"
+ ($c = Make-WebClient).DownloadFile($url, $dst)
+ Log "Download complete."
+ } Finally { if ($c -ne $null) { $c.Dispose() } }
+
+ if ($md5 -eq $null) { Log "Skipping md5 verification" }
+ elseif (($dmd5 = Get-MD5Sum $dst) -eq $md5) { Log "Successfully verified $dst" }
+ else { throw "MD5 for $dst $dmd5 does not match $md5" }
+}
+
+Function Install-Chef($msi) {
+ Log "Installing Chef Omnibus package $msi"
+ $p = Start-Process -FilePath "msiexec.exe" -ArgumentList "/qn /i $msi" -Passthru -Wait
+
+ if ($p.ExitCode -ne 0) { throw "msiexec was not successful. Received exit code $($p.ExitCode)" }
+
+ Remove-Item $msi -Force
+ Log "Installation complete"
+}
+
+Function Log($m) { Write-Host " $m`n" }
+
+Function Make-WebClient {
+ $proxy = New-Object -TypeName System.Net.WebProxy
+ $proxy.Address = $env:http_proxy
+ $client = New-Object -TypeName System.Net.WebClient
+ $client.Proxy = $proxy
+ return $client
+}
+
+Function Unresolve-Path($p) {
+ if ($p -eq $null) { return $null }
+ else { return $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($p) }
+}
+
+$chef_omnibus_root = Unresolve-Path $chef_omnibus_root
+$msi = Unresolve-Path $msi
+
+if (Check-UpdateChef $chef_omnibus_root $version) {
+ Write-Host "-----> Installing Chef Omnibus ($pretty_version)`n"
+ if ($chef_metadata_url -ne $null) {
+ $url, $md5 = Get-ChefMetadata "$chef_metadata_url"
+ } else {
+ $url = $chef_msi_url
+ $md5 = $null
+ }
+ Download-Chef "$url" $md5 $msi
+ Install-Chef $msi
+} else {
+ Write-Host "-----> Chef Omnibus installation detected ($pretty_version)`n"
+}
diff --git a/support/install_command.sh b/support/install_command.sh
new file mode 100644
index 0000000..505e7b0
--- /dev/null
+++ b/support/install_command.sh
@@ -0,0 +1,229 @@
+tmp_stderr="/tmp/stderr";
+
+# capture_tmp_stderr SOURCE
+capture_tmp_stderr() {
+ # spool up $tmp_stderr from all the commands we called
+ if test -f "$tmp_stderr"; then
+ output="`cat $tmp_stderr`";
+ stderr_results="${stderr_results}\nSTDERR from $1:\n\n${output}\n";
+ rm $tmp_stderr;
+ fi
+}
+
+# do_curl URL FILENAME
+do_curl() {
+ echo "Trying curl...";
+ curl -sL -D "$tmp_stderr" "$1" > "$2";
+ ec=$?;
+ # check for 404
+ grep "404 Not Found" "$tmp_stderr" 2>&1 >/dev/null;
+ if test $? -eq 0; then
+ http_404_error "$1";
+ fi
+
+ # check for bad return status or empty output
+ if test $ec -ne 0 || test ! -s "$2"; then
+ capture_tmp_stderr "curl";
+ return 1;
+ else
+ echo "Download complete.";
+ return 0;
+ fi
+}
+
+# do_download URL FILENAME
+do_download() {
+ echo "Downloading ${1} to file ${2}";
+
+ exists wget;
+ if test $? -eq 0; then
+ do_wget "$1" "$2" && return 0;
+ fi
+
+ exists curl;
+ if test $? -eq 0; then
+ do_curl "$1" "$2" && return 0;
+ fi
+
+ exists fetch;
+ if test $? -eq 0; then
+ do_fetch "$1" "$2" && return 0;
+ fi
+
+ exists python;
+ if test $? -eq 0; then
+ do_python "$1" "$2" && return 0;
+ fi
+
+ exists perl;
+ if test $? -eq 0; then
+ do_perl "$1" "$2" && return 0;
+ fi
+
+ unable_to_download "$1" "$2";
+}
+
+# do_fetch URL FILENAME
+do_fetch() {
+ echo "Trying fetch...";
+ fetch -o "$2" "$1" 2>"$tmp_stderr";
+ ec=$?;
+ # check for 404
+ grep "Not Found" "$tmp_stderr" 2>&1 >/dev/null;
+ if test $? -eq 0; then
+ http_404_error "$1";
+ fi
+
+ # check for bad return status or empty output
+ if test $ec -ne 0 || test ! -s "$2"; then
+ capture_tmp_stderr "fetch";
+ return 1;
+ else
+ echo "Download complete.";
+ return 0;
+ fi
+}
+
+# do_perl URL FILENAME
+do_perl() {
+ echo "Trying perl...";
+ perl -e "use LWP::Simple; getprint(\$ARGV[0]);" "$1" > "$2" 2>"$tmp_stderr";
+ ec=$?;
+ # check for 404
+ grep "404 Not Found" "$tmp_stderr" 2>&1 >/dev/null;
+ if test $? -eq 0; then
+ http_404_error "$1";
+ fi
+
+ # check for bad return status or empty output
+ if test $ec -ne 0 || test ! -s "$2"; then
+ capture_tmp_stderr "perl";
+ return 1;
+ else
+ echo "Download complete.";
+ return 0;
+ fi
+}
+
+# do_python URL FILENAME
+do_python() {
+ echo "Trying python...";
+ python -c "import sys,urllib2 ; sys.stdout.write(urllib2.urlopen(sys.argv[1]).read())" "$1" > "$2" 2>"$tmp_stderr";
+ ec=$?;
+ # check for 404
+ grep "HTTP Error 404" "$tmp_stderr" 2>&1 >/dev/null;
+ if test $? -eq 0; then
+ http_404_error "$1";
+ fi
+
+ # check for bad return status or empty output
+ if test $ec -ne 0 || test ! -s "$2"; then
+ capture_tmp_stderr "python";
+ return 1;
+ else
+ echo "Download complete.";
+ return 0;
+ fi
+}
+
+# do_wget URL FILENAME
+do_wget() {
+ echo "Trying wget...";
+ wget -O "$2" "$1" 2>"$tmp_stderr";
+ ec=$?;
+ # check for 404
+ grep "ERROR 404" "$tmp_stderr" 2>&1 >/dev/null;
+ if test $? -eq 0; then
+ http_404_error "$1";
+ fi
+
+ # check for bad return status or empty output
+ if test $ec -ne 0 || test ! -s "$2"; then
+ capture_tmp_stderr "wget";
+ return 1;
+ else
+ echo "Download complete.";
+ return 0;
+ fi
+}
+
+# exists COMMAND
+exists() {
+ if command -v "$1" >/dev/null 2>&1; then
+ return 0;
+ else
+ return 1;
+ fi
+}
+
+# http_404_error URL
+http_404_error() {
+ echo ">>>>>> Downloading ${1} resulted in an HTTP/404, aborting";
+ exit 40;
+}
+
+# should_update_chef ROOT VERSION
+should_update_chef() {
+ if test ! -d "$1"; then
+ return 0;
+ elif test "$2" = "true"; then
+ return 1;
+ elif test "$2" = "latest"; then
+ return 0;
+ fi
+
+ if test -f "${1}/version-manifest.txt"; then
+ chef_version="`head -n 1 ${1}/version-manifest.txt | cut -d \" \" -f 2`";
+ else
+ chef_version="`${1}/bin/chef-solo -v | cut -d \" \" -f 2`";
+ fi
+
+ echo "$chef_version" | grep "^${2}" 2>&1 >/dev/null;
+ if test $? -eq 0; then
+ return 1;
+ else
+ echo "${2}" | grep "^$chef_version" 2>&1 >/dev/null;
+ if test $? -eq 0; then
+ return 1;
+ else
+ return 0;
+ fi
+ fi
+}
+
+# unable_to_download URL FILE
+unable_to_download() {
+ echo "Unable to download $1 to $2, aborting";
+
+ if test "x${stderr_results}" != "x"; then
+ echo "\nDEBUG OUTPUT FOLLOWS:\n${stderr_results}";
+ fi
+
+ exit 10;
+}
+
+# main
+main() {
+ should_update_chef "$chef_omnibus_root" "$version"
+ if test $? -eq 0; then
+ echo "-----> Installing Chef Omnibus (${pretty_version})";
+
+ # solaris 10 lacks recent enough credentials, so http url is used
+ platform="`/usr/bin/uname -s 2>/dev/null`";
+ platform_version="`/usr/bin/uname -r 2>/dev/null`";
+ if test "x${platform}" = "xSunOS" && test "x${platform_version}" = "x5.10"; then
+ chef_omnibus_url=`echo "$chef_omnibus_url" | sed -e "s/https/http/"`;
+ fi
+
+ do_download "$chef_omnibus_url" /tmp/install.sh;
+ $sudo_sh /tmp/install.sh $install_flags;
+ else
+ echo "-----> Chef Omnibus installation detected (${pretty_version})";
+ fi
+}
+
+# augment path in an attempt to find a download program
+PATH="${PATH}:/opt/local/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/sfw/bin";
+export PATH;
+
+main
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-mixlib-install.git
More information about the Pkg-ruby-extras-commits
mailing list