# Phusion Passenger - http://www.modrails.com/# Copyright (c) 2010 Phusion## "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.## Permission is hereby granted, free of charge, to any person obtaining a copy# of this software and associated documentation files (the "Software"), to deal# in the Software without restriction, including without limitation the rights# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell# copies of the Software, and to permit persons to whom the Software is# furnished to do so, subject to the following conditions:## The above copyright notice and this permission notice shall be included in# all copies or substantial portions of the Software.## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN# THE SOFTWARE.require'phusion_passenger'require'phusion_passenger/constants'require'phusion_passenger/console_text_template'require'phusion_passenger/platform_info'# IMPORTANT: do not directly or indirectly require native_support; we can't compile# it yet until we have a compiler, and installers usually check whether a compiler# is installed.modulePhusionPassenger# Abstract base class for text mode installers. Used by# passenger-install-apache2-module and passenger-install-nginx-module.## Subclasses must at least implement the #install! method which handles# the installation itself.## Usage:## installer = ConcereteInstallerClass.new(options...)# installer.startclassAbstractInstallerPASSENGER_WEBSITE="http://www.modrails.com/"PHUSION_WEBSITE="www.phusion.nl"# Create an AbstractInstaller. All options will be stored as instance# variables, for example:## installer = AbstractInstaller.new(:foo => "bar")# installer.instance_variable_get(:"@foo") # => "bar"definitialize(options={})options.each_pairdo|key,value|instance_variable_set(:"@#{key}",value)endend# Start the installation by calling the #install! method.defstartbefore_installinstall!rescuePlatformInfo::RuntimeError=>enew_screencolor_puts"<red>An error occurred</red>"putsputse.messageexit1ensureafter_installendprivatedefbefore_install# Hook for subclasses.enddefafter_install# Reset terminal colors.STDOUT.write("\e[0m")STDOUT.flushenddefcolor_print(text)STDOUT.write(ConsoleTextTemplate.new(:text=>text).result)STDOUT.flushenddefcolor_puts(text)color_print("#{text}\n")enddefrender_template(name,options={})putsConsoleTextTemplate.new({:file=>name},options).resultenddefnew_screenputslineputsenddeflineputs"--------------------------------------------"enddefprompt(message)done=falsewhile!donecolor_print"#{message}: "beginresult=STDIN.readlinerescueEOFErrorexit2endresult.strip!done=!block_given?||yield(result)endreturnresultrescueInterruptexit2enddefwait(timeout=nil)returnif@autobeginiftimeoutrequire'timeout'unlessdefined?(Timeout)beginTimeout.timeout(timeout)doSTDIN.readlineendrescueTimeout::Error# Do nothing.endelseSTDIN.readlineendrescueInterruptexit2endenddefsh(*args)puts"# #{args.join(' ')}"result=system(*args)ifresultreturntrueelsif$?.signaled?&&$?.termsig==Signal.list["INT"]raiseInterruptelsereturnfalseendenddefdependenciesreturn[]enddefcheck_dependencies(show_new_screen=true)new_screenifshow_new_screenmissing_dependencies=[]color_puts"<banner>Checking for required software...</banner>"putsdependencies.eachdo|dep|color_print" * #{dep.name}... "result=dep.checkifresult.found?ifresult.found_atcolor_puts"<green>found at #{result.found_at}</green>"elsecolor_puts"<green>found</green>"endelsecolor_puts"<red>not found</red>"missing_dependencies<<dependendifmissing_dependencies.empty?returntrueelseputscolor_puts"<red>Some required software is not installed.</red>"color_puts"But don't worry, this installer will tell you how to install them.\n"color_puts"<b>Press Enter to continue, or Ctrl-C to abort.</b>"ifPhusionPassenger.natively_packaged?wait(10)elsewaitendlineputscolor_puts"<banner>Installation instructions for required software</banner>"putsmissing_dependencies.eachdo|dep|print_dependency_installation_instructions(dep)putsendifrespond_to?(:users_guide)color_puts"If the aforementioned instructions didn't solve your problem, then please take"color_puts"a look at the Users Guide:"putscolor_puts" <yellow>#{users_guide}</yellow>"endreturnfalseendenddefprint_dependency_installation_instructions(dep)color_puts" * To install <yellow>#{dep.name}</yellow>:"ifdep.install_commentscolor_puts" "<<dep.install_commentsendif!dep.install_command.nil?color_puts" Please run <b>#{dep.install_command}</b> as root."elsif!dep.install_instructions.nil?color_puts" "<<dep.install_instructionselsif!dep.website.nil?color_puts" Please download it from <b>#{dep.website}</b>"if!dep.website_comments.nil?color_puts" (#{dep.website_comments})"endelsecolor_puts" Search Google."endenddefdownload(url,output)ifPlatformInfo.find_command("wget")returnsh("wget","-O",output,url)elsereturnsh("curl",url,"-f","-L","-o",output)endendendend# module PhusionPassenger