Class: GitPusshuTen::Commands::Rvm

Inherits:
Base
  • Object
show all
Defined in:
lib/gitpusshuten/modules/rvm/command.rb

Instance Attribute Summary

Attributes inherited from Base

#cli, #command, #configuration, #environment, #hooks, #perform_hooks

Instance Method Summary collapse

Methods inherited from Base

#c, #command_object, description, #e, #error, example, #g, #git, #help, #local, long_description, #message, #perform!, #perform_hooks!, #post_perform!, #pre_perform!, #prompt_for_root_password!, #prompt_for_user_password!, #r, #requires_user_existence!, #silent, #standard, usage, #validate!, #warning, #y, #yes?

Constructor Details

#initialize(*objects) ⇒ Rvm

Returns a new instance of Rvm.



17
18
19
20
21
22
23
# File 'lib/gitpusshuten/modules/rvm/command.rb', line 17

def initialize(*objects)
  super

  @command = cli.arguments.shift

  help if command.nil? or e.name.nil?
end

Instance Method Details

#ask_to_use_default_ruby_with_passenger!(ruby_version) ⇒ Object

Asks the user if he intends to make the newly set default ruby version as the ruby version for the passenger driven ruby applications



259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/gitpusshuten/modules/rvm/command.rb', line 259

def ask_to_use_default_ruby_with_passenger!(ruby_version)
  message("If you want to use #{y(ruby_version)} for your Ruby applications with Phusion Passenger")
  message("you must update your #{y("webserver's")} configuration file.\n\n")
  message("Would you like to do this now?\n\n")

  if yes?
    message "Which webserver are you using?"
    webserver = webserver?

    message "Invoking #{y("heavenly #{webserver.downcase} update-configuration for #{e.name}")} for you..\n\n\n"
    GitPusshuTen::Initializer.new(webserver.downcase, 'update-configuration', 'for', "#{e.name}")
  end
end

#choose_ruby_version!Object

Prompts the user to choose a Ruby to install



222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/gitpusshuten/modules/rvm/command.rb', line 222

def choose_ruby_version!
  choose do |menu|
    menu.prompt = ''

    %w[ruby-1.8.6 ruby-1.8.7 ruby-1.9.1 ruby-1.9.2].each do |mri|
      menu.choice(mri)
    end

    %w[ree-1.8.6 ree-1.8.7].each do |ree|
      menu.choice(ree)
    end
  end
end

#perform_install!Object

Installs RVM (Ruby Version Manager)



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
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/gitpusshuten/modules/rvm/command.rb', line 27

def perform_install!
  prompt_for_root_password!

  message "Which Ruby would you like to install and use as your default Ruby Interpreter?"
  ruby_version = choose_ruby_version!
  message "Going to install #{y(ruby_version)} after the #{y('RVM')} installation finishes."

  ##
  # Update aptitude package list and install git/curl/wget
  Spinner.return :message => "Updating package list and installing #{y('RVM')} requirements.." do
    e.install!("git-core curl wget;")
    g("Done!")
  end

  ##
  # Download Packages
  Spinner.return :message => "Downloading Git Pusshu Ten #{y('packages')}.." do
    e.download_packages!("$HOME", :root)
    g("Done!")
  end

  ##
  # Install RVM (system wide)
  Spinner.return :message => "Installing #{y('RVM')}.." do
    e.execute_as_root("cd $HOME; wget -O rvm-install-system-wide --no-check-certificate http://bit.ly/rvm-install-system-wide; bash rvm-install-system-wide; rm rvm-install-system-wide;")
    g("Done!")
  end

  ##
  # Download Git Packages and add the rvm load snippet into /etc/profile.
  if not e.execute_as_root("cat /etc/profile").include?('source "/usr/local/rvm/scripts/rvm"')
    Spinner.return :message => "Configuring #{y('/etc/profile')}.." do
      e.execute_as_root("cd $HOME; cat gitpusshuten-packages/modules/rvm/profile >> /etc/profile")
      g("Done!")
    end
  end

  ##
  # Add the gemrc into the root's home directory
  if not e.file?('/root/.gemrc')
    Spinner.return :message => "Configuring #{y('.gemrc')} file.." do
      e.execute_as_root("cd $HOME; cat gitpusshuten-packages/modules/rvm/gemrc > ~/.gemrc")
      g("Done!")
    end
  end

  ##
  # Create a .bashrc in $HOME to load /etc/profile for non-interactive sessions
  if not e.execute_as_root("cat $HOME/.bashrc").include?('source /etc/profile')
    Spinner.return :message => "Configuring #{y('.bashrc')}.." do
      e.execute_as_root("echo 'source /etc/profile' > $HOME/.bashrc; source $HOME/.bashrc")
      g("Done!")
    end
  end

  ##
  # Install required packages for installing Ruby
  Spinner.return :message => "Installing the Ruby Interpreter #{y('dependency packages')}.." do
    e.install!("build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf")
    g("Done!")
  end

  ##
  # Install a Ruby version
  Spinner.return :message => "Installing #{y(ruby_version)} with #{y('rvm')}. This may take a while.." do
    e.execute_as_root("rvm install #{ruby_version}")
    g("Done!")
  end

  ##
  # Set the Ruby version as the default Ruby
  Spinner.return :message => "Making #{y(ruby_version)} the default Ruby.." do
    e.execute_as_root("rvm use #{ruby_version} --default")
    g("Done!")
  end

  ##
  # Clean up Packages
  Spinner.return :message => "Cleaning up Git Pusshu Ten #{y('packages')}.." do
    e.clean_up_packages!("$HOME", :root)
    g("Done!")
  end

  message "Finished!"
end

#perform_install_ruby!Object

Installs a Ruby version with RVM



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/gitpusshuten/modules/rvm/command.rb', line 140

def perform_install_ruby!
  perform_list! # prompts root

  message "Which Ruby version would you like to install?"
  ruby_version = choose_ruby_version!

  message "Would you like to make #{y(ruby_version)} your default Ruby?"
  yes? ? make_default = true : make_default = false

  Spinner.return :message => "Installing #{y(ruby_version)}, this may take a while.." do
    e.execute_as_root("rvm install #{ruby_version}")
    g("Done!")
  end

  if make_default
    Spinner.return :message => "Setting #{y(ruby_version)} as the system wide default Ruby." do
      e.execute_as_root("rvm use #{ruby_version} --default")
      g("Done!")
    end

    ask_to_use_default_ruby_with_passenger!(ruby_version)
  end
end

#perform_list!Object

Displays a list of installed gems



129
130
131
132
133
134
135
136
# File 'lib/gitpusshuten/modules/rvm/command.rb', line 129

def perform_list!
  prompt_for_root_password!

  Spinner.return :message => "Getting a list of installed Rubies.", :put => true do
    e.execute_as_root("rvm list")
  end
  message "The ( #{y("=>")} ) arrow indicates which Ruby version is currently being used."
end

#perform_remove_ruby!Object

Remove a Ruby version



183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/gitpusshuten/modules/rvm/command.rb', line 183

def perform_remove_ruby!
  perform_list! # prompts root

  message "Which Ruby version would you like to remove?"
  ruby_version = choose_ruby_version!

  Spinner.return :message => "Removing #{y(ruby_version)}.." do
    if not e.execute_as_root("rvm remove #{ruby_version}") =~ /is already non existent/
      g("Ruby version #{ruby_version} has been removed.")
    else
      r("Ruby version #{ruby_version} is already non existent.")
    end
  end
end

#perform_set_default_ruby!Object

Change the default Ruby on the server



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/gitpusshuten/modules/rvm/command.rb', line 200

def perform_set_default_ruby!
  perform_list! # prompts root

  message "Which Ruby version would you like to make the system wide default?"
  ruby_version = choose_ruby_version!

  Spinner.return :message => "Changing system wide default Ruby to #{y(ruby_version)}" do
    if not e.execute_as_root("rvm use #{ruby_version} --default") =~ /not installed/
      @succeeded = true
      g("Ruby version #{ruby_version} is now set as the system wide default.")
    else
      r("Could not set #{ruby_version} as default")
    end
  end

  if @succeeded
    ask_to_use_default_ruby_with_passenger!(ruby_version)
  end
end

#perform_uninstall_ruby!Object

Uninstalls a Ruby version



166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/gitpusshuten/modules/rvm/command.rb', line 166

def perform_uninstall_ruby!
  perform_list! # prompts root

  message "Which Ruby version would you like to uninstall?"
  ruby_version = choose_ruby_version!

  Spinner.return :message => "Uninstalling #{y(ruby_version)}.." do
    if not e.execute_as_root("rvm uninstall #{ruby_version}") =~ /has already been removed/
      g("Ruby version #{ruby_version} has been uninstalled.")
    else
      r("Ruby version #{ruby_version} has already been removed.")
    end
  end
end

#perform_update!Object

Performs an update for RVM



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/gitpusshuten/modules/rvm/command.rb', line 115

def perform_update!
  prompt_for_root_password!

  message "Updating RVM."
  message "Would you like to get the latest stable, or bleeding edge version?"
  option = rvm_version?
  Spinner.return :message => "Updating #{y('rvm')} to the #{y(option.nil? ? 'latest stable' : 'bleeding edge')}." do
    e.execute_as_root("rvm update #{option}")
    g("Done!")
  end
end

#rvm_version?Boolean

Prompts the user to choose a RVM version to install

Returns:

  • (Boolean)


238
239
240
241
242
243
244
# File 'lib/gitpusshuten/modules/rvm/command.rb', line 238

def rvm_version?
  choose do |menu|
    menu.prompt = ''
    menu.choice('latest stable') { nil      }
    menu.choice('bleeding edge') { '--head' }
  end
end

#webserver?Boolean

Prompts the user to select a webserver

Returns:

  • (Boolean)


248
249
250
251
252
253
254
# File 'lib/gitpusshuten/modules/rvm/command.rb', line 248

def webserver?
  choose do |menu|
    menu.prompt = ''
    menu.choice('NginX')
    menu.choice('Apache')
  end
end