On Dec 21, 2006, at 11:13 AM, Charles Brian Quinn wrote:
> Thanks Steven,
>
> This is using Jamis' net/ssh library and using:
>
> sudo cmd do |channel, stream, data|
> data.each_line do | line |
>
> to regex match lines and type in input. this could work, but i was
> hoping for bash or something simpler....
>
> Guess that means it's time to move my all of my shell scripts over to
> ruby (except for the one that installs ruby) ;-)
>
> Thanks!
Charles-
You and me both. I didn't want to spend the time writing bash
scripts for this when I need to do it on tons of machines anyway. So
the script he linked to is actually a capistrano plugin. Take the
file and put it somewhere in your load path and then require it from
a capistrano recipe file and then you can use it like this:
require 'cap_gem'
task :install_gems, :roles => :app do
gem.select 'mongrel' , 'http://mongrel.rubyforge.org/releases'
gem.install 'mongrel', 'http://mongrel.rubyforge.org/releases' ,
'1.0'
end
select will select the most recent versions for the current platform
and install it. install will install a specific version but won't
auto select from a menu. So is there are two or more versions of a
gem then you want to use select.
Here is the more current version of the plugin for cap. This one
supports the --source option.
require 'rubygems'
require 'capistrano'
# Installs within Capistrano as the plugin _gem_.
# Prefix all calls to the library with <tt>gem.</tt>
# Manages installing gems and versioned gems.
module Gem
# Default install command
#
# * doesn't install documentation
# * installs all required dependencies automatically.
#
GEM_INSTALL="gem install -y --no-rdoc"
# Upgrade the *gem* system to the latest version. Runs via *sudo*
def update_system
sudo "gem update --system"
end
# Updates all the installed gems to the latest version. Runs via
*sudo*.
# Don't use this command if any of the gems require a version
selection.
def upgrade
sudo "gem update --no-rdoc"
end
# Removes old versions of gems from installation area.
def cleanup
sudo "gem cleanup"
end
# Installs the gems detailed in +packages+, selecting version
+version+ if
# specified.
#
# +packages+ can be a single string or an array of strings.
#
def install(packages, source=nil, version=nil)
sudo "#{GEM_INSTALL} #{version ? '-v '+version.to_s : nil} #
{source ? '--source='+source : nil } #{packages.to_a.join(' ')}"
end
def uninstall(package)
sudo "gem uninstall #{package}" do |channel, stream, data|
data.each_line do |line|
if line =~ /\[Yn\]/
channel.send_data "Y\n"
end
end
end
end
# Auto selects a gem from a list and installs it.
#
# *gem* has no mechanism on the command line of disambiguating
builds for
# different platforms, and instead asks the user. This method has
the necessary
# conversation to select the +version+ relevant to +platform+ (or
the one nearest
# the top of the list if you don't specify +version+).
def select(package, source=nil, version=nil, platform='ruby')
selections={}
cmd="#{GEM_INSTALL} #{version ? '-v '+version.to_s : nil} #
{package} #{source ? '--source='+source : nil }"
sudo cmd do |channel, stream, data|
data.each_line do | line |
case line
when /\s(\d+).*\(#{platform}\)/
if selections[channel[:host]].nil?
selections[channel[:host]]=$1.dup+"\n"
logger.info "Selecting #$&", "#{stream} :: #{channel[:host]}"
end
when /\s\d+\./
# Discard other selections from data stream
when /^>/
channel.send_data selections[channel[:host]]
logger.debug line, "#{stream} :: #{channel[:host]}"
else
logger.info line, "#{stream} :: #{channel[:host]}"
end
end
end
end
end
Capistrano.plugin :gem, Gem
Cheers-
-- Ezra Zygmuntowicz-- Lead Rails Evangelist
-- [EMAIL PROTECTED]
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)
_______________________________________________
Mongrel-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/mongrel-users