generate_vhosts 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/generate_vhosts +23 -0
- data/lib/generate_vhosts.rb +38 -0
- data/lib/template.vhost.erb +11 -0
- metadata +69 -0
data/bin/generate_vhosts
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'generate_vhosts'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
OptionParser.new do |opts|
|
7
|
+
opts.banner = "Usage: generate_vhosts [options]"
|
8
|
+
|
9
|
+
opts.on("-d", "--directory DIR", "The directory your projects are located, defaults to ~/code") do |d|
|
10
|
+
@dir = d
|
11
|
+
end
|
12
|
+
|
13
|
+
opts.on_tail("-h", "--help", "Show this help message.") do
|
14
|
+
puts opts;
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
end.parse!
|
18
|
+
|
19
|
+
if @dir
|
20
|
+
puts GenerateVhosts.new(@dir).vhosts
|
21
|
+
else
|
22
|
+
puts GenerateVhosts.new.vhosts
|
23
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'ERB'
|
2
|
+
require 'socket'
|
3
|
+
|
4
|
+
class GenerateVhosts
|
5
|
+
|
6
|
+
attr_accessor :vhosts
|
7
|
+
|
8
|
+
def initialize(code_dir="~/code")
|
9
|
+
@vhosts = ""
|
10
|
+
@hostname = Socket.gethostname.split('.').first
|
11
|
+
@code_dir = code_dir
|
12
|
+
Dir.chdir(File.expand_path(code_dir)) do
|
13
|
+
Dir.glob("*").each do |subdir|
|
14
|
+
@app_dir = subdir
|
15
|
+
@vhosts << generate_vhost if is_web_app
|
16
|
+
end
|
17
|
+
end
|
18
|
+
@vhosts
|
19
|
+
end
|
20
|
+
|
21
|
+
def is_web_app
|
22
|
+
rack? || rails_legacy?
|
23
|
+
end
|
24
|
+
|
25
|
+
def rack?
|
26
|
+
File.exists?("./#{@app_dir}/config.ru") and File.directory?("./#{@app_dir}/public")
|
27
|
+
end
|
28
|
+
|
29
|
+
def rails_legacy?
|
30
|
+
File.exists?("./#{@app_dir}/config/boot.rb") and File.directory?("./#{@app_dir}/public")
|
31
|
+
end
|
32
|
+
|
33
|
+
def generate_vhost
|
34
|
+
template = ERB.new(File.read(File.join(File.dirname(__FILE__), "/template.vhost.erb")))
|
35
|
+
template.result(binding)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<VirtualHost *:80>
|
2
|
+
DocumentRoot "<%= File.expand_path(File.join(@code_dir, @app_dir, "public")) %>"
|
3
|
+
ServerName <%= @app_dir %>
|
4
|
+
ServerAlias <%= @app_dir %>.local <%= @app_dir %>.<%= @hostname %>
|
5
|
+
ErrorLog "/private/var/log/apache2/<%= @app_dir %>-error_log"
|
6
|
+
CustomLog "/private/var/log/apache2/<%= @app_dir %>-access_log" combined
|
7
|
+
<Directory <%= File.expand_path(File.join(@code_dir, @app_dir, "public")) %>>
|
8
|
+
Order allow,deny
|
9
|
+
Allow from all
|
10
|
+
</Directory>
|
11
|
+
</VirtualHost>
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: generate_vhosts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Matt House
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-18 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email: matt@eightbitraptor.com
|
24
|
+
executables:
|
25
|
+
- generate_vhosts
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/generate_vhosts.rb
|
32
|
+
- lib/template.vhost.erb
|
33
|
+
- bin/generate_vhosts
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://eightbitraptor.com
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
hash: 3
|
49
|
+
segments:
|
50
|
+
- 0
|
51
|
+
version: "0"
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.3.7
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Generate vhosts for all rack apps in a given directory
|
68
|
+
test_files: []
|
69
|
+
|