mixlib-install 0.8.0.alpha.2 → 0.8.0.alpha.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -2
- data/Rakefile +5 -0
- data/acceptance/Gemfile +3 -1
- data/acceptance/Gemfile.lock +37 -5
- data/acceptance/current/.acceptance/acceptance-cookbook/recipes/provision.rb +3 -1
- data/acceptance/current/.kitchen.yml +18 -23
- data/acceptance/unstable/.acceptance/acceptance-cookbook/.gitignore +2 -0
- data/acceptance/unstable/.acceptance/acceptance-cookbook/metadata.rb +1 -0
- data/acceptance/unstable/.acceptance/acceptance-cookbook/recipes/destroy.rb +3 -0
- data/acceptance/unstable/.acceptance/acceptance-cookbook/recipes/provision.rb +3 -0
- data/acceptance/unstable/.acceptance/acceptance-cookbook/recipes/verify.rb +3 -0
- data/acceptance/unstable/.kitchen.yml +40 -0
- data/lib/mixlib/install.rb +35 -3
- data/lib/mixlib/install/backend/artifactory.rb +108 -34
- data/lib/mixlib/install/backend/omnitruck.rb +2 -2
- data/lib/mixlib/install/generator.rb +6 -1
- data/lib/mixlib/install/generator/base.rb +65 -0
- data/lib/mixlib/install/generator/bourne.rb +23 -14
- data/lib/mixlib/install/generator/bourne/scripts/artifactory_urls.sh.erb +31 -0
- data/lib/mixlib/install/generator/bourne/scripts/{fetch_metadata.sh → fetch_metadata.sh.erb} +1 -1
- data/lib/mixlib/install/generator/bourne/scripts/helpers.sh +7 -2
- data/lib/mixlib/install/generator/bourne/scripts/platform_detection.sh +8 -0
- data/lib/mixlib/install/generator/bourne/scripts/script_cli_parameters.sh +36 -0
- data/lib/mixlib/install/generator/powershell.rb +94 -0
- data/lib/mixlib/install/generator/powershell/scripts/get_project_metadata.ps1.erb +87 -0
- data/lib/mixlib/install/generator/powershell/scripts/get_project_metadata_for_artifactory.ps1.erb +83 -0
- data/lib/mixlib/install/generator/powershell/scripts/helpers.ps1 +69 -0
- data/lib/mixlib/install/generator/powershell/scripts/install_project.ps1 +96 -0
- data/lib/mixlib/install/options.rb +86 -23
- data/lib/mixlib/install/version.rb +1 -1
- metadata +17 -4
@@ -24,7 +24,7 @@ module Mixlib
|
|
24
24
|
class Install
|
25
25
|
class Backend
|
26
26
|
class Omnitruck
|
27
|
-
|
27
|
+
ENDPOINT = "https://omnitruck.chef.io/".freeze
|
28
28
|
|
29
29
|
attr_accessor :options
|
30
30
|
|
@@ -55,7 +55,7 @@ module Mixlib
|
|
55
55
|
private
|
56
56
|
|
57
57
|
def omnitruck_get(resource, parameters)
|
58
|
-
uri = URI.parse(
|
58
|
+
uri = URI.parse(ENDPOINT)
|
59
59
|
http = Net::HTTP.new(uri.host, uri.port)
|
60
60
|
http.use_ssl = (uri.scheme == "https")
|
61
61
|
|
@@ -16,12 +16,17 @@
|
|
16
16
|
#
|
17
17
|
|
18
18
|
require "mixlib/install/generator/bourne"
|
19
|
+
require "mixlib/install/generator/powershell"
|
19
20
|
|
20
21
|
module Mixlib
|
21
22
|
class Install
|
22
23
|
class Generator
|
23
24
|
def self.install_command(options)
|
24
|
-
|
25
|
+
if options.for_ps1?
|
26
|
+
PowerShell.new(options).install_command
|
27
|
+
else
|
28
|
+
Bourne.new(options).install_command
|
29
|
+
end
|
25
30
|
end
|
26
31
|
end
|
27
32
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2015 Chef, Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "erb"
|
19
|
+
require "ostruct"
|
20
|
+
require "mixlib/install/backend/omnitruck"
|
21
|
+
|
22
|
+
module Mixlib
|
23
|
+
class Install
|
24
|
+
class Generator
|
25
|
+
class Base
|
26
|
+
attr_reader :options
|
27
|
+
|
28
|
+
def initialize(options)
|
29
|
+
@options = options
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Returns the base path where the script fragments are located for
|
34
|
+
# the generator as a String.
|
35
|
+
#
|
36
|
+
def self.script_base_path
|
37
|
+
raise "You must define a script_base_path for your Generator::Base class."
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Gets the contents of the given script.
|
42
|
+
#
|
43
|
+
def self.get_script(name, context = {})
|
44
|
+
script_path = File.join(script_base_path, name)
|
45
|
+
|
46
|
+
# If there is an erb template we render it, otherwise we just read
|
47
|
+
# and returnt the contents of the script
|
48
|
+
if File.exist? "#{script_path}.erb"
|
49
|
+
# Default values to use incase they are not set in the context
|
50
|
+
context[:base_url] ||= Mixlib::Install::Backend::Omnitruck::ENDPOINT
|
51
|
+
|
52
|
+
context_object = OpenStruct.new(context).instance_eval { binding }
|
53
|
+
ERB.new(File.read("#{script_path}.erb")).result(context_object)
|
54
|
+
else
|
55
|
+
File.read(script_path)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_script(name, context = {})
|
60
|
+
self.class.get_script(name, context)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -15,28 +15,40 @@
|
|
15
15
|
# limitations under the License.
|
16
16
|
#
|
17
17
|
|
18
|
+
require "mixlib/install/generator/base"
|
19
|
+
require "mixlib/install/backend/artifactory"
|
20
|
+
|
18
21
|
module Mixlib
|
19
22
|
class Install
|
20
23
|
class Generator
|
21
|
-
class Bourne
|
22
|
-
|
24
|
+
class Bourne < Base
|
25
|
+
def self.install_sh(context)
|
26
|
+
install_command = []
|
27
|
+
install_command << get_script("helpers.sh")
|
28
|
+
install_command << get_script("script_cli_parameters.sh")
|
29
|
+
install_command << get_script("platform_detection.sh")
|
30
|
+
install_command << get_script("fetch_metadata.sh", context)
|
31
|
+
install_command << get_script("fetch_package.sh")
|
32
|
+
install_command << get_script("install_package.sh")
|
33
|
+
install_command.join("\n\n")
|
34
|
+
end
|
23
35
|
|
24
|
-
def
|
25
|
-
|
36
|
+
def self.script_base_path
|
37
|
+
File.join(File.dirname(__FILE__), "bourne/scripts")
|
26
38
|
end
|
27
39
|
|
28
40
|
def install_command
|
29
41
|
install_command = []
|
30
|
-
install_command << get_script(
|
42
|
+
install_command << get_script("helpers.sh")
|
31
43
|
install_command << render_variables
|
32
|
-
install_command << get_script(
|
44
|
+
install_command << get_script("platform_detection.sh")
|
33
45
|
if options.for_artifactory?
|
34
46
|
install_command << artifactory_urls
|
35
47
|
else
|
36
|
-
install_command << get_script(
|
48
|
+
install_command << get_script("fetch_metadata.sh")
|
37
49
|
end
|
38
|
-
install_command << get_script(
|
39
|
-
install_command << get_script(
|
50
|
+
install_command << get_script("fetch_package.sh")
|
51
|
+
install_command << get_script("install_package.sh")
|
40
52
|
|
41
53
|
install_command.join("\n\n")
|
42
54
|
end
|
@@ -50,11 +62,8 @@ EOS
|
|
50
62
|
end
|
51
63
|
|
52
64
|
def artifactory_urls
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
def get_script(name)
|
57
|
-
File.read(File.join(File.dirname(__FILE__), "bourne/scripts/#{name}.sh"))
|
65
|
+
artifacts = Mixlib::Install::Backend::Artifactory.new(options).info
|
66
|
+
get_script("artifactory_urls.sh", artifacts: artifacts)
|
58
67
|
end
|
59
68
|
end
|
60
69
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# artifactory_urls.sh
|
2
|
+
############
|
3
|
+
# This section sets up the information for a build to be installed from artifactory
|
4
|
+
# then uses $platform, $platform_version and $machine to select the correct
|
5
|
+
# version.
|
6
|
+
#
|
7
|
+
# Inputs:
|
8
|
+
# $platform:
|
9
|
+
# $platform_version:
|
10
|
+
# $machine:
|
11
|
+
#
|
12
|
+
# Outputs:
|
13
|
+
# $download_url:
|
14
|
+
# $sha256:
|
15
|
+
# $md5:
|
16
|
+
############
|
17
|
+
|
18
|
+
<% artifacts.each do |artifact| %>
|
19
|
+
artifact_info_dir="$tmp_dir/artifact_info/<%= File.join(artifact.platform, artifact.platform_version, artifact.architecture)%>"
|
20
|
+
mkdir -p $artifact_info_dir
|
21
|
+
touch "$artifact_info_dir/artifact_info"
|
22
|
+
echo "url <%= artifact.url%>" >> "$artifact_info_dir/artifact_info"
|
23
|
+
echo "md5 <%= artifact.md5%>" >> "$artifact_info_dir/artifact_info"
|
24
|
+
echo "sha256 <%= artifact.sha256%>" >> "$artifact_info_dir/artifact_info"
|
25
|
+
<% end %>
|
26
|
+
|
27
|
+
artifact_info_for_platform="$tmp_dir/artifact_info/$platform/$platform_version/$machine/artifact_info"
|
28
|
+
|
29
|
+
download_url=`awk '$1 == "url" { print $2 }' "$artifact_info_for_platform"`
|
30
|
+
sha256=`awk '$1 == "sha256" { print $2 }' "$artifact_info_for_platform"`
|
31
|
+
md5=`awk '$1 == "md5" { print $2 }' "$artifact_info_for_platform"`
|
data/lib/mixlib/install/generator/bourne/scripts/{fetch_metadata.sh → fetch_metadata.sh.erb}
RENAMED
@@ -21,7 +21,7 @@
|
|
21
21
|
echo "Getting information for $project $channel $version for $platform..."
|
22
22
|
|
23
23
|
metadata_filename="$tmp_dir/metadata.txt"
|
24
|
-
metadata_url="
|
24
|
+
metadata_url="<%= base_url %>$channel/$project/metadata?v=$version&p=$platform&pv=$platform_version&m=$machine"
|
25
25
|
|
26
26
|
do_download "$metadata_url" "$metadata_filename"
|
27
27
|
|
@@ -274,8 +274,13 @@ install_file() {
|
|
274
274
|
echo "Installing $project $version"
|
275
275
|
case "$1" in
|
276
276
|
"rpm")
|
277
|
-
|
278
|
-
|
277
|
+
if test "x$platform" = "xnexus" || test "x$platform" = "xios_xr"; then
|
278
|
+
echo "installing with yum..."
|
279
|
+
yum install -yv "$2"
|
280
|
+
else
|
281
|
+
echo "installing with rpm..."
|
282
|
+
rpm -Uvh --oldpackage --replacepkgs "$2"
|
283
|
+
fi
|
279
284
|
;;
|
280
285
|
"deb")
|
281
286
|
echo "installing with dpkg..."
|
@@ -96,6 +96,14 @@ elif test "x$os" = "xAIX"; then
|
|
96
96
|
platform="aix"
|
97
97
|
platform_version="`uname -v`.`uname -r`"
|
98
98
|
machine="powerpc"
|
99
|
+
elif test -f "/etc/os-release"; then
|
100
|
+
. /etc/os-release
|
101
|
+
if test "x$CISCO_RELEASE_INFO" != "x"; then
|
102
|
+
. $CISCO_RELEASE_INFO
|
103
|
+
fi
|
104
|
+
|
105
|
+
platform=$ID
|
106
|
+
platform_version=$VERSION
|
99
107
|
fi
|
100
108
|
|
101
109
|
if test "x$platform" = "x"; then
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# script_cli_parameters.sh
|
2
|
+
############
|
3
|
+
# This section reads the CLI parameters for the install script and translates
|
4
|
+
# them to the local parameters to be used later by the script.
|
5
|
+
#
|
6
|
+
# Outputs:
|
7
|
+
# $version: Requested version to be installed.
|
8
|
+
# $channel: Channel to install the product from
|
9
|
+
# $project: Project to be installed
|
10
|
+
# $cmdline_filename: Name of the package downloaded on local disk.
|
11
|
+
# $cmdline_dl_dir: Name of the directory downloaded package will be saved to on local disk.
|
12
|
+
############
|
13
|
+
|
14
|
+
# Defaults
|
15
|
+
channel="stable"
|
16
|
+
project="chef"
|
17
|
+
|
18
|
+
while getopts pnv:c:f:P:d: opt
|
19
|
+
do
|
20
|
+
case "$opt" in
|
21
|
+
|
22
|
+
v) version="$OPTARG";;
|
23
|
+
c) channel="$OPTARG";;
|
24
|
+
p) channel="current";; # compat for prerelease option
|
25
|
+
n) channel="current";; # compat for nightlies option
|
26
|
+
f) cmdline_filename="$OPTARG";;
|
27
|
+
P) project="$OPTARG";;
|
28
|
+
d) cmdline_dl_dir="$OPTARG";;
|
29
|
+
\?) # unknown flag
|
30
|
+
echo >&2 \
|
31
|
+
"usage: $0 [-P project] [-c release_channel] [-v version] [-f filename | -d download_dir]"
|
32
|
+
exit 1;;
|
33
|
+
esac
|
34
|
+
done
|
35
|
+
|
36
|
+
shift `expr $OPTIND - 1`
|
@@ -0,0 +1,94 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2015 Chef, Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "mixlib/install/generator/base"
|
19
|
+
|
20
|
+
module Mixlib
|
21
|
+
class Install
|
22
|
+
class Generator
|
23
|
+
class PowerShell < Base
|
24
|
+
def self.install_ps1(context)
|
25
|
+
install_project_module = []
|
26
|
+
install_project_module << get_script("helpers.ps1")
|
27
|
+
install_project_module << get_script("get_project_metadata.ps1", context)
|
28
|
+
install_project_module << get_script("install_project.ps1")
|
29
|
+
|
30
|
+
install_command = []
|
31
|
+
install_command << ps1_modularize(install_project_module.join("\n"), "Omnitruck")
|
32
|
+
install_command.join("\n\n")
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.script_base_path
|
36
|
+
File.join(File.dirname(__FILE__), "powershell/scripts")
|
37
|
+
end
|
38
|
+
|
39
|
+
def install_command
|
40
|
+
install_project_module = []
|
41
|
+
install_project_module << get_script("helpers.ps1")
|
42
|
+
install_project_module << if options.for_artifactory?
|
43
|
+
artifactory_urls
|
44
|
+
else
|
45
|
+
get_script("get_project_metadata.ps1")
|
46
|
+
end
|
47
|
+
install_project_module << get_script("install_project.ps1")
|
48
|
+
|
49
|
+
install_command = []
|
50
|
+
install_command << ps1_modularize(install_project_module.join("\n"), "Omnitruck")
|
51
|
+
install_command << render_command
|
52
|
+
install_command.join("\n\n")
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.ps1_modularize(module_body, module_name)
|
56
|
+
ps1_module = []
|
57
|
+
ps1_module << "new-module -name #{module_name} -scriptblock {"
|
58
|
+
ps1_module << module_body
|
59
|
+
ps1_module << "}"
|
60
|
+
ps1_module.join("\n")
|
61
|
+
end
|
62
|
+
|
63
|
+
def ps1_modularize(module_body, module_name)
|
64
|
+
self.class.ps1_modularize(module_body, module_name)
|
65
|
+
end
|
66
|
+
|
67
|
+
def artifactory_urls
|
68
|
+
get_script("get_project_metadata_for_artifactory.ps1",
|
69
|
+
artifacts: artifacts)
|
70
|
+
end
|
71
|
+
|
72
|
+
def artifacts
|
73
|
+
@artifacts ||= Mixlib::Install::Backend::Artifactory.new(options).info
|
74
|
+
end
|
75
|
+
|
76
|
+
def product_version
|
77
|
+
if options.for_artifactory?
|
78
|
+
options.resolved_version(artifacts)
|
79
|
+
else
|
80
|
+
options.product_version
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def render_command
|
85
|
+
<<EOS
|
86
|
+
install -project #{options.product_name} \
|
87
|
+
-version #{product_version} \
|
88
|
+
-channel #{options.channel}
|
89
|
+
EOS
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
function Get-ProjectMetadata {
|
2
|
+
<#
|
3
|
+
.SYNOPSIS
|
4
|
+
Get metadata for a Chef Software, Inc. project
|
5
|
+
.DESCRIPTION
|
6
|
+
Get metadata for project
|
7
|
+
.EXAMPLE
|
8
|
+
iex (new-object net.webclient).downloadstring('https:/omnitruck.chef.io/install.ps1'); Get-ProjectMetadata -project chef -channel stable
|
9
|
+
|
10
|
+
Gets the download url, MD5 checksum, and SHA256 checksum for the latest stable release of Chef.
|
11
|
+
.EXAMPLE
|
12
|
+
iex (irm 'https://omnitruck.chef.io/install.ps1'); Get-ProjectMetadata -project chefdk -channel stable -version 0.8.0
|
13
|
+
|
14
|
+
Gets the download url, MD5 checksum, and SHA256 checksum for ChefDK 0.8.0.
|
15
|
+
#>
|
16
|
+
[cmdletbinding()]
|
17
|
+
param (
|
18
|
+
# Base url to retrieve metadata from.
|
19
|
+
[uri]$base_server_uri = '<%= base_url %>',
|
20
|
+
[string]
|
21
|
+
# Project to install
|
22
|
+
# chef - Chef Client
|
23
|
+
# chefdk - Chef Development Kit
|
24
|
+
# angrychef - AngryChef
|
25
|
+
# server and container are not valid windows targets
|
26
|
+
[validateset('chef', 'chefdk', 'angrychef')]
|
27
|
+
[string]
|
28
|
+
$project = 'chef',
|
29
|
+
# Version of the application to install
|
30
|
+
# This parameter is optional, if not supplied it will provide the latest version,
|
31
|
+
# and if an iteration number is not specified, it will grab the latest available iteration.
|
32
|
+
# Partial version numbers are also acceptable (using v=11
|
33
|
+
# will grab the latest 11.x client which matches the other flags).
|
34
|
+
[string]
|
35
|
+
$version,
|
36
|
+
# Release channel to install from
|
37
|
+
[validateset('current', 'stable')]
|
38
|
+
[string]
|
39
|
+
$channel = 'stable',
|
40
|
+
# The following legacy switches are just aliases for the current channel
|
41
|
+
[switch]
|
42
|
+
$prerelease,
|
43
|
+
[switch]
|
44
|
+
$nightlies
|
45
|
+
)
|
46
|
+
|
47
|
+
# The following legacy switches are just aliases for the current channel
|
48
|
+
if (($prerelease -eq $true)) { $channel = 'current'}
|
49
|
+
if (($nightlies -eq $true)) { $channel = 'current'}
|
50
|
+
|
51
|
+
# PowerShell is only on Windows ATM
|
52
|
+
$platform = 'windows'
|
53
|
+
Write-Verbose "Platform: $platform"
|
54
|
+
|
55
|
+
# TODO: No Win10 build endpoint yet
|
56
|
+
switch -regex ((get-wmiobject win32_operatingsystem).version) {
|
57
|
+
'10\.0\.\d+' {$platform_version = '2012r2'}
|
58
|
+
'6\.3\.\d+' {$platform_version = '2012r2'}
|
59
|
+
'6\.2\.\d+' {$platform_version = '2012'}
|
60
|
+
'6\.1\.\d+' {$platform_version = '2008r2'}
|
61
|
+
'6\.0\.\d+' {$platform_version = '2008'}
|
62
|
+
}
|
63
|
+
Write-Verbose "Platform Version: $platform_version"
|
64
|
+
|
65
|
+
# TODO: When we ship a 64 bit ruby for Windows.
|
66
|
+
$machine = 'x86_64'
|
67
|
+
Write-Verbose "Machine: $machine"
|
68
|
+
Write-Verbose "Project: $project"
|
69
|
+
|
70
|
+
$metadata_base_url = "$($channel)/$($project)/metadata"
|
71
|
+
$metadata_array = ("?v=$($version)",
|
72
|
+
"p=$platform",
|
73
|
+
"pv=$platform_version",
|
74
|
+
"m=$machine")
|
75
|
+
$metadata_base_url += [string]::join('&', $metadata_array)
|
76
|
+
$metadata_url = new-uri $base_server_uri $metadata_base_url
|
77
|
+
|
78
|
+
Write-Verbose "Downloading $project details from $metadata_url"
|
79
|
+
$package_metadata = (Get-WebContent $metadata_url).trim() -split '\n' |
|
80
|
+
foreach { $hash = @{} } {$key, $value = $_ -split '\s+'; $hash.Add($key, $value)} {$hash}
|
81
|
+
|
82
|
+
Write-Verbose "Project details: "
|
83
|
+
foreach ($key in $package_metadata.keys) {
|
84
|
+
Write-Verbose "`t$key = $($package_metadata[$key])"
|
85
|
+
}
|
86
|
+
$package_metadata
|
87
|
+
}
|