from-scratch 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +7 -0
  2. data/.chef/knife.rb +6 -0
  3. data/.gitignore +9 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +4 -0
  6. data/Berksfile +17 -0
  7. data/Berksfile.lock +19 -0
  8. data/Gemfile +4 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +58 -0
  11. data/Rakefile +6 -0
  12. data/Thorfile +5 -0
  13. data/bin/scratchify +6 -0
  14. data/chefignore +101 -0
  15. data/cookbooks/chef_gem/CHANGELOG.md +24 -0
  16. data/cookbooks/chef_gem/README.md +38 -0
  17. data/cookbooks/chef_gem/libraries/chef_gem.rb +72 -0
  18. data/cookbooks/chef_gem/metadata.json +29 -0
  19. data/cookbooks/chef_gem/recipes/default.rb +0 -0
  20. data/cookbooks/java/.gitignore +21 -0
  21. data/cookbooks/java/.kitchen.docker.yml +15 -0
  22. data/cookbooks/java/.kitchen.yml +126 -0
  23. data/cookbooks/java/.travis.yml +6 -0
  24. data/cookbooks/java/Berksfile +10 -0
  25. data/cookbooks/java/CHANGELOG.md +398 -0
  26. data/cookbooks/java/CONTRIBUTING.md +12 -0
  27. data/cookbooks/java/Gemfile +15 -0
  28. data/cookbooks/java/ISSUES.md +43 -0
  29. data/cookbooks/java/LICENSE +201 -0
  30. data/cookbooks/java/README.md +402 -0
  31. data/cookbooks/java/Rakefile +60 -0
  32. data/cookbooks/java/TESTING.md +41 -0
  33. data/cookbooks/java/attributes/default.rb +146 -0
  34. data/cookbooks/java/libraries/helpers.rb +120 -0
  35. data/cookbooks/java/libraries/matchers.rb +5 -0
  36. data/cookbooks/java/metadata.json +69 -0
  37. data/cookbooks/java/providers/alternatives.rb +94 -0
  38. data/cookbooks/java/providers/ark.rb +255 -0
  39. data/cookbooks/java/recipes/default.rb +22 -0
  40. data/cookbooks/java/recipes/default_java_symlink.rb +19 -0
  41. data/cookbooks/java/recipes/homebrew.rb +3 -0
  42. data/cookbooks/java/recipes/ibm.rb +76 -0
  43. data/cookbooks/java/recipes/ibm_tar.rb +70 -0
  44. data/cookbooks/java/recipes/openjdk.rb +74 -0
  45. data/cookbooks/java/recipes/oracle.rb +74 -0
  46. data/cookbooks/java/recipes/oracle_i386.rb +73 -0
  47. data/cookbooks/java/recipes/oracle_jce.rb +75 -0
  48. data/cookbooks/java/recipes/oracle_rpm.rb +60 -0
  49. data/cookbooks/java/recipes/purge_packages.rb +20 -0
  50. data/cookbooks/java/recipes/set_attributes_from_version.rb +55 -0
  51. data/cookbooks/java/recipes/set_java_home.rb +44 -0
  52. data/cookbooks/java/recipes/windows.rb +82 -0
  53. data/cookbooks/java/resources/alternatives.rb +30 -0
  54. data/cookbooks/java/resources/ark.rb +58 -0
  55. data/cookbooks/java/templates/default/ibm_jdk.installer.properties.erb +3 -0
  56. data/cookbooks/java/templates/default/oracle.jinfo.erb +6 -0
  57. data/cookbooks/rvm/.foodcritic +1 -0
  58. data/cookbooks/rvm/.gitignore +7 -0
  59. data/cookbooks/rvm/.kitchen.yml +66 -0
  60. data/cookbooks/rvm/.travis.yml +9 -0
  61. data/cookbooks/rvm/Berksfile +10 -0
  62. data/cookbooks/rvm/CHANGELOG.md +253 -0
  63. data/cookbooks/rvm/CODE_OF_CONDUCT.md +12 -0
  64. data/cookbooks/rvm/CONTRIBUTING.md +26 -0
  65. data/cookbooks/rvm/Gemfile +20 -0
  66. data/cookbooks/rvm/Guardfile +12 -0
  67. data/cookbooks/rvm/README.md +1459 -0
  68. data/cookbooks/rvm/Rakefile +18 -0
  69. data/cookbooks/rvm/attributes/.gitkeep +0 -0
  70. data/cookbooks/rvm/attributes/default.rb +68 -0
  71. data/cookbooks/rvm/attributes/gem_package.rb +23 -0
  72. data/cookbooks/rvm/attributes/vagrant.rb +23 -0
  73. data/cookbooks/rvm/libraries/chef_rvm_environment_helpers.rb +55 -0
  74. data/cookbooks/rvm/libraries/chef_rvm_gemset_helpers.rb +67 -0
  75. data/cookbooks/rvm/libraries/chef_rvm_recipe_helpers.rb +80 -0
  76. data/cookbooks/rvm/libraries/chef_rvm_ruby_helpers.rb +95 -0
  77. data/cookbooks/rvm/libraries/chef_rvm_set_helpers.rb +16 -0
  78. data/cookbooks/rvm/libraries/chef_rvm_shell_helpers.rb +57 -0
  79. data/cookbooks/rvm/libraries/chef_rvm_string_cache.rb +104 -0
  80. data/cookbooks/rvm/libraries/chef_rvm_string_helpers.rb +61 -0
  81. data/cookbooks/rvm/libraries/chef_rvm_version_helpers.rb +45 -0
  82. data/cookbooks/rvm/libraries/gem_package_monkeypatch.rb +34 -0
  83. data/cookbooks/rvm/libraries/provider_rvm_installation.rb +185 -0
  84. data/cookbooks/rvm/libraries/resource_rvm_installation.rb +103 -0
  85. data/cookbooks/rvm/libraries/rvm_chef_user_environment.rb +55 -0
  86. data/cookbooks/rvm/libraries/rvm_rubygems_package.rb +189 -0
  87. data/cookbooks/rvm/libraries/rvm_shell_chef_wrapper.rb +99 -0
  88. data/cookbooks/rvm/metadata.json +51 -0
  89. data/cookbooks/rvm/providers/default_ruby.rb +63 -0
  90. data/cookbooks/rvm/providers/environment.rb +78 -0
  91. data/cookbooks/rvm/providers/gemset.rb +118 -0
  92. data/cookbooks/rvm/providers/global_gem.rb +97 -0
  93. data/cookbooks/rvm/providers/ruby.rb +178 -0
  94. data/cookbooks/rvm/providers/shell.rb +121 -0
  95. data/cookbooks/rvm/providers/wrapper.rb +73 -0
  96. data/cookbooks/rvm/recipes/.gitkeep +0 -0
  97. data/cookbooks/rvm/recipes/default.rb +40 -0
  98. data/cookbooks/rvm/recipes/gem_package.rb +33 -0
  99. data/cookbooks/rvm/recipes/system.rb +37 -0
  100. data/cookbooks/rvm/recipes/system_install.rb +42 -0
  101. data/cookbooks/rvm/recipes/user.rb +43 -0
  102. data/cookbooks/rvm/recipes/user_install.rb +58 -0
  103. data/cookbooks/rvm/recipes/vagrant.rb +37 -0
  104. data/cookbooks/rvm/resources/default_ruby.rb +31 -0
  105. data/cookbooks/rvm/resources/environment.rb +31 -0
  106. data/cookbooks/rvm/resources/gem.rb +37 -0
  107. data/cookbooks/rvm/resources/gemset.rb +32 -0
  108. data/cookbooks/rvm/resources/global_gem.rb +34 -0
  109. data/cookbooks/rvm/resources/ruby.rb +32 -0
  110. data/cookbooks/rvm/resources/shell.rb +41 -0
  111. data/cookbooks/rvm/resources/wrapper.rb +34 -0
  112. data/cookbooks/rvm/templates/default/rvmrc.erb +14 -0
  113. data/cookbooks/rvm/templates/default/vagrant-chef-client-wrapper.erb +23 -0
  114. data/cookbooks/rvm/templates/default/vagrant-chef-solo-wrapper.erb +23 -0
  115. data/cookbooks/rvm/test/integration/data_bags/users/virgil1.json +4 -0
  116. data/cookbooks/rvm/test/integration/data_bags/users/virgil2.json +4 -0
  117. data/cookbooks/rvm/test/integration/data_bags/users/wigglebottom.json +3 -0
  118. data/cookbooks/rvm/test/integration/installs/bats/version_pinning.bats +13 -0
  119. data/cookbooks/rvm/test/integration/rubies/bats/_common.bash +16 -0
  120. data/cookbooks/rvm/test/integration/rubies/bats/verify_1.9.3.bats +9 -0
  121. data/cookbooks/rvm/test/integration/rubies/bats/verify_jruby.bats +12 -0
  122. data/cookbooks/rvm/test/integration/rubies/bats/verify_patch_support.bats +19 -0
  123. data/cookbooks/rvm/test/integration/rubies/bats/verify_ree.bats +9 -0
  124. data/cookbooks/rvm/test/integration/rubies/bats/verify_rubygems_version_support.bats +15 -0
  125. data/cookbooks/rvm/test/integration/stock_system_and_user/bats/system.bats +45 -0
  126. data/cookbooks/rvm/test/unit/libraries/provider_rvm_installation_spec.rb +220 -0
  127. data/cookbooks/rvm/test/unit/libraries/resource_rvm_installation_spec.rb +139 -0
  128. data/cookbooks/rvm/test/unit/spec_helper.rb +23 -0
  129. data/cookbooks/scratchify/.chef/knife.rb +9 -0
  130. data/cookbooks/scratchify/Berksfile +16 -0
  131. data/cookbooks/scratchify/Berksfile.lock +19 -0
  132. data/cookbooks/scratchify/LICENSE.txt +21 -0
  133. data/cookbooks/scratchify/README.md +41 -0
  134. data/cookbooks/scratchify/Thorfile +5 -0
  135. data/cookbooks/scratchify/bin/console +14 -0
  136. data/cookbooks/scratchify/bin/scratchify +6 -0
  137. data/cookbooks/scratchify/bin/setup +7 -0
  138. data/cookbooks/scratchify/chefignore +101 -0
  139. data/cookbooks/scratchify/data_bags/users/deploy.json +6 -0
  140. data/cookbooks/scratchify/environments/.gitkeep +0 -0
  141. data/cookbooks/scratchify/from-scratch.gemspec +36 -0
  142. data/cookbooks/scratchify/lib/from/scratch.rb +31 -0
  143. data/cookbooks/scratchify/lib/from/scratch/interviewer.rb +35 -0
  144. data/cookbooks/scratchify/lib/from/scratch/version.rb +3 -0
  145. data/cookbooks/scratchify/metadata.json +36 -0
  146. data/cookbooks/scratchify/nodes/normfood.ru.json +75 -0
  147. data/cookbooks/scratchify/recipes/default.rb +0 -0
  148. data/cookbooks/scratchify/roles/.gitkeep +0 -0
  149. data/cookbooks/scratchify/spec/from/scratch_spec.rb +11 -0
  150. data/cookbooks/scratchify/spec/spec_helper.rb +2 -0
  151. data/cookbooks/user/.gitignore +5 -0
  152. data/cookbooks/user/.kitchen.yml +46 -0
  153. data/cookbooks/user/.travis.yml +4 -0
  154. data/cookbooks/user/Berksfile +7 -0
  155. data/cookbooks/user/CHANGELOG.md +101 -0
  156. data/cookbooks/user/Gemfile +14 -0
  157. data/cookbooks/user/README.md +447 -0
  158. data/cookbooks/user/Rakefile +21 -0
  159. data/cookbooks/user/attributes/default.rb +50 -0
  160. data/cookbooks/user/libraries/matchers.rb +26 -0
  161. data/cookbooks/user/metadata.json +46 -0
  162. data/cookbooks/user/providers/account.rb +212 -0
  163. data/cookbooks/user/recipes/data_bag.rb +59 -0
  164. data/cookbooks/user/recipes/default.rb +18 -0
  165. data/cookbooks/user/resources/account.rb +41 -0
  166. data/cookbooks/user/templates/default/authorized_keys.erb +7 -0
  167. data/from-scratch.gemspec +33 -0
  168. data/lib/from-scratch.rb +25 -0
  169. data/lib/from-scratch/version.rb +3 -0
  170. data/metadata.rb +15 -0
  171. data/recipes/default.rb +0 -0
  172. data/templates/node.json.erb +31 -0
  173. data/templates/user.json.erb +6 -0
  174. metadata +330 -0
@@ -0,0 +1,63 @@
1
+ #
2
+ # Cookbook Name:: rvm
3
+ # Provider:: default_ruby
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
+ include Chef::RVM::StringHelpers
23
+ include Chef::RVM::EnvironmentHelpers
24
+
25
+ def load_current_resource
26
+ @rubie = normalize_ruby_string(select_ruby(new_resource.ruby_string))
27
+ @gemset = select_gemset(new_resource.ruby_string)
28
+ @ruby_string = @gemset.nil? ? @rubie : "#{@rubie}@#{@gemset}"
29
+ @rvm_env = ::RVM::ChefUserEnvironment.new(new_resource.user)
30
+ end
31
+
32
+ action :create do
33
+ next if skip_ruby?
34
+
35
+ # ensure ruby is installed and gemset exists (if specified)
36
+ unless env_exists?(@ruby_string)
37
+ e = rvm_environment @ruby_string do
38
+ user new_resource.user
39
+ action :nothing
40
+ end
41
+ e.run_action(:create)
42
+ end
43
+
44
+ Chef::Log.info("Setting default ruby to rvm_ruby[#{@ruby_string}]")
45
+ @rvm_env.rvm :use, @ruby_string, :default => true
46
+ new_resource.updated_by_last_action(true)
47
+ end
48
+
49
+ private
50
+
51
+ def skip_ruby?
52
+ if @rubie.nil?
53
+ Chef::Log.warn("#{self.class.name}: RVM ruby string `#{@rubie}' " +
54
+ "is not known. Use `rvm list known` to get a full list.")
55
+ true
56
+ elsif ruby_default?(@ruby_string)
57
+ Chef::Log.debug("#{self.class.name}: `#{@ruby_string}' is already default, " +
58
+ "so skipping")
59
+ true
60
+ else
61
+ false
62
+ end
63
+ end
@@ -0,0 +1,78 @@
1
+ #
2
+ # Cookbook Name:: rvm
3
+ # Provider:: environment
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
+ include Chef::RVM::StringHelpers
23
+ include Chef::RVM::RubyHelpers
24
+ include Chef::RVM::GemsetHelpers
25
+
26
+ def load_current_resource
27
+ @rubie = normalize_ruby_string(select_ruby(new_resource.ruby_string))
28
+ @gemset = select_gemset(new_resource.ruby_string)
29
+ @ruby_string = @gemset.nil? ? @rubie : "#{@rubie}@#{@gemset}"
30
+ @rvm_env = ::RVM::ChefUserEnvironment.new(new_resource.user)
31
+ end
32
+
33
+ action :create do
34
+ next if skip_environment?
35
+
36
+ if @gemset
37
+ gemset_resource :create
38
+ else
39
+ ruby_resource :install
40
+ end
41
+ new_resource.updated_by_last_action(true)
42
+ end
43
+
44
+ private
45
+
46
+ def skip_environment?
47
+ if @rubie.nil?
48
+ Chef::Log.warn("#{self.class.name}: RVM ruby string `#{@rubie}' " +
49
+ "is not known. Use `rvm list known` to get a full list.")
50
+ true
51
+ else
52
+ false
53
+ end
54
+ end
55
+
56
+ def gemset_resource(exec_action)
57
+ # ensure gemset is created, if specified
58
+ unless gemset_exists?(:ruby => @rubie, :gemset => @gemset)
59
+ r = rvm_gemset @ruby_string do
60
+ user new_resource.user
61
+ action :nothing
62
+ end
63
+ r.run_action(exec_action)
64
+ new_resource.updated_by_last_action(true) if r.updated_by_last_action?
65
+ end
66
+ end
67
+
68
+ def ruby_resource(exec_action)
69
+ # ensure ruby is installed
70
+ unless ruby_installed?(@rubie)
71
+ r = rvm_ruby @rubie do
72
+ user new_resource.user
73
+ action :nothing
74
+ end
75
+ r.run_action(exec_action)
76
+ new_resource.updated_by_last_action(true) if r.updated_by_last_action?
77
+ end
78
+ end
@@ -0,0 +1,118 @@
1
+ #
2
+ # Cookbook Name:: rvm
3
+ # Provider:: gemset
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
+ include Chef::RVM::StringHelpers
23
+ include Chef::RVM::RubyHelpers
24
+ include Chef::RVM::GemsetHelpers
25
+
26
+ def load_current_resource
27
+ if new_resource.ruby_string
28
+ @rubie = normalize_ruby_string(select_ruby(new_resource.ruby_string))
29
+ @gemset = new_resource.gemset
30
+ else
31
+ @rubie = normalize_ruby_string(select_ruby(new_resource.gemset))
32
+ @gemset = select_gemset(new_resource.gemset)
33
+ end
34
+ @ruby_string = "#{@rubie}@#{@gemset}"
35
+ @rvm_env = ::RVM::ChefUserEnvironment.new(new_resource.user)
36
+ end
37
+
38
+ action :create do
39
+ unless ruby_installed?(@rubie)
40
+ r = rvm_ruby @rubie do
41
+ user new_resource.user
42
+ action :nothing
43
+ end
44
+ r.run_action(:install)
45
+ end
46
+
47
+ if gemset_exists?(:ruby => @rubie, :gemset => @gemset)
48
+ Chef::Log.debug("rvm_gemset[#{@ruby_string}] already exists, so skipping")
49
+ else
50
+ Chef::Log.info("Creating rvm_gemset[#{@ruby_string}]")
51
+
52
+ @rvm_env.use @rubie
53
+ if @rvm_env.gemset_create @gemset
54
+ update_installed_gemsets(@rubie)
55
+ Chef::Log.debug("Creation of rvm_gemset[#{@ruby_string}] was successful.")
56
+ else
57
+ Chef::Log.warn("Failed to create rvm_gemset[#{@ruby_string}].")
58
+ end
59
+
60
+ new_resource.updated_by_last_action(true)
61
+ end
62
+ end
63
+
64
+ action :delete do
65
+ if gemset_exists?(:ruby => @rubie, :gemset => @gemset)
66
+ Chef::Log.info("Deleting rvm_gemset[#{@ruby_string}]")
67
+
68
+ @rvm_env.use @rubie
69
+ if @rvm_env.gemset_delete @gemset
70
+ update_installed_gemsets(@rubie)
71
+ Chef::Log.debug("Deletion of rvm_gemset[#{@ruby_string}] was successful.")
72
+ new_resource.updated_by_last_action(true)
73
+ else
74
+ Chef::Log.warn("Failed to delete rvm_gemset[#{@ruby_string}].")
75
+ end
76
+ else
77
+ Chef::Log.debug("rvm_gemset[#{@ruby_string}] does not exist, so skipping")
78
+ end
79
+ end
80
+
81
+ action :empty do
82
+ if gemset_exists?(:ruby => @rubie, :gemset => @gemset)
83
+ Chef::Log.info("Emptying rvm_gemset[#{@ruby_string}]")
84
+
85
+ @rvm_env.use @ruby_string
86
+ if @rvm_env.gemset_empty
87
+ update_installed_gemsets(@rubie)
88
+ Chef::Log.debug("Emptying of rvm_gemset[#{@ruby_string}] was successful.")
89
+ new_resource.updated_by_last_action(true)
90
+ else
91
+ Chef::Log.warn("Failed to empty rvm_gemset[#{@ruby_string}].")
92
+ end
93
+ else
94
+ Chef::Log.debug("rvm_gemset[#{@ruby_string}] does not exist, so skipping")
95
+ end
96
+ end
97
+
98
+ action :update do
99
+ Chef::Log.info("Updating rvm_gemset[#{@ruby_string}]")
100
+
101
+ # create gemset if it doesn't exist
102
+ unless gemset_exists?(:ruby => @rubie, :gemset => @gemset)
103
+ c = rvm_gemset @ruby_string do
104
+ user new_resource.user
105
+ action :nothing
106
+ end
107
+ c.run_action(:create)
108
+ end
109
+
110
+ @rvm_env.use @ruby_string
111
+ if @rvm_env.gemset_update
112
+ update_installed_gemsets(@rubie)
113
+ Chef::Log.debug("Updating of rvm_gemset[#{@ruby_string}] was successful.")
114
+ new_resource.updated_by_last_action(true)
115
+ else
116
+ Chef::Log.warn("Failed to update rvm_gemset[#{@ruby_string}].")
117
+ end
118
+ end
@@ -0,0 +1,97 @@
1
+ #
2
+ # Cookbook Name:: rvm
3
+ # Provider:: global_gem
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
+ include Chef::RVM::RubyHelpers
23
+
24
+ def load_current_resource
25
+ @rvm_env = ::RVM::ChefUserEnvironment.new(new_resource.user)
26
+ end
27
+
28
+ [:install, :upgrade, :remove, :purge].each do |exec_action|
29
+ action exec_action do
30
+ # add gem entry into global.gems
31
+ update_global_gems_file exec_action
32
+
33
+ # install gem in all rubies in global gemsets
34
+ installed_rubies.each do |rubie|
35
+ gem_package_wrapper exec_action, "#{rubie}@global"
36
+ end
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ ##
43
+ # Wraps the rvm_gem resource
44
+ #
45
+ # @param [Symbol] action to be performed with gem_package provider
46
+ # @param [optional, String, #to_s] the fully qualifed rvm string
47
+ def gem_package_wrapper(exec_action, ruby_global_gemset)
48
+ g = rvm_gem new_resource.package_name do
49
+ ruby_string ruby_global_gemset
50
+ source new_resource.source if new_resource.source
51
+ options new_resource.options if new_resource.options
52
+ version new_resource.version if new_resource.version
53
+ gem_binary new_resource.gem_binary if new_resource.gem_binary
54
+ user new_resource.user
55
+ action :nothing
56
+ end
57
+ g.run_action(exec_action)
58
+ new_resource.updated_by_last_action(true) if g.updated_by_last_action?
59
+ end
60
+
61
+ ##
62
+ # Updates global.gems file to create or remove a gem entry
63
+ #
64
+ # @oaram [Symbol] action to :create or :remove the gem from the file
65
+ def update_global_gems_file(exec_action)
66
+ gem = if new_resource.version
67
+ "#{new_resource.package_name} -v#{new_resource.version}"
68
+ else
69
+ new_resource.package_name
70
+ end
71
+ user_dir = Etc.getpwnam(new_resource.user).dir if new_resource.user
72
+ global_gems_file = if new_resource.user
73
+ "#{user_dir}/.rvm/gemsets/global.gems"
74
+ else
75
+ "#{node['rvm']['root_path']}/gemsets/global.gems"
76
+ end
77
+
78
+ if [:install, :upgrade].include?(exec_action)
79
+ e = execute "Add #{gem} to #{global_gems_file}" do
80
+ if new_resource.user
81
+ user new_resource.user
82
+ group Etc.getpwnam(new_resource.user).gid
83
+ environment ({ 'USER' => new_resource.user, 'HOME' => user_dir })
84
+ else
85
+ user "root"
86
+ group "rvm"
87
+ end
88
+
89
+ command %{echo "#{gem}" >> "#{global_gems_file}"}
90
+ action :nothing
91
+
92
+ not_if %{grep -q "^#{gem}" "#{global_gems_file}"}
93
+ end
94
+ e.run_action(:run)
95
+ new_resource.updated_by_last_action(true) if e.updated_by_last_action?
96
+ end
97
+ end
@@ -0,0 +1,178 @@
1
+ #
2
+ # Cookbook Name:: rvm
3
+ # Provider:: ruby
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
+ include Chef::RVM::StringHelpers
23
+ include Chef::RVM::RubyHelpers
24
+
25
+ def load_current_resource
26
+ @rubie = normalize_ruby_string(select_ruby(new_resource.ruby_string))
27
+ @ruby_string = new_resource.ruby_string
28
+ @rvm_env = ::RVM::ChefUserEnvironment.new(
29
+ new_resource.user, "default",
30
+ :rvm_rubygems_version => new_resource.rubygems_version,
31
+ :source_environment => false
32
+ )
33
+ end
34
+
35
+ action :install do
36
+ next if skip_ruby?
37
+
38
+ if ruby_installed?(@ruby_string)
39
+ Chef::Log.debug("rvm_ruby[#{@rubie}] is already installed, so skipping")
40
+ else
41
+ install_start = Time.now
42
+ install_options = {:rvm_by_path => true}
43
+ install_options[:patch] = new_resource.patch if new_resource.patch
44
+
45
+ install_ruby_dependencies @rubie
46
+
47
+ Chef::Log.info("Building rvm_ruby[#{@rubie}], this could take a while...")
48
+
49
+ if @rvm_env.install(@rubie, install_options)
50
+ Chef::Log.info("Installation of rvm_ruby[#{@rubie}] was successful.")
51
+ @rvm_env.use @rubie
52
+ update_installed_rubies
53
+ new_resource.updated_by_last_action(true)
54
+
55
+ Chef::Log.info("Importing initial gemsets for rvm_ruby[#{@rubie}]")
56
+ if @rvm_env.gemset_initial
57
+ Chef::Log.debug("Initial gemsets for rvm_ruby[#{@rubie}] are installed")
58
+ else
59
+ Chef::Log.warn(
60
+ "Failed to install initial gemsets for rvm_ruby[#{@rubie}] ")
61
+ end
62
+ else
63
+ Chef::Log.warn("Failed to install rvm_ruby[#{@rubie}]. " +
64
+ "Check logs in #{::RVM.path}/log/#{@rubie}")
65
+ end
66
+
67
+ Chef::Log.info("rvm_ruby[#{@rubie}] build time was " +
68
+ "#{(Time.now - install_start)/60.0} minutes.")
69
+ end
70
+ end
71
+
72
+ action :uninstall do
73
+ next if skip_ruby?
74
+
75
+ if ruby_installed?(@rubie)
76
+ Chef::Log.info("Uninstalling rvm_ruby[#{@rubie}]")
77
+
78
+ if @rvm_env.uninstall(@rubie, :rvm_by_path => true)
79
+ update_installed_rubies
80
+ Chef::Log.debug("Uninstallation of rvm_ruby[#{@rubie}] was successful.")
81
+ new_resource.updated_by_last_action(true)
82
+ else
83
+ Chef::Log.warn("Failed to uninstall rvm_ruby[#{@rubie}]. " +
84
+ "Check logs in #{::RVM.path}/log/#{@rubie}")
85
+ end
86
+ else
87
+ Chef::Log.debug("rvm_ruby[#{@rubie}] was not installed, so skipping")
88
+ end
89
+ end
90
+
91
+ action :remove do
92
+ next if skip_ruby?
93
+
94
+ if ruby_installed?(@rubie)
95
+ Chef::Log.info("Removing rvm_ruby[#{@rubie}]")
96
+
97
+ if @rvm_env.remove(@rubie, :rvm_by_path => true)
98
+ update_installed_rubies
99
+ Chef::Log.debug("Removal of rvm_ruby[#{@rubie}] was successful.")
100
+ new_resource.updated_by_last_action(true)
101
+ else
102
+ Chef::Log.warn("Failed to remove rvm_ruby[#{@rubie}]. " +
103
+ "Check logs in #{::RVM.path}/log/#{@rubie}")
104
+ end
105
+ else
106
+ Chef::Log.debug("rvm_ruby[#{@rubie}] was not installed, so skipping")
107
+ end
108
+ end
109
+
110
+ private
111
+
112
+ def skip_ruby?
113
+ if @rubie.nil?
114
+ Chef::Log.warn("#{self.class.name}: RVM ruby string `#{@rubie}' " +
115
+ "is not known. Use `rvm list known` to get a full list.")
116
+ true
117
+ else
118
+ false
119
+ end
120
+ end
121
+
122
+ ##
123
+ # Installs any package dependencies needed by a given ruby
124
+ #
125
+ # @param [String, #to_s] the fully qualified RVM ruby string
126
+ def install_ruby_dependencies(rubie)
127
+ pkgs = []
128
+ case rubie
129
+ when /^ruby-/, /^ree-/, /^rbx-/, /^kiji/
130
+ case node['platform']
131
+ when "debian","ubuntu"
132
+ pkgs = %w{ build-essential openssl libreadline6 libreadline6-dev
133
+ zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev
134
+ sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev
135
+ ncurses-dev automake libtool bison ssl-cert pkg-config libgdbm-dev libffi-dev}
136
+ pkgs += %w{ subversion } if rubie =~ /^ruby-head$/
137
+ when "suse"
138
+ pkgs = %w{ gcc-c++ patch zlib zlib-devel libffi-devel
139
+ sqlite3-devel libxml2-devel libxslt-devel }
140
+ if node['platform_version'].to_f >= 11.0
141
+ pkgs += %w{ libreadline5 readline-devel libopenssl-devel }
142
+ else
143
+ pkgs += %w{ readline readline-devel openssl-devel }
144
+ end
145
+ pkgs += %w{ git subversion autoconf } if rubie =~ /^ruby-head$/
146
+ when "centos","redhat","fedora","scientific","amazon"
147
+ pkgs = %w{ gcc-c++ patch readline readline-devel zlib zlib-devel
148
+ libyaml-devel libffi-devel openssl-devel
149
+ make bzip2 autoconf automake libtool bison
150
+ libxml2 libxml2-devel libxslt libxslt-devel }
151
+ pkgs += %w{ git subversion autoconf } if rubie =~ /^ruby-head$/
152
+ when "gentoo"
153
+ pkgs = %w{ libiconv readline zlib openssl libyaml sqlite libxslt libtool gcc autoconf automake bison m4 }
154
+ end
155
+ when /^jruby/
156
+ begin
157
+ resource_collection.find("ruby_block[update-java-alternatives]").
158
+ run_action(:create)
159
+ rescue Chef::Exceptions::ResourceNotFound
160
+ Chef::Log.debug(
161
+ "java cookbook not loaded or not on ubuntu/debian, so skipping")
162
+ end
163
+
164
+ # TODO: need to figure out how to pull in java recipe only when needed. For
165
+ # now, users of jruby will have to add the "java" recipe to their run_list.
166
+ #include_recipe "java"
167
+ case node['platform']
168
+ when "debian","ubuntu"
169
+ pkgs += %w{ g++ ant }
170
+ end
171
+ end
172
+
173
+ pkgs.each do |pkg|
174
+ package pkg do
175
+ action :nothing
176
+ end.run_action(:install)
177
+ end
178
+ end