/
abstract_installer.rb
197 lines (177 loc) · 4.56 KB
/
abstract_installer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# Phusion Passenger - http://www.modrails.com/
# Copyright (C) 2009 Phusion
#
# Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
require 'phusion_passenger/console_text_template'
require 'phusion_passenger/version'
module PhusionPassenger
# Abstract base class for installers. Used by passenger-install-apache2-module
# and passenger-install-nginx-module.
class AbstractInstaller
PASSENGER_WEBSITE = "http://www.modrails.com/"
PHUSION_WEBSITE = "www.phusion.nl"
USERS_GUIDE = begin
if PhusionPassenger.natively_packaged?
"/usr/share/doc/phusion_passenger/Users guide.html"
else
File.expand_path("#{LIBDIR}/../../doc/Users guide.html")
end
end
def initialize(options = {})
options.each_pair do |key, value|
instance_variable_set(:"@#{key}", value)
end
end
def start
install!
ensure
reset_terminal_colors
end
private
def reset_terminal_colors
STDOUT.write("\e[0m")
STDOUT.flush
end
def color_print(text)
STDOUT.write(ConsoleTextTemplate.new(:text => text).result)
STDOUT.flush
end
def color_puts(text)
color_print("#{text}\n")
end
def render_template(name, options = {})
puts ConsoleTextTemplate.new({ :file => name }, options).result
end
def new_screen
puts
line
puts
end
def line
puts "--------------------------------------------"
end
def prompt(message)
done = false
while !done
color_print "#{message}: "
begin
result = STDIN.readline
rescue EOFError
exit 2
end
result.strip!
done = !block_given? || yield(result)
end
return result
rescue Interrupt
exit 2
end
def wait(timeout = nil)
return if @auto
begin
if timeout
require 'timeout' unless defined?(Timeout)
begin
Timeout.timeout(timeout) do
STDIN.readline
end
rescue Timeout::Error
# Do nothing.
end
else
STDIN.readline
end
rescue Interrupt
exit 2
end
end
def sh(*args)
puts "# #{args.join(' ')}"
result = system(*args)
if result
return true
elsif $?.signaled? && $?.termsig == Signal.list["INT"]
raise Interrupt
else
return false
end
end
def dependencies
return []
end
def check_dependencies
new_screen
missing_dependencies = []
color_puts "<banner>Checking for required software...</banner>"
puts
dependencies.each do |dep|
color_print " * #{dep.name}... "
result = dep.check
if result.found?
if result.found_at
color_puts "<green>found at #{result.found_at}</green>"
else
color_puts "<green>found</green>"
end
else
color_puts "<red>not found</red>"
missing_dependencies << dep
end
end
if missing_dependencies.empty?
return true
else
puts
color_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>"
if Passenger.natively_packaged?
wait(10)
else
wait
end
line
puts
color_puts "<banner>Installation instructions for required software</banner>"
puts
missing_dependencies.each do |dep|
print_dependency_installation_instructions(dep)
puts
end
color_puts "If the aforementioned instructions didn't solve your problem, then please take"
color_puts "a look at the Users Guide:"
puts
color_puts " <yellow>#{USERS_GUIDE}</yellow>"
return false
end
end
def print_dependency_installation_instructions(dep)
color_puts " * To install <yellow>#{dep.name}</yellow>:"
if !dep.install_command.nil?
color_puts " Please run <b>#{dep.install_command}</b> as root."
elsif !dep.install_instructions.nil?
color_puts " " << dep.install_instructions
elsif !dep.website.nil?
color_puts " Please download it from <b>#{dep.website}</b>"
if !dep.website_comments.nil?
color_puts " (#{dep.website_comments})"
end
else
color_puts " Search Google."
end
end
end
end # module PhusionPassenger