disabled
  1   ˆl–ßi~”Jj"TÊ�zà¸TÅ£�þ@³€yÑ²ø^!YùÂ0ÁÀ¿  5   ˆl–Ü4ý( ©¤ýÔâ�rà[¸ )‹Fÿ�þB g#É’Œ_ÏÃƒh¹ÂÁÀ      disabled
  7   ˆl–Ü4ý( ©¤ýÔâ�rà›¸ÛÊbÑ¿‘äÇò 8à	€‘¦FA?Äƒh¹ÃÂÁ      0
  F   	ˆl–Ãa¾”ªeJe@ãB¸©‹Fÿ�þ\}–ÖnVYhB#Ò”€þÅ„�²ÏÄ_�uÐb&=LyZËcõÄÃ ?÷     	# encoding: utf-8
#  Phusion Passenger - https://www.phusionpassenger.com/
#  Copyright (c) 2014-2017 Phusion Holding B.V.
#
#  "Passenger", "Phusion Passenger" and "Union Station" are registered
#  trademarks of Phusion Holding B.V.
#
#  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 'optparse'
PhusionPassenger.require_passenger_lib 'constants'
PhusionPassenger.require_passenger_lib 'config/command'

module PhusionPassenger
  module Config

    class ValidateInstallCommand < Command
      # Signifies that there is at least 1 error.
      FAIL_EXIT_CODE = 1
      # Signifies that there are no error, but at least 1 warning.
      WARN_EXIT_CODE = 2
      # Internal error occurred.
      INTERNAL_ERROR_CODE = 9

      def run
        @orig_argv = @argv.dup
        parse_options
        prepare
        begin
          if !@options[:auto] && !@options[:invoked_from_installer]
            ask_what_to_validate
          end
          if @options[:validate_apache2]
            initialize_apache_envvars
            if !@options[:auto] && !@options[:invoked_from_installer]
              check_whether_there_are_multiple_apache_installs
            end
          end

          if @options[:validate_passenger]
            check_tools_in_path
            check_no_other_installs_in_path
          end
          if @options[:validate_apache2]
            if check_apache2_installed
              check_apache2_load_module_config
            end
          end

          if @options[:summary]
            summarize
          end
          exit(FAIL_EXIT_CODE) if @error_count > 0
          exit(WARN_EXIT_CODE) if @warning_count > 0
        ensure
          reset_terminal
        end
      end

    private
      def self.create_default_options
        return {
          :auto => !STDIN.tty?,
          :validate_passenger => true,
          :colors => STDOUT.tty?,
          :summary => true
        }
      end

      def self.create_option_parser(options)
        OptionParser.new do |opts|
          nl = "\n" + ' ' * 37
          opts.banner = "Usage: passenger-config validate-install [OPTIONS]\n"
          opts.separator ""
          opts.separator "  Validate this #{SHORT_PROGRAM_NAME} installation and/or its integration with web servers."
          opts.separator "  If you run this command in a terminal, it will run interactively and ask you questions."
          opts.separator "  You can run this command non-interactively either by running it without a terminal, "
          opts.separator "  or by passing --auto."
          opts.separator ""
          opts.separator "  When running non-interactively, the default is to validate the #{SHORT_PROGRAM_NAME}"
          opts.separator "  installation only (so e.g. Apache is not valida