Guest User

Untitled

a guest
Feb 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. ## Will add a new rails host for the specified directory.
  4. ## Usage: sudo board-train directory domain
  5.  
  6. if ARGV[0].nil? || ARGV[1].nil?
  7. puts "Usage: #{__FILE__} directory domain"
  8. exit
  9. end
  10.  
  11. domain = ARGV[1]
  12. app_dir = File.join(File.expand_path(ARGV[0]), "public")
  13.  
  14. puts "Domain: #{domain}"
  15. puts "Path: #{app_dir}"
  16.  
  17. File.open("/etc/hosts", "a") do |f|
  18. f.puts "127.0.0.1 #{domain}"
  19. end
  20.  
  21. vhost_template = <<END
  22. <VirtualHost *:80>
  23. RailsEnv development
  24. ServerName #{domain}
  25. DocumentRoot #{app_dir}
  26. <Directory "#{app_dir}">
  27. Order allow,deny
  28. Allow from all
  29. </Directory>
  30. </VirtualHost>
  31. END
  32.  
  33. File.open("/etc/apache2/sites/#{domain}", "w+") do |f|
  34. f.write vhost_template
  35. end
  36.  
  37. system "apachectl restart"
Add Comment
Please, Sign In to add comment