from-scratch 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.chef/knife.rb +6 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Berksfile +17 -0
- data/Berksfile.lock +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +6 -0
- data/Thorfile +5 -0
- data/bin/scratchify +6 -0
- data/chefignore +101 -0
- data/cookbooks/chef_gem/CHANGELOG.md +24 -0
- data/cookbooks/chef_gem/README.md +38 -0
- data/cookbooks/chef_gem/libraries/chef_gem.rb +72 -0
- data/cookbooks/chef_gem/metadata.json +29 -0
- data/cookbooks/chef_gem/recipes/default.rb +0 -0
- data/cookbooks/java/.gitignore +21 -0
- data/cookbooks/java/.kitchen.docker.yml +15 -0
- data/cookbooks/java/.kitchen.yml +126 -0
- data/cookbooks/java/.travis.yml +6 -0
- data/cookbooks/java/Berksfile +10 -0
- data/cookbooks/java/CHANGELOG.md +398 -0
- data/cookbooks/java/CONTRIBUTING.md +12 -0
- data/cookbooks/java/Gemfile +15 -0
- data/cookbooks/java/ISSUES.md +43 -0
- data/cookbooks/java/LICENSE +201 -0
- data/cookbooks/java/README.md +402 -0
- data/cookbooks/java/Rakefile +60 -0
- data/cookbooks/java/TESTING.md +41 -0
- data/cookbooks/java/attributes/default.rb +146 -0
- data/cookbooks/java/libraries/helpers.rb +120 -0
- data/cookbooks/java/libraries/matchers.rb +5 -0
- data/cookbooks/java/metadata.json +69 -0
- data/cookbooks/java/providers/alternatives.rb +94 -0
- data/cookbooks/java/providers/ark.rb +255 -0
- data/cookbooks/java/recipes/default.rb +22 -0
- data/cookbooks/java/recipes/default_java_symlink.rb +19 -0
- data/cookbooks/java/recipes/homebrew.rb +3 -0
- data/cookbooks/java/recipes/ibm.rb +76 -0
- data/cookbooks/java/recipes/ibm_tar.rb +70 -0
- data/cookbooks/java/recipes/openjdk.rb +74 -0
- data/cookbooks/java/recipes/oracle.rb +74 -0
- data/cookbooks/java/recipes/oracle_i386.rb +73 -0
- data/cookbooks/java/recipes/oracle_jce.rb +75 -0
- data/cookbooks/java/recipes/oracle_rpm.rb +60 -0
- data/cookbooks/java/recipes/purge_packages.rb +20 -0
- data/cookbooks/java/recipes/set_attributes_from_version.rb +55 -0
- data/cookbooks/java/recipes/set_java_home.rb +44 -0
- data/cookbooks/java/recipes/windows.rb +82 -0
- data/cookbooks/java/resources/alternatives.rb +30 -0
- data/cookbooks/java/resources/ark.rb +58 -0
- data/cookbooks/java/templates/default/ibm_jdk.installer.properties.erb +3 -0
- data/cookbooks/java/templates/default/oracle.jinfo.erb +6 -0
- data/cookbooks/rvm/.foodcritic +1 -0
- data/cookbooks/rvm/.gitignore +7 -0
- data/cookbooks/rvm/.kitchen.yml +66 -0
- data/cookbooks/rvm/.travis.yml +9 -0
- data/cookbooks/rvm/Berksfile +10 -0
- data/cookbooks/rvm/CHANGELOG.md +253 -0
- data/cookbooks/rvm/CODE_OF_CONDUCT.md +12 -0
- data/cookbooks/rvm/CONTRIBUTING.md +26 -0
- data/cookbooks/rvm/Gemfile +20 -0
- data/cookbooks/rvm/Guardfile +12 -0
- data/cookbooks/rvm/README.md +1459 -0
- data/cookbooks/rvm/Rakefile +18 -0
- data/cookbooks/rvm/attributes/.gitkeep +0 -0
- data/cookbooks/rvm/attributes/default.rb +68 -0
- data/cookbooks/rvm/attributes/gem_package.rb +23 -0
- data/cookbooks/rvm/attributes/vagrant.rb +23 -0
- data/cookbooks/rvm/libraries/chef_rvm_environment_helpers.rb +55 -0
- data/cookbooks/rvm/libraries/chef_rvm_gemset_helpers.rb +67 -0
- data/cookbooks/rvm/libraries/chef_rvm_recipe_helpers.rb +80 -0
- data/cookbooks/rvm/libraries/chef_rvm_ruby_helpers.rb +95 -0
- data/cookbooks/rvm/libraries/chef_rvm_set_helpers.rb +16 -0
- data/cookbooks/rvm/libraries/chef_rvm_shell_helpers.rb +57 -0
- data/cookbooks/rvm/libraries/chef_rvm_string_cache.rb +104 -0
- data/cookbooks/rvm/libraries/chef_rvm_string_helpers.rb +61 -0
- data/cookbooks/rvm/libraries/chef_rvm_version_helpers.rb +45 -0
- data/cookbooks/rvm/libraries/gem_package_monkeypatch.rb +34 -0
- data/cookbooks/rvm/libraries/provider_rvm_installation.rb +185 -0
- data/cookbooks/rvm/libraries/resource_rvm_installation.rb +103 -0
- data/cookbooks/rvm/libraries/rvm_chef_user_environment.rb +55 -0
- data/cookbooks/rvm/libraries/rvm_rubygems_package.rb +189 -0
- data/cookbooks/rvm/libraries/rvm_shell_chef_wrapper.rb +99 -0
- data/cookbooks/rvm/metadata.json +51 -0
- data/cookbooks/rvm/providers/default_ruby.rb +63 -0
- data/cookbooks/rvm/providers/environment.rb +78 -0
- data/cookbooks/rvm/providers/gemset.rb +118 -0
- data/cookbooks/rvm/providers/global_gem.rb +97 -0
- data/cookbooks/rvm/providers/ruby.rb +178 -0
- data/cookbooks/rvm/providers/shell.rb +121 -0
- data/cookbooks/rvm/providers/wrapper.rb +73 -0
- data/cookbooks/rvm/recipes/.gitkeep +0 -0
- data/cookbooks/rvm/recipes/default.rb +40 -0
- data/cookbooks/rvm/recipes/gem_package.rb +33 -0
- data/cookbooks/rvm/recipes/system.rb +37 -0
- data/cookbooks/rvm/recipes/system_install.rb +42 -0
- data/cookbooks/rvm/recipes/user.rb +43 -0
- data/cookbooks/rvm/recipes/user_install.rb +58 -0
- data/cookbooks/rvm/recipes/vagrant.rb +37 -0
- data/cookbooks/rvm/resources/default_ruby.rb +31 -0
- data/cookbooks/rvm/resources/environment.rb +31 -0
- data/cookbooks/rvm/resources/gem.rb +37 -0
- data/cookbooks/rvm/resources/gemset.rb +32 -0
- data/cookbooks/rvm/resources/global_gem.rb +34 -0
- data/cookbooks/rvm/resources/ruby.rb +32 -0
- data/cookbooks/rvm/resources/shell.rb +41 -0
- data/cookbooks/rvm/resources/wrapper.rb +34 -0
- data/cookbooks/rvm/templates/default/rvmrc.erb +14 -0
- data/cookbooks/rvm/templates/default/vagrant-chef-client-wrapper.erb +23 -0
- data/cookbooks/rvm/templates/default/vagrant-chef-solo-wrapper.erb +23 -0
- data/cookbooks/rvm/test/integration/data_bags/users/virgil1.json +4 -0
- data/cookbooks/rvm/test/integration/data_bags/users/virgil2.json +4 -0
- data/cookbooks/rvm/test/integration/data_bags/users/wigglebottom.json +3 -0
- data/cookbooks/rvm/test/integration/installs/bats/version_pinning.bats +13 -0
- data/cookbooks/rvm/test/integration/rubies/bats/_common.bash +16 -0
- data/cookbooks/rvm/test/integration/rubies/bats/verify_1.9.3.bats +9 -0
- data/cookbooks/rvm/test/integration/rubies/bats/verify_jruby.bats +12 -0
- data/cookbooks/rvm/test/integration/rubies/bats/verify_patch_support.bats +19 -0
- data/cookbooks/rvm/test/integration/rubies/bats/verify_ree.bats +9 -0
- data/cookbooks/rvm/test/integration/rubies/bats/verify_rubygems_version_support.bats +15 -0
- data/cookbooks/rvm/test/integration/stock_system_and_user/bats/system.bats +45 -0
- data/cookbooks/rvm/test/unit/libraries/provider_rvm_installation_spec.rb +220 -0
- data/cookbooks/rvm/test/unit/libraries/resource_rvm_installation_spec.rb +139 -0
- data/cookbooks/rvm/test/unit/spec_helper.rb +23 -0
- data/cookbooks/scratchify/.chef/knife.rb +9 -0
- data/cookbooks/scratchify/Berksfile +16 -0
- data/cookbooks/scratchify/Berksfile.lock +19 -0
- data/cookbooks/scratchify/LICENSE.txt +21 -0
- data/cookbooks/scratchify/README.md +41 -0
- data/cookbooks/scratchify/Thorfile +5 -0
- data/cookbooks/scratchify/bin/console +14 -0
- data/cookbooks/scratchify/bin/scratchify +6 -0
- data/cookbooks/scratchify/bin/setup +7 -0
- data/cookbooks/scratchify/chefignore +101 -0
- data/cookbooks/scratchify/data_bags/users/deploy.json +6 -0
- data/cookbooks/scratchify/environments/.gitkeep +0 -0
- data/cookbooks/scratchify/from-scratch.gemspec +36 -0
- data/cookbooks/scratchify/lib/from/scratch.rb +31 -0
- data/cookbooks/scratchify/lib/from/scratch/interviewer.rb +35 -0
- data/cookbooks/scratchify/lib/from/scratch/version.rb +3 -0
- data/cookbooks/scratchify/metadata.json +36 -0
- data/cookbooks/scratchify/nodes/normfood.ru.json +75 -0
- data/cookbooks/scratchify/recipes/default.rb +0 -0
- data/cookbooks/scratchify/roles/.gitkeep +0 -0
- data/cookbooks/scratchify/spec/from/scratch_spec.rb +11 -0
- data/cookbooks/scratchify/spec/spec_helper.rb +2 -0
- data/cookbooks/user/.gitignore +5 -0
- data/cookbooks/user/.kitchen.yml +46 -0
- data/cookbooks/user/.travis.yml +4 -0
- data/cookbooks/user/Berksfile +7 -0
- data/cookbooks/user/CHANGELOG.md +101 -0
- data/cookbooks/user/Gemfile +14 -0
- data/cookbooks/user/README.md +447 -0
- data/cookbooks/user/Rakefile +21 -0
- data/cookbooks/user/attributes/default.rb +50 -0
- data/cookbooks/user/libraries/matchers.rb +26 -0
- data/cookbooks/user/metadata.json +46 -0
- data/cookbooks/user/providers/account.rb +212 -0
- data/cookbooks/user/recipes/data_bag.rb +59 -0
- data/cookbooks/user/recipes/default.rb +18 -0
- data/cookbooks/user/resources/account.rb +41 -0
- data/cookbooks/user/templates/default/authorized_keys.erb +7 -0
- data/from-scratch.gemspec +33 -0
- data/lib/from-scratch.rb +25 -0
- data/lib/from-scratch/version.rb +3 -0
- data/metadata.rb +15 -0
- data/recipes/default.rb +0 -0
- data/templates/node.json.erb +31 -0
- data/templates/user.json.erb +6 -0
- metadata +330 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
#
|
2
|
+
# Cookbook Name:: rvm
|
3
|
+
# Library:: Chef::RVM::ShellHelpers
|
4
|
+
#
|
5
|
+
# Author:: Fletcher Nichol <fnichol@nichol.ca>
|
6
|
+
#
|
7
|
+
# Copyright 2011, Fletcher Nichol
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
module RVM
|
24
|
+
module ShellHelpers
|
25
|
+
##
|
26
|
+
# Finds the correct shell profile to source to init an RVM-aware
|
27
|
+
# shell environment
|
28
|
+
#
|
29
|
+
# @param [String] a user's home directory path if this is for a user or
|
30
|
+
# nil if it is in a system context
|
31
|
+
# @return [String] full path the shell profile
|
32
|
+
def find_profile_to_source(user_dir = nil)
|
33
|
+
if user_dir
|
34
|
+
"#{user_dir}/.rvm/scripts/rvm"
|
35
|
+
else
|
36
|
+
if ::File.directory?("/etc/profile.d")
|
37
|
+
"/etc/profile.d/rvm.sh"
|
38
|
+
else
|
39
|
+
"/etc/profile"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Returns a shell command that is RVM-aware
|
46
|
+
#
|
47
|
+
# @param [String, #to_s] the shell command to be wrapped
|
48
|
+
# @param [String] A user's home directory path if this is for a user or
|
49
|
+
# nil if it is in a system context
|
50
|
+
# @return [String] the command wrapped in RVM-initialized bash command
|
51
|
+
def rvm_wrap_cmd(cmd, user_dir = nil)
|
52
|
+
profile = find_profile_to_source(user_dir)
|
53
|
+
%{bash -c "source #{profile} && #{cmd.gsub(/"/, '\"')}"}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
#
|
2
|
+
# Cookbook Name:: rvm
|
3
|
+
# Library:: Chef::RVM::StringCache
|
4
|
+
#
|
5
|
+
# Author:: Fletcher Nichol <fnichol@nichol.ca>
|
6
|
+
#
|
7
|
+
# Copyright 2011, Fletcher Nichol
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
|
22
|
+
require 'chef/mixin/command'
|
23
|
+
|
24
|
+
class Chef
|
25
|
+
module RVM
|
26
|
+
module ShellHelpers
|
27
|
+
# stub to satisfy StringCache (library load order not guarenteed)
|
28
|
+
end
|
29
|
+
|
30
|
+
class StringCache
|
31
|
+
class << self
|
32
|
+
include Chef::Mixin::Command
|
33
|
+
include Chef::RVM::ShellHelpers
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Returns a fully qualified RVM Ruby string for the given input string
|
38
|
+
#
|
39
|
+
# @param [String] a string that can interpreted by RVM
|
40
|
+
# @param [String] the username if this is for a user install or nil if
|
41
|
+
# it is a system install
|
42
|
+
# @return [String] a fully qualified RVM Ruby string
|
43
|
+
def self.fetch(str, user = nil)
|
44
|
+
@@strings ||= Hash.new
|
45
|
+
rvm_install = user || "system"
|
46
|
+
@@strings[rvm_install] ||= Hash.new
|
47
|
+
|
48
|
+
return @@strings[rvm_install][str] if @@strings[rvm_install].has_key?(str)
|
49
|
+
|
50
|
+
result = canonical_ruby_string(str, user)
|
51
|
+
# cache everything except default environment
|
52
|
+
if str == 'default'
|
53
|
+
result
|
54
|
+
else
|
55
|
+
@@strings[rvm_install][str] = result
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
protected
|
60
|
+
|
61
|
+
def self.canonical_ruby_string(str, user)
|
62
|
+
Chef::Log.debug("Fetching canonical RVM string for: #{str} " +
|
63
|
+
"(#{user || 'system'})")
|
64
|
+
if user
|
65
|
+
user_dir = Etc.getpwnam(user).dir
|
66
|
+
else
|
67
|
+
user_dir = nil
|
68
|
+
end
|
69
|
+
|
70
|
+
cmd = ["source #{find_profile_to_source(user_dir)}",
|
71
|
+
"rvm_ruby_string='#{str}'", "__rvm_ruby_string",
|
72
|
+
"echo $rvm_ruby_string"].join(" && ")
|
73
|
+
pid, stdin, stdout, stderr = popen4('bash', shell_params(user, user_dir))
|
74
|
+
stdin.puts(cmd)
|
75
|
+
stdin.close
|
76
|
+
|
77
|
+
result = stdout.read.split('\n').first.chomp
|
78
|
+
if result =~ /^-/ # if the result has a leading dash, value is bogus
|
79
|
+
Chef::Log.warn("Could not determine canonical RVM string for: #{str} " +
|
80
|
+
"(#{user || 'system'})")
|
81
|
+
nil
|
82
|
+
else
|
83
|
+
Chef::Log.debug("Canonical RVM string is: #{str} => #{result} " +
|
84
|
+
"(#{user || 'system'})")
|
85
|
+
result
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.shell_params(user, user_dir)
|
90
|
+
if user
|
91
|
+
{
|
92
|
+
:user => user,
|
93
|
+
:environment => {
|
94
|
+
'USER' => user,
|
95
|
+
'HOME' => user_dir
|
96
|
+
}
|
97
|
+
}
|
98
|
+
else
|
99
|
+
Hash.new
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#
|
2
|
+
# Cookbook Name:: rvm
|
3
|
+
# Library:: Chef::RVM::StringHelpers
|
4
|
+
#
|
5
|
+
# Author:: Fletcher Nichol <fnichol@nichol.ca>
|
6
|
+
#
|
7
|
+
# Copyright 2011, Fletcher Nichol
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
module RVM
|
24
|
+
module StringHelpers
|
25
|
+
##
|
26
|
+
# Filters out any gemset declarations in an RVM Ruby string
|
27
|
+
#
|
28
|
+
# @param [String, #to_s] the RVM Ruby string
|
29
|
+
# @return [String] the Ruby string, minus gemset
|
30
|
+
def select_ruby(ruby_string)
|
31
|
+
ruby_string.split('@').first
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Filters out any Ruby declaration in an RVM Ruby string
|
36
|
+
#
|
37
|
+
# @param [String, #to_s] the RVM Ruby string
|
38
|
+
# @return [String] the gemset string, minus Ruby or nil if no gemset given
|
39
|
+
def select_gemset(ruby_string)
|
40
|
+
if ruby_string.include?('@')
|
41
|
+
ruby_string.split('@').last
|
42
|
+
else
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# Sanitizes a Ruby string so that it's more normalized.
|
49
|
+
#
|
50
|
+
# @param [String, #to_s] an RVM Ruby string
|
51
|
+
# @param [String] a specific user RVM or nil for system-wide
|
52
|
+
# @return [String] a fully qualified RVM Ruby string
|
53
|
+
def normalize_ruby_string(ruby_string, user = new_resource.user, patch = new_resource.patch)
|
54
|
+
return "system" if ruby_string == "system"
|
55
|
+
fetched_ruby_string = StringCache.fetch(ruby_string, user)
|
56
|
+
return "#{fetched_ruby_string} --patch #{patch}" if patch
|
57
|
+
fetched_ruby_string
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class Chef
|
2
|
+
module RVM
|
3
|
+
module ShellHelpers
|
4
|
+
# stub to satisfy VersionCache (library load order not guarenteed)
|
5
|
+
end
|
6
|
+
|
7
|
+
module VersionHelpers
|
8
|
+
def rvm_version(user = nil)
|
9
|
+
VersionCache.fetch_version(user)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class VersionCache
|
14
|
+
class << self
|
15
|
+
include Chef::Mixin::ShellOut
|
16
|
+
include Chef::RVM::ShellHelpers
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.fetch_version(user = nil)
|
20
|
+
@@versions ||= Hash.new
|
21
|
+
rvm_install = user || "system"
|
22
|
+
@@versions[rvm_install] ||= rvm_version(user)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.rvm_version(user = nil)
|
26
|
+
cmd = "rvm version | cut -d ' ' -f 2"
|
27
|
+
|
28
|
+
if user
|
29
|
+
user_dir = Etc.getpwnam(user).dir
|
30
|
+
environment = { 'USER' => user, 'HOME' => user_dir }
|
31
|
+
else
|
32
|
+
user_dir = nil
|
33
|
+
environment = nil
|
34
|
+
end
|
35
|
+
|
36
|
+
version = shell_out!(
|
37
|
+
rvm_wrap_cmd(cmd, user_dir), :env => environment).stdout.strip
|
38
|
+
|
39
|
+
Chef::Log.debug "RVM version = #{version} (#{user || 'system'})"
|
40
|
+
|
41
|
+
version
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#
|
2
|
+
# Cookbook Name:: rvm
|
3
|
+
# Library: gem_package resource monkey patch
|
4
|
+
#
|
5
|
+
# Author:: Fletcher Nichol <fnichol@nichol.ca>
|
6
|
+
#
|
7
|
+
# Copyright 2011, Fletcher Nichol
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
|
22
|
+
##
|
23
|
+
# Patch Chef::Resource::GemPackage resource to use the RVMRubygems provider.
|
24
|
+
# This has potentially dangerous side effects and should be considered
|
25
|
+
# experimental. You have been warned.
|
26
|
+
def patch_gem_package
|
27
|
+
::Chef::Resource::GemPackage.class_eval do
|
28
|
+
def initialize(name, run_context=nil)
|
29
|
+
super
|
30
|
+
@resource_name = :gem_package
|
31
|
+
@provider = Chef::Provider::Package::RVMRubygems
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
#
|
2
|
+
# Cookbook Name:: rvm
|
3
|
+
# Provider:: rvm_installation
|
4
|
+
#
|
5
|
+
# Author:: Fletcher Nichol <fnichol@nichol.ca>
|
6
|
+
#
|
7
|
+
# Copyright 2013, Fletcher Nichol
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
|
22
|
+
require "chef/provider"
|
23
|
+
require "chef/resource/remote_file"
|
24
|
+
require "chef/resource/package"
|
25
|
+
require "chef/resource/template"
|
26
|
+
require "chef/mixin/shell_out"
|
27
|
+
|
28
|
+
class Chef
|
29
|
+
|
30
|
+
class Provider
|
31
|
+
|
32
|
+
class RvmInstallation < Chef::Provider
|
33
|
+
|
34
|
+
include Chef::Mixin::ShellOut
|
35
|
+
|
36
|
+
def load_current_resource
|
37
|
+
@current_resource = Chef::Resource::RvmInstallation.new(new_resource.name)
|
38
|
+
if @current_resource.installed(installed?)
|
39
|
+
@current_resource.version(version)
|
40
|
+
end
|
41
|
+
@current_resource
|
42
|
+
end
|
43
|
+
|
44
|
+
def action_install
|
45
|
+
converge_rvmrc
|
46
|
+
if current_resource.installed
|
47
|
+
Chef::Log.info("#{new_resource} #{current_resource.version} " +
|
48
|
+
"already installed - nothing to do")
|
49
|
+
else
|
50
|
+
converge_install
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def action_force
|
55
|
+
converge_rvmrc
|
56
|
+
end
|
57
|
+
|
58
|
+
def converge_rvmrc
|
59
|
+
converge_by("manage rvmrc for #{new_resource}") { write_rvmrc }
|
60
|
+
end
|
61
|
+
|
62
|
+
def converge_install
|
63
|
+
converge_by("install RVM for #{new_resource}") { install_rvm }
|
64
|
+
Chef::Log.info("#{new_resource} #{new_resource.version} installed")
|
65
|
+
end
|
66
|
+
|
67
|
+
def install_rvm
|
68
|
+
install_packages
|
69
|
+
download_installer
|
70
|
+
run_install_cmd
|
71
|
+
|
72
|
+
new_resource.version(version)
|
73
|
+
end
|
74
|
+
|
75
|
+
def install_packages
|
76
|
+
Array(new_resource.install_pkgs).map do |pkg|
|
77
|
+
r = Chef::Resource::Package.new(pkg, run_context)
|
78
|
+
r.run_action(:install)
|
79
|
+
r
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def write_rvmrc
|
84
|
+
r = Chef::Resource::Template.new(rvmrc_path, run_context)
|
85
|
+
r.owner(new_resource.user)
|
86
|
+
r.group(etc_user.gid)
|
87
|
+
r.mode("0644")
|
88
|
+
r.source(new_resource.rvmrc_template_source)
|
89
|
+
r.cookbook(new_resource.rvmrc_template_cookbook)
|
90
|
+
r.variables(
|
91
|
+
:user => new_resource.user,
|
92
|
+
:rvm_path => rvm_path,
|
93
|
+
:rvmrc_env => new_resource.rvmrc_env
|
94
|
+
)
|
95
|
+
r.run_action(:create)
|
96
|
+
r
|
97
|
+
end
|
98
|
+
|
99
|
+
def download_installer
|
100
|
+
r = Chef::Resource::RemoteFile.new(rvm_installer_path, run_context)
|
101
|
+
r.source(new_resource.installer_url)
|
102
|
+
r.run_action(:create)
|
103
|
+
r
|
104
|
+
end
|
105
|
+
|
106
|
+
def run_install_cmd
|
107
|
+
rvm_shell_out!(%{bash #{rvm_installer_path} #{new_resource.installer_flags}})
|
108
|
+
end
|
109
|
+
|
110
|
+
def rvm_installer_path
|
111
|
+
::File.join(
|
112
|
+
Chef::Config[:file_cache_path], "rvm-installer-#{new_resource.user}"
|
113
|
+
)
|
114
|
+
end
|
115
|
+
|
116
|
+
def installed?
|
117
|
+
cmd = rvm_shell_out(
|
118
|
+
%{bash -c "source #{rvm_path}/scripts/rvm && type rvm"}
|
119
|
+
)
|
120
|
+
(cmd.exitstatus == 0 && cmd.stdout.lines.first == "rvm is a function\n")
|
121
|
+
end
|
122
|
+
|
123
|
+
def version
|
124
|
+
cmd = rvm("version")
|
125
|
+
matches = /^rvm ([\w.]+)/.match(cmd.stdout)
|
126
|
+
|
127
|
+
if cmd.exitstatus != 0
|
128
|
+
raise "Could not determine version for #{new_resource}, " +
|
129
|
+
"exited (#{cmd.exitstatus})"
|
130
|
+
end
|
131
|
+
|
132
|
+
if matches && matches[1]
|
133
|
+
return matches[1]
|
134
|
+
else
|
135
|
+
raise "Could not determine version for #{new_resource} " +
|
136
|
+
"from version string [#{cmd.stdout}]"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def rvm_shell_out(cmd)
|
141
|
+
user = new_resource.user
|
142
|
+
home_dir = etc_user.dir
|
143
|
+
opts = {
|
144
|
+
:user => user,
|
145
|
+
:group => etc_user.gid,
|
146
|
+
:cwd => home_dir,
|
147
|
+
:env => { "HOME" => home_dir, "USER" => user, "TERM" => "dumb" }
|
148
|
+
}
|
149
|
+
|
150
|
+
Chef::Log.debug("Running [#{cmd}] with #{opts}")
|
151
|
+
shell_out(cmd, opts)
|
152
|
+
end
|
153
|
+
|
154
|
+
def rvm_shell_out!(*args)
|
155
|
+
cmd = rvm_shell_out(*args)
|
156
|
+
cmd.error!
|
157
|
+
cmd
|
158
|
+
end
|
159
|
+
|
160
|
+
def rvm(subcommand)
|
161
|
+
rvm_shell_out(%{#{rvm_path}/bin/rvm #{subcommand}})
|
162
|
+
end
|
163
|
+
|
164
|
+
def rvm_path
|
165
|
+
if new_resource.user == "root"
|
166
|
+
"/usr/local/rvm"
|
167
|
+
else
|
168
|
+
::File.join(etc_user.dir, ".rvm")
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def rvmrc_path
|
173
|
+
if new_resource.user == "root"
|
174
|
+
"/etc/rvmrc"
|
175
|
+
else
|
176
|
+
::File.join(etc_user.dir, ".rvmrc")
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def etc_user
|
181
|
+
Etc.getpwnam(new_resource.user)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|