forked from github/homebrew-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrew-setup-nginx-conf
More file actions
executable file
·91 lines (75 loc) · 2.27 KB
/
brew-setup-nginx-conf
File metadata and controls
executable file
·91 lines (75 loc) · 2.27 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env ruby
# Generates and installs a project nginx configuration using erb.
require "erb"
require "pathname"
root_configuration = ARGV.delete "--root"
if root_configuration
http_port = 80
https_port = 443
else
http_port = 8080
https_port = 8443
end
name = ARGV.shift
root = ARGV.shift || "."
input = ARGV.shift || "config/dev/nginx.conf.erb"
if !name || !root || !input
abort "Usage: brew generate-nginx-conf [--root] <project_name> <project_root_path> <nginx.conf.erb>"
end
unless input.end_with? ".erb"
abort "Error: #{input} is not a .erb file!"
end
root = File.expand_path root
input = File.expand_path input
data = IO.read input
conf = ERB.new(data).result
output = input.sub(/.erb$/, "")
output.sub!(/.conf$/, ".root.conf") if root_configuration
IO.write output, conf
exit if ENV["BOXEN_HOME"]
exit if root_configuration
/access_log (?<log>.+);/ =~ conf
if log
log = Pathname(log)
log.dirname.mkpath
FileUtils.touch log unless log.exist?
end
exit unless RUBY_PLATFORM.include? "darwin"
strap_url = ENV["STRAP_URL"]
strap_url ||= "https://strap.githubapp.com"
unless File.exist? "/usr/local/bin/brew"
abort <<-EOS
Error: Homebrew is not in /usr/local. Install it by running Strap:
#{strap_url}
EOS
end
brewfile = <<-EOS
brew "launchdns", restart_service: true
brew "nginx", restart_service: true
EOS
started_nginx = false
unless system "echo '#{brewfile}' | brew bundle check --file=- >/dev/null"
puts "Installing *.dev dependencies:"
unless system "echo '#{brewfile}' | brew bundle --file=-"
abort "Error: install *.dev dependencies with brew bundle!"
end
started_nginx = true
end
if `readlink /etc/resolver 2>/dev/null`.chomp != "/usr/local/etc/resolver"
unless system "sudo -n true >/dev/null"
puts "Asking for your password to setup *.dev:"
end
unless system "sudo ln -sf /usr/local/etc/resolver /etc/resolver"
abort "Error: failed to symlink /usr/local/etc/resolver to /etc/resolver!"
end
end
server = "/usr/local/etc/nginx/servers/#{name}"
unless system "ln -sf '#{File.absolute_path(output)}' '#{server}'"
abort "Error: failed to symlink #{output} to #{server}!"
end
system "brew prune >/dev/null"
unless started_nginx
unless system "brew services restart nginx >/dev/null"
abort "Error: failed to (re)start nginx!"
end
end