~ubuntu-branches/ubuntu/wily/ruby-passenger/wily-proposed

« back to all changes in this revision

Viewing changes to lib/phusion_passenger/abstract_installer.rb

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2013-11-23 23:50:02 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20131123235002-8fdhsq7afj15o2z2
Tags: 4.0.25-1
* New upstream release.
* Refresh fix_install_path.patch.
* Build for Ruby 2.0 instead of 1.8. (Closes: #725591)
* Add fix_ftbfs_fortify_source.patch.
* Install passenger template files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
require 'phusion_passenger/platform_info'
28
28
require 'phusion_passenger/platform_info/operating_system'
29
29
require 'phusion_passenger/utils/ansi_colors'
 
30
require 'fileutils'
 
31
require 'etc'
30
32
 
31
33
# IMPORTANT: do not directly or indirectly require native_support; we can't compile
32
34
# it yet until we have a compiler, and installers usually check whether a compiler
69
71
        rescue Abort
70
72
                puts
71
73
                return false
 
74
        rescue SignalException, SystemExit
 
75
                raise
72
76
        rescue PlatformInfo::RuntimeError => e
73
77
                new_screen
74
78
                puts "<red>An error occurred</red>"
75
79
                puts
76
80
                puts e.message
77
81
                exit 1
 
82
        rescue Exception => e
 
83
                show_support_options_for_installer_bug(e)
 
84
                exit 2
78
85
        ensure
79
86
                after_install
80
87
        end
105
112
                STDOUT.write(Utils::AnsiColors::RESET)
106
113
                STDOUT.flush
107
114
        end
 
115
 
 
116
        def users_guide_path
 
117
                return PhusionPassenger.index_doc_path
 
118
        end
 
119
 
 
120
        def users_guide_url
 
121
                return INDEX_DOC_URL
 
122
        end
108
123
        
109
124
        def dependencies
110
125
                return [[], []]
148
163
                                puts "   #{dep.install_instructions}"
149
164
                                puts
150
165
                        end
151
 
                        if respond_to?(:users_guide)
152
 
                                puts "If the aforementioned instructions didn't solve your problem, then please take"
153
 
                                puts "a look at the Users Guide:"
154
 
                                puts
155
 
                                puts "  <yellow>#{users_guide}</yellow>"
156
 
                        end
 
166
                        puts "If the aforementioned instructions didn't solve your problem, then please take"
 
167
                        puts "a look at the Users Guide:"
 
168
                        puts
 
169
                        puts "  <yellow>#{users_guide_path}</yellow>"
 
170
                        puts "  <yellow>#{users_guide_url}</yellow>"
157
171
                        return false
158
172
                end
159
173
        end
160
174
 
161
175
        def check_whether_os_is_broken
162
 
                if PlatformInfo.os_name == "freebsd9" && `uname -r` =~ /^9\.1-/
163
 
                        new_screen
164
 
                        render_template 'installer_common/freebsd9_broken_cxx_runtime'
 
176
                # No known broken OSes at the moment.
 
177
        end
 
178
 
 
179
        def check_gem_install_permission_problems
 
180
                return true if PhusionPassenger.natively_packaged?
 
181
                begin
 
182
                        require 'rubygems'
 
183
                rescue LoadError
 
184
                        return true
 
185
                end
 
186
 
 
187
                if Process.uid != 0 &&
 
188
                   PhusionPassenger.source_root =~ /^#{Regexp.escape home_dir}\// &&
 
189
                   PhusionPassenger.source_root =~ /^#{Regexp.escape Gem.dir}\// &&
 
190
                   File.stat(PhusionPassenger.source_root).uid == 0
 
191
                        new_screen
 
192
                        render_template 'installer_common/gem_install_permission_problems'
 
193
                        return false
 
194
                else
 
195
                        return true
 
196
                end
 
197
        end
 
198
 
 
199
        def check_directory_accessible_by_web_server
 
200
                return true if PhusionPassenger.natively_packaged?
 
201
                inaccessible_directories = []
 
202
                list_parent_directories(PhusionPassenger.source_root).each do |path|
 
203
                        if !world_executable?(path)
 
204
                                inaccessible_directories << path
 
205
                        end
 
206
                end
 
207
                if !inaccessible_directories.empty?
 
208
                        new_screen
 
209
                        render_template 'installer_common/world_inaccessible_directories',
 
210
                                :directories => inaccessible_directories
165
211
                        wait
166
212
                end
167
213
        end
189
235
                                :current => ram_mb + swap_mb,
190
236
                                :ram => ram_mb,
191
237
                                :swap => swap_mb,
192
 
                                :doc => users_guide
 
238
                                :doc_path => users_guide_path,
 
239
                                :doc_url => users_guide_url
193
240
                        wait
194
241
                end
195
242
        end
 
243
 
 
244
        def show_support_options_for_installer_bug(e)
 
245
                # We do not use template rendering here. Since we've determined that there's
 
246
                # a bug, *anything* may be broken, so we use the safest codepath to ensure that
 
247
                # the user sees the proper messages.
 
248
                begin
 
249
                        line
 
250
                        @stderr.puts "*** EXCEPTION: #{e} (#{e.class})\n    " +
 
251
                                e.backtrace.join("\n    ")
 
252
                        new_screen
 
253
                        puts '<red>Oops, something went wrong :-(</red>'
 
254
                        puts
 
255
                        puts "We're sorry, but it looks like this installer ran into an unexpected problem.\n" +
 
256
                                "Please visit the following website for support. We'll do our best to help you.\n\n" +
 
257
                                "  <b>#{SUPPORT_URL}</b>\n\n" +
 
258
                                "When submitting a support inquiry, please copy and paste the entire installler\n" +
 
259
                                "output."
 
260
                rescue Exception => e2
 
261
                        # Raise original exception so that it doesn't get lost.
 
262
                        raise e
 
263
                end
 
264
        end
196
265
        
197
266
        
198
267
        def use_stderr
199
268
                old_stdout = @stdout
200
269
                begin
201
 
                        @stdout = STDERR
 
270
                        @stdout = @stderr
202
271
                        yield
203
272
                ensure
204
273
                        @stdout = old_stdout
212
281
        
213
282
        def puts(text = nil)
214
283
                if text
215
 
                        @stdout.puts(Utils::AnsiColors.ansi_colorize(text))
 
284
                        @stdout.puts(Utils::AnsiColors.ansi_colorize(text.to_s))
216
285
                else
217
286
                        @stdout.puts
218
287
                end
302
371
        rescue Interrupt
303
372
                raise Abort
304
373
        end
 
374
 
 
375
        def home_dir
 
376
                Etc.getpwuid(Process.uid).dir
 
377
        end
305
378
        
306
379
        
307
380
        def sh(*args)
341
414
                sh!("#{PlatformInfo.rake_command} #{args.join(' ')}")
342
415
        end
343
416
        
344
 
        def download(url, output)
 
417
        def download(url, output, options = {})
 
418
                if options[:use_cache] && cache_dir = PhusionPassenger.download_cache_dir
 
419
                        basename = url.sub(/.*\//, '')
 
420
                        if File.exist?("#{cache_dir}/#{basename}")
 
421
                                puts "Copying #{basename} from #{cache_dir}..."
 
422
                                FileUtils.cp("#{cache_dir}/#{basename}", output)
 
423
                                return true
 
424
                        end
 
425
                end
 
426
 
 
427
                args = []
345
428
                if PlatformInfo.find_command("wget")
346
 
                        return sh("wget", "-O", output, url)
 
429
                        if options[:cacert]
 
430
                                args << "--ca-certificate=#{options[:cacert]}"
 
431
                        end
 
432
                        return sh("wget", "--tries=3", "-O", output, url, *args)
347
433
                else
348
 
                        return sh("curl", url, "-f", "-L", "-o", output)
349
 
                end
 
434
                        if options[:cacert]
 
435
                                args << "--cacert"
 
436
                                args << options[:cacert]
 
437
                        end
 
438
                        return sh("curl", url, "-f", "-L", "-o", output, *args)
 
439
                end
 
440
        end
 
441
 
 
442
        def list_parent_directories(dir)
 
443
                dirs = []
 
444
                components = File.expand_path(dir).split(File::SEPARATOR)
 
445
                components.shift # Remove leading /
 
446
                components.size.times do |i|
 
447
                        dirs << File::SEPARATOR + components[0 .. i].join(File::SEPARATOR)
 
448
                end
 
449
                return dirs.reverse
 
450
        end
 
451
 
 
452
        def world_executable?(dir)
 
453
                begin
 
454
                        stat = File.stat(dir)
 
455
                rescue Errno::EACCESS
 
456
                        return false
 
457
                end
 
458
                return stat.mode & 0000001 != 0
350
459
        end
351
460
end
352
461