]>
gitweb.michael.orlitzky.com - mjo-overlay.git/blob - djbdns/files/djbdns-setup
5 # Copyright (C) 2004-2006 Kalin KOZHUHAROV <kalin@thinrope.net>
6 # The latest version of this script can be accessed at:
7 # rsync://rsync.tar.bz/gentoo-portage-pkalin/net-dns/djbdns/files/djbdns-setup
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 # http://www.gnu.org/copyleft/gpl.html
21 # {{{ Rip off the ewarn code from /sbin/functions.sh
25 echo -e " ${WARN}*${NORMAL} $*"
31 S_SEPARATOR
="--------------------------------------------------------------------------------"
32 D_SEPARATOR
="================================================================================"
35 REQ_USERS
="tinydns dnscache dnslog"
49 echo ": Checking for required group (${REQ_GROUP}) :"
50 grep ${REQ_GROUP} /etc
/group
&> /dev
/null
53 ebegin
"Adding group ${REQ_GROUP}"
54 /usr
/sbin
/groupadd
${REQ_GROUP} &>/dev
/null
&& eend
0 || eend
1
57 echo ": Checking for required users (${REQ_USERS}) :"
58 for user
in ${REQ_USERS};
60 grep ${user} /etc
/passwd
&> /dev
/null
63 ebegin
"Adding user ${user}"
64 /usr
/sbin
/useradd
-d /dev
/null
-s /bin
/false
-g ${REQ_GROUP} ${user} &>/dev
/null
&& eend
0 || eend
1
75 echo ": Start services :"
77 echo " Your services (${services// /, }) are ready for startup!"
79 ewarn
" The following requires daemontools to be running!"
81 read -p " Would you like ${services// /, } to be started and supervised by daemontools now? [Y|n]> " answer
82 if [ "${answer}" == "Y" ] || [ "${answer}" == "" ]
85 ebegin
"Checking if daemontools are running"
86 ps
-A |grep svscanboot
&>/dev
/null
&& eend
0 || eend
1
88 ebegin
"Linking services in /service"
89 # Don't make symbolic links to / !
90 # use ../ instead as it gives trouble in chrooted environments
91 local fixedroot_path
=`echo ${mypath} | sed -e 's#^/#../#'`
92 for service
in ${services};
94 for ip
in ${IPs[${service}]};
96 ln -sf ${fixedroot_path}/${service}/${ip} /service
/${service}_
${ip}
103 ls -l --color=auto
/service
/
105 ebegin
"Waiting 5 seconds for services to start"
109 echo ": Check services status :"
111 for service
in ${services};
113 for ip
in ${IPs[${service}]};
115 svstat
/service
/${service}_
${ip} /service
/${service}_
${ip}/log
129 echo "${S_SEPARATOR}"
130 echo ": Grant access to axfrdns :"
132 TCPRULES_DIR
="${mypath}/axfrdns/${myip}/control"
133 echo " axfrdns is accessed by your secondary servers and when response cannot fit UDP packet"
134 echo " You have to specify which IP addresses are allowed to access it"
135 echo " in ${TCPRULES_DIR}/tcp.axfrdns"
138 echo " 1.2.3.4 would allow the host 1.2.3.4"
139 echo " 1.2.3. would allow ALL hosts 1.2.3.x (like 1.2.3.4, 1.2.3.100, etc.)"
140 ewarn
"Do NOT forget the trailing dot!"
142 echo " Press Enter if you do not want to allow any access now."
145 sed -i -e "s#-x tcp.cdb#-x control/tcp.axfrdns.cdb#g" ${mypath}/axfrdns
/${myip}/run
146 if [ -e ${TCPRULES_DIR}/tcp.axfrdns
]
148 ewarn
"${TCPRULES_DIR}/tcp.axfrdns exists."
149 read -p " Do you want it cleared? [y|N]: " answer
150 if [ "${answer}" == "y" ]
152 echo '# sample line: 1.2.3.4:allow,AXFR="heaven.af.mil/3.2.1.in-addr.arpa"' > ${TCPRULES_DIR}/tcp.axfrdns
156 read -p " IP to allow (press Enter to end)> " ipallow
158 while [ "$ipallow" != "" ]
160 echo "${ipallow}:allow" >> ${TCPRULES_DIR}/tcp.axfrdns
161 read -p " IP to allow (press Enter to end)> " ipallow
163 echo ":deny" >> ${TCPRULES_DIR}/tcp.axfrdns
165 echo " Here are the tcprules created so far:"
167 cat ${TCPRULES_DIR}/tcp.axfrdns
170 read -p " Would you like ${TCPRULES_DIR}/tcp.axfrdns.cdb updated? [Y|n]: " answer
171 if [ "${answer}" == "Y" ] || [ "${answer}" == "" ]
173 ebegin
"Updating ${TCPRULES_DIR}/tcp.axfrdns.cdb"
174 bash
-c "cd ${TCPRULES_DIR} && make" && eend
0 || eend
1
181 echo ": Configure forwarding :"
183 echo " dnscache can be configured to forward queries to another"
184 echo " DNS cache (such as the one your ISP provides) rather than"
185 echo " performing the lookups itself."
187 echo " To enable this forwarding-only mode (usually a good idea),"
188 echo " provide the IPs of the caches to forward to."
189 echo " To have dnscache perform the lookups itself, just press Enter."
191 read -p " forward-to IP> " myforward
193 if [ "$myforward" != "" ]
195 echo $myforward > ${mypath}/dnscache
/${myip}/root
/servers
/\@
196 echo -n "1" > ${mypath}/dnscache
/${myip}/env
/FORWARDONLY
198 read -p " forward-to IP (press Enter to end)> " myforward
199 while [ "$myforward" != "" ]
201 echo $myforward >> ${mypath}/dnscache
/${myip}/root
/servers
/\@
202 read -p " forward-to IP (press Enter to end)> " myforward
206 echo " Currently all queries will be forwarded to:"
208 cat ${mypath}/dnscache
/${myip}/root
/servers
/\@
213 echo ": Configuring clients :"
215 echo " By default dnscache allows only localhost (127.0.0.1) to"
216 echo " access it. You have to specify the IP addresses of the"
217 echo " clients that shall be allowed to use it."
220 echo " 1.2.3.4 would allow only one host: 1.2.3.4"
221 echo " 1.2.3 would allow all hosts 1.2.3.0/24 (e.g. 1.2.3.4, 1.2.3.100, etc.)"
223 echo " Press Enter if you do NOT want to allow external clients!"
226 read -p " Allowed IP> " myclientip
228 while [ "$myclientip" != "" ]
230 touch ${mypath}/dnscache
/${myip}/root
/ip
/${myclientip}
231 read -p " Allowed IP (press Enter to end)> " myclientip
235 echo " All queries from the hosts below will be answered:"
237 ls -1 ${mypath}/dnscache
/${myip}/root
/ip
241 #configure cachsize - $mypath/env/CACHESIZE
244 #configure datalimit - $mypath/env/DATALIMIT
250 local service_human
="$1"
251 local service_machine
="$2"
254 echo ": ${service_human} setup :"
257 for service
in ${services};
259 if [ ! -e ${mypath}/${service} ]
261 ebegin
"Creating ${mypath}/${service}"
262 mkdir -p $mypath/${service} && eend
0 || eend
1
267 echo ": IP address to bind to :"
269 echo " Specify an address to which the ${service_human} should bind."
270 echo " Currently accessible IPs:"
271 local addrs
=`ifconfig -a | grep "inet addr" | cut -f2 -d":" | cut -f1 -d" "`
275 while [ "${myip}" == "" ]
277 read -p " IP to bind to> " myip
281 for service
in ${services};
283 IPs
[${service}]="${IPs[${service}]} ${myip}"
286 local dnscache_INSTALL
="/usr/bin/dnscache-conf dnscache dnslog ${mypath}/dnscache/${myip} $myip"
287 local tinydns_INSTALL
="/usr/bin/tinydns-conf tinydns dnslog ${mypath}/tinydns/${myip} $myip"
288 local axfrdns_INSTALL
="\
289 /usr/bin/axfrdns-conf tinydns dnslog ${mypath}/axfrdns/${myip} ${mypath}/tinydns/${myip} $myip &&\
290 mkdir -p ${mypath}/axfrdns/${myip}/control &&\
291 echo -e \"tcp.axfrdns.cdb:\ttcp.axfrdns\n\ttcprules tcp.axfrdns.cdb .tcp.axfrdns.cdb.tmp < tcp.axfrdns\" > ${mypath}/axfrdns/${myip}/control/Makefile &&\
292 rm -f ${mypath}/axfrdns/${myip}/tcp ${mypath}/axfrdns/${myip}/Makefile"
294 for service
in ${services};
296 if [ ! -e ${mypath}/${service}/${myip} ]
298 ebegin
"Setting up ${service} in ${mypath}/${service}/${myip}"
299 eval command=\$
${service}_INSTALL
300 /bin
/bash
-c "${command}" && eend
0 || eend
1
302 ewarn
"${service} directory ${mypath}/${service}/${myip} exists, nothing done."
314 ewarn
"You must be root to run this script, sorry."
318 echo "${D_SEPARATOR}"
319 echo ": DJB DNS setup :"
321 echo " This script will help you setup the following:"
323 echo " DNS server(s): to publish addresses of Internet hosts"
325 echo " DNS cache(s) : to find addresses of Internet hosts"
327 echo " For further information see:"
328 echo " http://cr.yp.to/djbdns/blurb/overview.html"
330 ewarn
"If you have already setup your services,"
331 ewarn
"either exit now, or setup in different directories."
335 read -p " Would you like to continue with setup? [Y|n]> " answer
336 if [ "${answer}" == "n" ] || [ "${answer}" == "N" ]
338 ewarn
"Aborting setup"
342 echo "${D_SEPARATOR}"
343 echo ": Choose install location :"
346 echo " The default (${default_path}) will install them"
347 echo " in ${default_path}/\${service}/\${IP_ADDRESS}"
350 echo " /var/tinydns /1.2.3.4"
351 echo " /192.168.33.1"
352 echo " /axfrdns /1.2.3.4"
353 echo " /192.168.33.1"
354 echo " /dnscache/127.0.0.1"
356 ewarn
"Do NOT enter trailing slash"
357 echo " Where do you want services installed?"
358 read -p "[${default_path}] > " mypath
361 if [ "${mypath}" == "" ]
363 mypath
=${default_path}
366 echo "${D_SEPARATOR}"
371 until [ "$answer" == "n" ]
373 echo "${D_SEPARATOR}"
375 read -p " Would you like to setup ${another}dnscache? [Y|n]> " answer
376 if [ "${answer}" == "Y" ] || [ "${answer}" == "" ]
379 echo "${S_SEPARATOR}"
380 common_setup
"DNS cache" "dnscache" "dnscache"
385 ewarn
"Skipping dnscache specific setup."
393 until [ "$answer" == "n" ]
395 echo "${D_SEPARATOR}"
397 read -p " Would you like to setup ${another}DNS server? [Y|n]> " answer
398 if [ "${answer}" == "Y" ] || [ "${answer}" == "" ]
401 echo "${S_SEPARATOR}"
402 common_setup
"DNS server" "{tinydns,afxrdns}" "tinydns axfrdns"
408 ewarn
"Skipping tinydns and axfrdns specific setup."
414 echo "${D_SEPARATOR}"
416 start_services
"tinydns axfrdns dnscache"
418 echo "${D_SEPARATOR}"
421 # vim: set ts=4 fenc=utf-8 foldmethod=marker: