Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 66 lines (50 sloc) 1.49 KB
#!/usr/bin/env ruby
begin
require 'rubygems'
rescue LoadError
end
require 'yaml'
CONFIG_PATH = '/etc/httpd/conf'
# No syntax checking whatsoever on the yaml files. You're on your own.
class Vhost
def initialize(args)
# This might be dangerous? I'm pretty sure we can trust whoever's
# writing our vhost definitions :)
args.each do |k,v|
instance_variable_set "@#{k}", v
end
@type ||= 'standard'
# We need to wrap @location in slashes, but if it's root, that gives us
# // or ///, so we collapse multiple sequential slashes to a single /.
@location = "/#{@location}/"
@location.gsub!(/\/+/,'/')
@types = YAML.load(open("#{CONFIG_PATH}/types.yml"))
end
def to_s
if @types.has_key? @type
eval("return \"#{@types[@type]}\"")
end
end
end
output = ""
# Default/catchall vhost.
output << <<END
<VirtualHost *>
DocumentRoot /srv/http/localhost/htdocs
</VirtualHost>
END
hosts = YAML.load(open("#{CONFIG_PATH}/vhosts.yml"))
begin
hosts.each do |k,v|
vhost = Vhost.new(v.merge({'domain' => k}))
output << vhost.to_s
end
rescue
exit 1 # Just return an error. We don't care what it is.
# The initscript will smack somebody on the head and fail.
end
# Write the output file and commit it to git.
File.open("#{CONFIG_PATH}/vhosts.gen/vhosts.gen.conf",'w') do |f|
f.puts output
`cd "#{CONFIG_PATH}/vhosts.gen"; git commit -a -m 'generated by generate-vhosts'`
end