Skip to content

Instantly share code, notes, and snippets.

@Sutto
Created July 23, 2008 17:15
Show Gist options
  • Save Sutto/1816 to your computer and use it in GitHub Desktop.
Save Sutto/1816 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
## Will add a new rails host for the specified directory.
## Usage: sudo board-train directory domain
if ARGV[0].nil? || ARGV[1].nil?
puts "Usage: #{__FILE__} directory domain"
exit
end
domain = ARGV[1]
app_dir = File.join(File.expand_path(ARGV[0]), "public")
puts "Domain: #{domain}"
puts "Path: #{app_dir}"
File.open("/etc/hosts", "a") do |f|
f.puts "127.0.0.1 #{domain}"
end
vhost_template = <<END
<VirtualHost *:80>
RailsEnv development
ServerName #{domain}
DocumentRoot #{app_dir}
<Directory "#{app_dir}">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
END
File.open("/etc/apache2/sites/#{domain}", "w+") do |f|
f.write vhost_template
end
system "apachectl restart"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment