Skip to content

Commit

Permalink
Refactor AbstractInstaller.
Browse files Browse the repository at this point in the history
  • Loading branch information
FooBarWidget committed Dec 7, 2010
1 parent 930ed9a commit ba1f02e
Show file tree
Hide file tree
Showing 8 changed files with 278 additions and 136 deletions.
7 changes: 3 additions & 4 deletions bin/passenger-install-apache2-module
Expand Up @@ -40,7 +40,6 @@ require 'phusion_passenger/abstract_installer'

class Installer < PhusionPassenger::AbstractInstaller
include PhusionPassenger
include PhusionPassenger::PlatformInfo

def dependencies
result = [
Expand Down Expand Up @@ -77,7 +76,7 @@ class Installer < PhusionPassenger::AbstractInstaller
return "#{DOCDIR}/Users guide Apache.html"
end

def install!
def run_steps
if PhusionPassenger.natively_packaged?
check_dependencies || exit(1)
show_apache2_config_snippets
Expand Down Expand Up @@ -151,7 +150,7 @@ private
def install_apache2_module
puts
line
color_puts '<banner>Compiling and installing Apache 2 module...</banner>'
puts '<banner>Compiling and installing Apache 2 module...</banner>'
puts "cd #{PASSENGER_ROOT}"
if ENV['TRACE']
puts "#{PlatformInfo.rake_command} --trace apache2:clean apache2 RELEASE=yes"
Expand Down Expand Up @@ -233,5 +232,5 @@ installer = Installer.new(options)
if options[:snippet]
installer.send(:show_apache2_config_snippets, true)
else
installer.start
installer.run
end
45 changes: 22 additions & 23 deletions bin/passenger-install-nginx-module
Expand Up @@ -33,7 +33,6 @@ require 'phusion_passenger/abstract_installer'

class Installer < PhusionPassenger::AbstractInstaller
include PhusionPassenger
include PhusionPassenger::PlatformInfo

def dependencies
result = [
Expand All @@ -59,7 +58,7 @@ class Installer < PhusionPassenger::AbstractInstaller
return "#{DOCDIR}/Users guide Nginx.html"
end

def install!
def run_steps
Dir.chdir(SOURCE_ROOT)
show_welcome_screen
check_dependencies || exit(1)
Expand Down Expand Up @@ -126,7 +125,7 @@ private

def compile_passenger_support_files
new_screen
color_puts "<banner>Compiling Passenger support files...</banner>"
puts "<banner>Compiling Passenger support files...</banner>"
return sh("#{PlatformInfo.rake_command} nginx:clean nginx RELEASE=yes")
end

Expand All @@ -137,20 +136,20 @@ private
puts

if @auto_download
color_puts "<b>=> Proceeding with choice 1.</b>"
puts "<b>=> Proceeding with choice 1.</b>"
return true
elsif @nginx_source_dir
color_puts "<b>=> Proceeding with choice 2.</b>"
puts "<b>=> Proceeding with choice 2.</b>"
return false
else
choice = prompt("Enter your choice (1 or 2) or press Ctrl-C to abort") do |input|
if input == "1" || input == "2"
true
elsif input.empty?
color_puts "<red>No choice has been given.</red>"
puts "<red>No choice has been given.</red>"
false
else
color_puts "<red>'#{input}' is not a valid choice.</red>"
puts "<red>'#{input}' is not a valid choice.</red>"
false
end
end
Expand All @@ -160,15 +159,15 @@ private

def download_and_extract_pcre
new_screen
color_puts "<banner>PCRE (required by Nginx) not installed, downloading it...</banner>"
puts "<banner>PCRE (required by Nginx) not installed, downloading it...</banner>"

url = "ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-#{PREFERRED_PCRE_VERSION}.tar.gz"
dirname = "pcre-#{PREFERRED_PCRE_VERSION}"
tarball = "#{@working_dir}/pcre.tar.gz"

if download(url, tarball)
Dir.chdir(@working_dir) do
color_puts "<banner>Extracting PCRE source tarball...</banner>"
puts "<banner>Extracting PCRE source tarball...</banner>"
if sh("tar", "xzvf", tarball)
return "#{@working_dir}/#{dirname}"
else
Expand All @@ -190,15 +189,15 @@ private

def download_and_extract_nginx
new_screen
color_puts "<banner>Downloading Nginx...</banner>"
puts "<banner>Downloading Nginx...</banner>"

url = "http://sysoev.ru/nginx/nginx-#{PREFERRED_NGINX_VERSION}.tar.gz"
dirname = "nginx-#{PREFERRED_NGINX_VERSION}"
tarball = "#{@working_dir}/nginx.tar.gz"

if download(url, tarball)
Dir.chdir(@working_dir) do
color_puts "<banner>Extracting Nginx source tarball...</banner>"
puts "<banner>Extracting Nginx source tarball...</banner>"
if sh("tar", "xzvf", tarball)
return "#{@working_dir}/#{dirname}"
else
Expand All @@ -220,17 +219,17 @@ private

def ask_for_nginx_install_prefix
new_screen
color_puts "<banner>Where do you want to install Nginx to?</banner>"
puts "<banner>Where do you want to install Nginx to?</banner>"
puts
if @prefix
color_puts "<b>=> #{@prefix}</b>"
puts "<b>=> #{@prefix}</b>"
return @prefix
else
prefix = prompt("Please specify a prefix directory [/opt/nginx]") do |input|
if input.empty? || input =~ %r(/)
true
else
color_puts "<red>Please specify an absolute path.</red>"
puts "<red>Please specify an absolute path.</red>"
false
end
end
Expand All @@ -243,22 +242,22 @@ private

def ask_for_nginx_source_dir
new_screen
color_puts "<banner>Where is your Nginx source code located?</banner>"
puts "<banner>Where is your Nginx source code located?</banner>"
puts
if @nginx_source_dir
color_puts "<b>=> #{@nginx_source_dir}</b>"
puts "<b>=> #{@nginx_source_dir}</b>"
return @nginx_source_dir
else
return prompt("Please specify the directory") do |input|
if input =~ %r(/)
if File.exist?("#{input}/src/core/nginx.c")
true
else
color_puts "<red>'#{input}' does not look like an Nginx source directory.</red>"
puts "<red>'#{input}' does not look like an Nginx source directory.</red>"
false
end
else
color_puts "<red>Please specify an absolute path.</red>"
puts "<red>Please specify an absolute path.</red>"
false
end
end
Expand All @@ -275,10 +274,10 @@ private
if @extra_configure_flags
if @extra_configure_flags == "none"
extra_args = ""
color_puts "<b>=> No extra configure flags.</b>"
puts "<b>=> No extra configure flags.</b>"
else
extra_args = @extra_configure_flags
color_puts "<b>=> #{extra_args}</b>"
puts "<b>=> #{extra_args}</b>"
end
return extra_args
else
Expand All @@ -292,7 +291,7 @@ private
if input.empty? || input == "yes" || input == "no"
true
else
color_puts "<red>Please enter 'yes' or 'no'.</red>"
puts "<red>Please enter 'yes' or 'no'.</red>"
false
end
end
Expand Down Expand Up @@ -325,7 +324,7 @@ private
def install_nginx(source_dir, prefix, extra_configure_flags)
Dir.chdir(source_dir) do
new_screen
color_puts "<banner>Compiling and installing Nginx...</banner>"
puts "<banner>Compiling and installing Nginx...</banner>"
if !sh(build_nginx_configure_command(prefix, extra_configure_flags)) ||
!sh("make") ||
!sh("make install")
Expand Down Expand Up @@ -473,4 +472,4 @@ if options[:auto_download] && options[:nginx_source_dir]
exit 1
end

Installer.new(options).start
Installer.new(options).run

0 comments on commit ba1f02e

Please sign in to comment.