Class: Web::Install::Apache

Inherits:
Object show all
Includes:
FileUtils
Defined in:
lib/web/sapi/install/apache.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(install_dir, httpd_conf) ⇒ Apache

Returns a new instance of Apache.



12
13
14
15
# File 'lib/web/sapi/install/apache.rb', line 12

def initialize( install_dir, httpd_conf )
  @install_dir = install_dir
  @httpd_conf  = httpd_conf
end

Instance Attribute Details

#httpd_confObject

Returns the value of attribute httpd_conf.



11
12
13
# File 'lib/web/sapi/install/apache.rb', line 11

def httpd_conf
  @httpd_conf
end

#install_dirObject

Returns the value of attribute install_dir.



11
12
13
# File 'lib/web/sapi/install/apache.rb', line 11

def install_dir
  @install_dir
end

Class Method Details

.install(install_dir, httpd_conf) ⇒ Object



7
8
9
# File 'lib/web/sapi/install/apache.rb', line 7

def Apache::install( install_dir, httpd_conf )
  self.new(install_dir, httpd_conf).install
end

Instance Method Details

#apacheObject



21
22
23
24
25
26
# File 'lib/web/sapi/install/apache.rb', line 21

def apache
  [apache_root + "/Apache.exe",
   apache_root + "/bin/Apache.exe" ].find do |f|
    File.exists? f
  end
end

#apache_rootObject



17
18
19
# File 'lib/web/sapi/install/apache.rb', line 17

def apache_root
  File.dirname( File.dirname( httpd_conf ) )
end

#backupObject



41
42
43
# File 'lib/web/sapi/install/apache.rb', line 41

def backup
	"#{httpd_conf}.ruby-web.backup.#{Time::now::strftime('%Y.%m.%d') }"
end

#installObject



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
# File 'lib/web/sapi/install/apache.rb', line 57

def install
  puts "******************************************",
       "* Installing .rhtml and .rb mappings     *",
       "* for Apache                             *",
       "******************************************"    
	
	new_conf = ''
	lines = File.open( httpd_conf, "r" ) {|f| f.read }
	lines.each do |line|
	  if line =~ /index.html/ && ! line =~ /index.rhtml/
	    line.gsub!(/index.html/,'index.html index.php')
	  end
	  if line =~ /AddHandler cgi-script.*(\.rb|\.rhtml)/
	    ruby_conf.delete_at(0)
	  end
	  new_conf += line + "\n"
	end
	
	cp( httpd_conf, backup )
     
  config_file_changed = false

  if ruby_conf.empty?
    # apparently there is nothing to do...
  else
	  new_conf += "\n\n################# Ruby Web ###################\n"
	  new_conf += ruby_conf.join "\n"
	
	  File.open(temp, "w") do |f|
      f.write new_conf
    end
  
    cp( temp, httpd_conf )
  
    config_file_changed = true

    # ----------- Restart Apache ------------
    unless system(test_config_cmd)
      puts("[ruby-web #{$0}]: Unable that the Apache webserver is running correcly with the new module and the configuration file changes using the '#{test_config_cmd}' command.  Ruby-Web itself has been installed sucessfully, but it has not been activated.  Your old #{httpd_conf} file is untouched...")
      puts "[ruby-web #{$0}]: The modified config file is available in '#{temp}' so you can examine it and try to activate Ruby-Web"
    
      cp( backup, conf )
    else
      # restart apache
      system('net stop apache')
	    system('net start apache')
	  end
	end
end

#ruby_confObject



49
50
51
52
53
54
55
# File 'lib/web/sapi/install/apache.rb', line 49

def ruby_conf
	unless @ruby_conf
    @ruby_conf = Array.new
    @ruby_conf.push "AddHandler cgi-script .rb .rhtml"
  end
  @ruby_conf
end

#tempObject



45
46
47
# File 'lib/web/sapi/install/apache.rb', line 45

def temp
  "#{httpd_conf}.ruby-web.temp"
end

#test_config_cmdObject



28
29
30
# File 'lib/web/sapi/install/apache.rb', line 28

def test_config_cmd
  apache + " -t" if apache
end

#versionObject



32
33
34
35
36
37
38
39
# File 'lib/web/sapi/install/apache.rb', line 32

def version
  case apache
  when apache_root + "/Apache.exe"
    1
  when apache_root + "/bin/Apache.exe"
    2
  end
end