-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvhost.thor
More file actions
76 lines (66 loc) · 1.93 KB
/
vhost.thor
File metadata and controls
76 lines (66 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class Vhost < Thor
include Thor::Actions
# TODO: Add a -p / --passenger flag
desc "new URL [PATH]", "Create new vhost entry"
def new(url="?", path=".")
fullpath = File.expand_path path
url = if url == '?'
ask "Local url to use:"
else
url
end
unless url.empty?
puts "Creating #{url} at #{fullpath}"
puts " - Updating /etc/hosts"
entry = "\n127.0.0.1 #{url}\n"
#run "(echo '#{entry}' >> /etc/hosts)", :with=>'sudo'
File.open '/etc/hosts', 'a' do |hosts|
hosts << entry
end rescue begin
puts "You don't have permission to update /etc/hosts... Try using sudo:"
puts " sudo -E thor vhost:new #{url} #{path}"
puts "Done."
exit 1
end
puts " - Updating /etc/apache2/extra/httpd-vhosts.conf"
entry = """
# Created on #{Time.now}
<VirtualHost *:80>
ServerAdmin darthapo@gmail.com
DocumentRoot #{fullpath}
ServerName #{url}
ErrorLog /private/var/log/apache2/#{url}-error_log
CustomLog /private/var/log/apache2/#{url}-access_log common
RackEnv development
<Directory #{fullpath}>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
"""
File.open '/etc/apache2/extra/httpd-vhosts.conf', 'a' do |hosts|
hosts << entry
end
puts " - Restarting apache"
run 'apachectl restart'
puts "\nDone."
else
puts "Canceled"
end
end
desc "list", "List all vhost entries"
def list
# puts run('cat /etc/hosts')
lines = run('cat /etc/hosts', :capture=>true, :verbose=>false).to_s.split "\n"
lines.each do |line|
line.strip!
unless line == '' or line[0] == '#' or line.include?('adobe.com')
puts line
end
end
end
desc "edit", "Edit hosts and apache vhosts files in Textmate"
def edit
run "mate /etc/hosts /etc/apache2/extra/httpd-vhosts.conf"
end
end