]> gitweb.michael.orlitzky.com - mjo-overlay.git/blob - djbdns/files/dnscache-setup
skel.ebuild: use EAPI=8.
[mjo-overlay.git] / djbdns / files / dnscache-setup
1 #!/bin/bash
2
3 #for einfo, ewarn etc..
4 . /etc/init.d/functions.sh
5
6 setup() {
7 echo
8 echo
9 einfo "Dnscache Setup"
10 echo
11 echo
12 echo ">>> More information on this package can be found at"
13 echo ">>> http://cr.yp.to/djbdns.html and http://djbdns.org"
14 echo
15 echo "After this script completes, dnscache will be configured."
16 echo "Your /etc/resolv.conf will be updated so that all DNS"
17 echo "lookups will be directed to dnscache."
18 echo
19 echo "Your original /etc/resolv.conf will be backed up to "
20 echo "/etc/resolv.conf.orig."
21 echo
22 echo "If you have previously setup dnscache, those directories will"
23 echo "not be overwritten. To redo setup, delete your dnscache"
24 echo "dirs first or choose a different install location."
25 echo
26 echo '(press enter to begin setup, or press control-C to abort)'
27 echo
28 read
29
30 echo
31 einfo "Install location"
32 echo
33 echo "Where do you want dnscache installed?"
34 echo "Ex. Default (/var) will install dnscache in /var/dnscache,"
35 echo "or an external cache in /var/dnscachex."
36 echo "!!No trailing slash!!"
37 echo
38 read -p "[/var]> " mypath
39 echo
40
41 if [ "$mypath" == "" ]
42 then
43 mypath="/var"
44 fi
45
46 if [ ! -e ${mypath} ]
47 then
48 echo ">>> Creating ${mypath}..."
49 mkdir $mypath
50 fi
51
52 echo
53 echo
54 einfo "Internal or external cache?"
55 echo
56 echo "Specify an address to which dnscache should bind."
57 echo "If this is the only machine accessing dnscache,"
58 echo "127.0.0.1 is a good start."
59 echo "Currently running IP addresses:"
60 echo
61
62 # grab interfaces
63 addrs=`ifconfig -a | grep "inet addr" | cut -f2 -d":" | cut -f1 -d" "`
64
65 echo $addrs
66 echo
67 read -p "IP to bind cache to [127.0.0.1]> " myip
68 echo
69
70 if [ "$myip" == "" ]
71 then
72 myip="127.0.0.1"
73 mycachedir="dnscache"
74 else
75 mycachedir="dnscachex"
76 fi
77
78 # check for existance of users dnscache and dnslog:
79 echo
80 echo
81 einfo "Checking for dnscache and dnslog user accts ..."
82 echo
83 /usr/bin/grep nofiles /etc/group &> /dev/null
84 if [ $? -ne 0 ]
85 then
86 echo ">>> Adding group nofiles ..."
87 /usr/sbin/groupadd nofiles &> /dev/null
88 fi
89
90 /usr/bin/grep dnscache /etc/passwd &> /dev/null
91 if [ $? -ne 0 ]
92 then
93 echo ">>> Adding user dnscache ..."
94 /usr/sbin/useradd -d /dev/null -s /bin/false -g nofiles \
95 dnscache &> /dev/null
96 fi
97
98 /usr/bin/grep dnslog /etc/passwd &> /dev/null
99 if [ $? -ne 0 ]
100 then
101 echo ">>> Adding user dnslog ..."
102 /usr/sbin/useradd -d /dev/null -s /bin/false -g nofiles \
103 dnslog &> /dev/null
104 fi
105
106 if [ ! -e ${mypath}/${mycachedir} ]
107 then
108 /usr/bin/dnscache-conf dnscache dnslog \
109 ${mypath}/${mycachedir} ${myip}
110 else
111 ewarn "*** dnscache directory currently exists, nothing done."
112 fi
113
114 echo
115 echo
116 einfo "Configure a forward for dnscache?"
117 echo
118 echo "dnscache can be configured to forward queries to another"
119 echo "nameserver (such as the nameserver of your ISP) rather than "
120 echo "perform the lookups itself. If you would like to enable this "
121 echo "forwarding mode (a good idea most of the time), then enter the "
122 echo "IP's of your forwarding nameservers now,"
123 echo "otherwise just hit Enter."
124 echo
125 read -p "enter forward-to IP> " myforward
126 echo
127 if [ "$myforward" != "" ]
128 then
129 echo $myforward > ${mypath}/${mycachedir}/root/servers/\@
130 echo -n "1" > ${mypath}/${mycachedir}/env/FORWARDONLY
131
132 read -p "enter forward-to IP [hit Enter to stop]> " myforward
133 while [ "$myforward" != "" ]
134 do
135 echo $myforward >> ${mypath}/${mycachedir}/root/servers/\@
136 read -p "enter forward-to IP [hit Enter to stop]> " myforward
137 done
138 echo ">>> Setting up forwarding..."
139 fi
140
141 if [ "$myip" != "127.0.0.1" ]
142 then
143 echo
144 echo
145 einfo "Configuring clients"
146 echo
147 echo "dnscache by default only allows 127.0.0.1 to access it."
148 echo "You have to specify the IP addresses of the clients"
149 echo "that shall be allowed to use dnscache."
150 echo
151 echo "1.2.3.4 would allow host 1.2.3.4"
152 echo "1.2.3 would allow all hosts underneath 1.2.3.x"
153 echo
154 echo "Just hit Enter if you do not want to specify clients!"
155 echo
156
157 read -p "Enter IP> " myclientip
158
159 while [ "$myclientip" != "" ]
160 do
161 touch ${mypath}/${mycachedir}/root/ip/${myclientip}
162 read -p "Enter IP (hit Enter to stop)>" myclientip
163 done
164 fi
165
166 echo
167 echo
168 einfo "Misc"
169 echo
170 if [ ! -e /var/log/dnscache ]
171 then
172 echo ">>> linking /var/log/${mycachedir} to the $mycachedir log..."
173 ln -s ${mypath}/${mycachedir}/log/main /var/log/${mycachedir}
174 fi
175
176 if [ -e /etc/resolv.conf ]
177 then
178 /usr/bin/grep $myip /etc/resolv.conf &> /dev/null
179 if [ $? -ne 0 ]
180 then
181 echo ">>> Backing up /etc/resolv.conf to resolv.conf.orig..."
182 cp /etc/resolv.conf /etc/resolv.conf.orig
183 cat /etc/resolv.conf.orig | grep -v nameserver > /etc/resolv.conf
184 echo ">>> Removed nameserver entries from resolv.conf..."
185 echo nameserver $myip >> /etc/resolv.conf
186 echo
187 echo ">>> Added \"nameserver ${myip}\" to /etc/resolv.conf!"
188 else
189 echo ">>> ${myip} is already in /etc/resolv.conf - nothing done!"
190 fi
191 else
192 echo nameserver $myip >> /etc/resolv.conf
193 echo
194 echo ">>> Added \"nameserver ${myip}\" to /etc/resolv.conf!"
195 fi
196
197 #TODO
198 #configure cachsize - $mypath/env/CACHESIZE
199
200 #TODO
201 #configure datalimit - $mypath/env/DATALIMIT
202
203 echo
204 echo
205 einfo "Start service"
206 echo
207 echo "dnscache is ready for startup."
208 echo "Do you want dnscache to be started and"
209 echo "supervised by daemontools now?"
210
211 echo
212 echo "This requires svscan (daemontools) to be running currently and"
213 echo "monitoring /service !!"
214 echo
215 echo '(press control-C to abort)'
216 read
217
218 # check in /mnt/.init.d to find svscan link in running...
219 # if not running execute /etc/init.d/svscan start
220 # Don't make symbolic links to / !
221 # use ../ instead as it gives trouble in chrooted environments
222 # By Kalin KOZHUHAROV <kalin@ThinRope.net>
223 local fixedroot_path=`echo ${mypath} | sed -e 's#^/#../#'`
224 cd /service
225 ln -sf ${fixedroot_path}/${mycachedir} .
226
227 echo
228 echo
229 einfo "Installation successfull"
230 echo
231 }
232
233 # check for root user
234
235 if [ `id -u` -ne 0 ]
236 then
237 eerror "${0}: must be root."
238 exit 1
239 fi
240
241
242 # run setup
243 setup