This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 11.4k
/
isc-dhcp.rb
157 lines (138 loc) · 5.13 KB
/
isc-dhcp.rb
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
require 'formula'
class IscDhcp < Formula
homepage 'http://www.isc.org/software/dhcp'
url 'http://ftp.isc.org/isc/dhcp/4.2.4-P1/dhcp-4.2.4-P1.tar.gz'
sha256 'd3baabef27fc006e1ce1c4e3d03d7e5c4b6a34d5a2f45fa47d69235ed25ad420'
version '4.2.4-P1'
def install
# use one dir under var for all runtime state.
dhcpd_dir = var+'dhcpd'
# Change the locations of various files to match Homebrew
# we pass these in through CFLAGS since some cannot be changed
# via configure args.
path_opts = {
'_PATH_DHCPD_CONF' => etc+'dhcpd.conf',
'_PATH_DHCLIENT_CONF' => etc+'dhclient.conf',
'_PATH_DHCPD_DB' => dhcpd_dir+'dhcpd.leases',
'_PATH_DHCPD6_DB' => dhcpd_dir+'dhcpd6.leases',
'_PATH_DHCLIENT_DB' => dhcpd_dir+'dhclient.leases',
'_PATH_DHCLIENT6_DB' => dhcpd_dir+'dhclient6.leases',
'_PATH_DHCPD_PID' => dhcpd_dir+'dhcpd.pid',
'_PATH_DHCPD6_PID' => dhcpd_dir+'dhcpd6.pid',
'_PATH_DHCLIENT_PID' => dhcpd_dir+'dhclient.pid',
'_PATH_DHCLIENT6_PID' => dhcpd_dir+'dhclient6.pid',
'_PATH_DHCRELAY_PID' => dhcpd_dir+'dhcrelay.pid',
'_PATH_DHCRELAY6_PID' => dhcpd_dir+'dhcrelay6.pid',
}
path_opts.each do |symbol,path|
ENV.append 'CFLAGS', "-D#{symbol}='\"#{path}\"'"
end
# See discussion at: https://gist.github.com/1157223
if MacOS.version >= :lion
ENV.append 'CFLAGS', "-D__APPLE_USE_RFC_3542"
end
system './configure', "--disable-dependency-tracking",
"--prefix=#{prefix}",
"--localstatedir=#{dhcpd_dir}"
# the 'bind' subdirectory doesn't like overly parallel builds
# so build it sequentially. deparallelizing the whole build
# can be slow.
previous_makeflags = ENV['MAKEFLAGS']
ENV.deparallelize
system 'make -C bind'
ENV['MAKEFLAGS'] = previous_makeflags
# build everything else
inreplace 'Makefile', 'SUBDIRS = bind', 'SUBDIRS = '
system 'make'
system 'make install'
# rename all the installed sample etc/* files so they don't clobber
# any existing config files at symlink time.
Dir.open(prefix+'etc') do |dir|
dir.each do |f|
file = "#{dir.path}/#{f}"
File.rename(file, "#{file}.sample") if File.stat(file).file?
end
end
# create the state dir and lease files else dhcpd will not start up.
dhcpd_dir.mkpath
%w(dhcpd dhcpd6 dhclient dhclient6).each do |f|
file = "#{dhcpd_dir}/#{f}.leases"
File.new(file, File::CREAT|File::RDONLY).close
end
# sample launchd plists
plist_path.write dhcpd_plist
plist_path.chmod 0644
(prefix+'homebrew.mxcl.dhcpd6.plist').write dhcpd6_plist
(prefix+'homebrew.mxcl.dhcpd6.plist').chmod 0644
end
def caveats
<<-EOCAVEATS.undent
This install of dhcpd expects config files to be in #{etc}.
All state files (leases and pids) are stored in #{var}/dhcpd.
Dhcpd needs to run as root since it listens on privileged ports.
Sample launchd plists to achieve this have been provided at:
#{plist_path}
and:
#{prefix}/homebrew.mxcl.dhcpd6.plist
There are two plists because a single dhcpd process may do either
DHCPv4 or DHCPv6 but not both. Use one or both as needed.
Copy the plists to /Library/LaunchDaemons and start the services with
cd /Library/LaunchDaemons
launchctl load -w #{plist_path.basename}
launchctl load -w homebrew.mxcl.dhcpd6.plist
Note that you must create the appropriate config files before starting
the services or dhcpd will refuse to run.
DHCPv4: #{etc}/dhcpd.conf
DHCPv6: #{etc}/dhcpd6.conf
Sample config files may be found in #{etc}.
If you change the config, restart dhcpd with one or both of
launchctl stop #{plist_name}
launchctl stop homebrew.mxcl.dhcpd6
EOCAVEATS
end
def dhcpd_plist
<<-EOPLIST.undent
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version='1.0'>
<dict>
<key>Label</key><string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{HOMEBREW_PREFIX}/sbin/dhcpd</string>
<string>-f</string>
</array>
<key>Disabled</key><false/>
<key>KeepAlive</key><true/>
<key>RunAtLoad</key><true/>
<key>LowPriorityIO</key><true/>
</dict>
</plist>
EOPLIST
end
def dhcpd6_plist
<<-EOPLIST.undent
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version='1.0'>
<dict>
<key>Label</key><string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{HOMEBREW_PREFIX}/sbin/dhcpd</string>
<string>-f</string>
<string>-6</string>
<string>-cf</string>
<string>#{etc}/dhcpd6.conf</string>
</array>
<key>Disabled</key><false/>
<key>KeepAlive</key><true/>
<key>RunAtLoad</key><true/>
<key>LowPriorityIO</key><true/>
</dict>
</plist>
EOPLIST
end
end