forked from sous-chefs/rvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ruby.rb
100 lines (87 loc) · 3.14 KB
/
ruby.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#
# Cookbook Name:: rvm
# Provider:: ruby
#
# Author:: Fletcher Nichol <fnichol@nichol.ca>
#
# Copyright 2011, Fletcher Nichol
#
# 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.
#
action :install do
rubie = select_ruby(new_resource.ruby_string)
if ruby_unknown?(rubie)
Chef::Log.warn("rvm_ruby[#{rubie}] is either not fully qualified or not " +
"known . Use `rvm list known` to get a full list.")
elsif ruby_installed?(rubie)
Chef::Log.debug("rvm_ruby[#{rubie}] is already installed, so skipping")
else
install_start = Time.now
install_ruby_dependencies rubie
Chef::Log.info("Building rvm_ruby[#{rubie}], this could take awhile...")
if RVM.install(rubie)
Chef::Log.info("Installation of rvm_ruby[#{rubie}] was successful.")
env = RVM::Environment.new
env.use rubie
update_installed_rubies
Chef::Log.info("Importing initial gemsets for rvm_ruby[#{rubie}]")
if env.gemset_initial
Chef::Log.debug("Initial gemsets for rvm_ruby[#{rubie}] are installed")
else
Chef::Log.warn(
"Failed to install initial gemsets for rvm_ruby[#{rubie}] ")
end
else
Chef::Log.warn("Failed to install rvm_ruby[#{rubie}]. " +
"Check logs in #{RVM.path}/log/#{rubie}")
end
Chef::Log.debug("rvm_ruby[#{rubie}] build time was " +
"#{(Time.now - install_start)/60.0} minutes.")
end
end
action :uninstall do
rubie = new_resource.ruby_string
if ruby_unknown?(rubie)
Chef::Log.warn("rvm_ruby[#{rubie}] is either not fully qualified or not " +
"known . Use `rvm list known` to get a full list.")
elsif ruby_installed?(rubie)
Chef::Log.info("Uninstalling rvm_ruby[#{rubie}]")
if RVM.uninstall(rubie)
update_installed_rubies
Chef::Log.debug("Uninstallation of rvm_ruby[#{rubie}] was successful.")
else
Chef::Log.warn("Failed to uninstall rvm_ruby[#{rubie}]. " +
"Check logs in #{RVM.path}/log/#{rubie}")
end
else
Chef::Log.debug("rvm_ruby[#{rubie}] was not installed, so skipping")
end
end
action :remove do
rubie = new_resource.ruby_string
if ruby_unknown?(rubie)
Chef::Log.warn("rvm_ruby[#{rubie}] is either not fully qualified or not " +
"known . Use `rvm list known` to get a full list.")
elsif ruby_installed?(rubie)
Chef::Log.info("Removing rvm_ruby[#{rubie}]")
if RVM.remove(rubie)
update_installed_rubies
Chef::Log.debug("Removal of rvm_ruby[#{rubie}] was successful.")
else
Chef::Log.warn("Failed to remove rvm_ruby[#{rubie}]. " +
"Check logs in #{RVM.path}/log/#{rubie}")
end
else
Chef::Log.debug("rvm_ruby[#{rubie}] was not installed, so skipping")
end
end