Skip to content

Commit

Permalink
Improved download method detection on Remote Installer
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitrij Denissenko committed Dec 5, 2009
1 parent ba85e08 commit 465b99f
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions script/remote/retrospectiva_installer.rb
Expand Up @@ -10,20 +10,22 @@ class RemoteInstaller
RUBYGEMS_URL = "http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz"
RAKE_URL = "http://rubyforge.org/frs/download.php/56872/rake-0.8.7.tgz"
VENDOR_URL = "http://cloud.github.com/downloads/dim/retrospectiva/vendor-#{BRANCH}.tar.gz"
DOWNLOADERS = [:curl, :wget]

def self.run!
new.run!
end

def initialize
@rake = false
@rubygems = false
@rake = false
@rubygems = false
end

def run!
puts "\n Retrospectiva Remote Installer\n ==============================\n\n"

check_prerequisites || instruct!
detect_downloader
install_retrospectiva!
install_rubygems!
install_rake!
Expand All @@ -42,6 +44,12 @@ def check_prerequisites
check_lib('sqlite3')
end

def detect_downloader
@downloader = DOWNLOADERS.detect do |m|
system("#{m} --version 1> /dev/null 2> /dev/null", false)
end || abort("[E] Unable to find #{DOWNLOADERS.join(' or ')} in your system path.")
end

def check_lib(name)
begin
require_library_or_gem name
Expand Down Expand Up @@ -202,12 +210,11 @@ def instruct!
DATABASE_FILE = File.join(INSTALL_PATH, 'db', 'production.db')

def download!(url, path)
if system("curl --version > /dev/null")
case @downloader
when :curl
system "curl -s -L #{url} > #{path}"
elsif system("wget --version > /dev/null")
when :wget
system "wget -q -O #{path} #{url}"
else
raise "Unable to find curl or wget in your system path."
end
end

Expand All @@ -219,8 +226,8 @@ def step(description, nl = false)
puts " #{description}" + (nl ? "\n" : '')
end

def system(command)
super(command) || abort("[E] Command '#{command}' failed during execution")
def system(command, raise_on_error = true)
super(command) || (raise_on_error && abort("[E] Command '#{command}' failed during execution"))
end

def ruby_path
Expand Down

0 comments on commit 465b99f

Please sign in to comment.