blob: eaf409a7678d894dc81b8650762fec92906030cc (
plain)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
#!/bin/bash
#for einfo, ewarn etc..
. /sbin/functions.sh
setup() {
echo
echo
einfo "Dnscache Setup"
echo
echo
echo ">>> More information on this package can be found at"
echo ">>> http://cr.yp.to/djbdns.html and http://djbdns.org"
echo
echo "After this script completes, dnscache will be configured."
echo "Your /etc/resolv.conf will be updated so that all DNS"
echo "lookups will be directed to dnscache."
echo
echo "Your original /etc/resolv.conf will be backed up to "
echo "/etc/resolv.conf.orig."
echo
echo "If you have previously setup dnscache, those directories will"
echo "not be overwritten. To redo setup, delete your dnscache"
echo "dirs first or choose a different install location."
echo
echo '(press enter to begin setup, or press control-C to abort)'
echo
read
echo
einfo "Install location"
echo
echo "Where do you want dnscache installed?"
echo "Ex. Default (/var) will install dnscache in /var/dnscache,"
echo "or an external cache in /var/dnscachex."
echo "!!No trailing slash!!"
echo
read -p "[/var]> " mypath
echo
if [ "$mypath" == "" ]
then
mypath="/var"
fi
if [ ! -e ${mypath} ]
then
echo ">>> Creating ${mypath}..."
mkdir $mypath
fi
echo
echo
einfo "Internal or external cache?"
echo
echo "Specify an address to which dnscache should bind."
echo "If this is the only machine accessing dnscache,"
echo "127.0.0.1 is a good start."
echo "Currently running IP addresses:"
echo
# grab interfaces
addrs=`ifconfig -a | grep "inet addr" | cut -f2 -d":" | cut -f1 -d" "`
echo $addrs
echo
read -p "IP to bind cache to [127.0.0.1]> " myip
echo
if [ "$myip" == "" ]
then
myip="127.0.0.1"
mycachedir="dnscache"
else
mycachedir="dnscachex"
fi
# check for existance of users dnscache and dnslog:
echo
echo
einfo "Checking for dnscache and dnslog user accts ..."
echo
/usr/bin/grep nofiles /etc/group &> /dev/null
if [ $? -ne 0 ]
then
echo ">>> Adding group nofiles ..."
/usr/sbin/groupadd nofiles &> /dev/null
fi
/usr/bin/grep dnscache /etc/passwd &> /dev/null
if [ $? -ne 0 ]
then
echo ">>> Adding user dnscache ..."
/usr/sbin/useradd -d /dev/null -s /bin/false -g nofiles \
dnscache &> /dev/null
fi
/usr/bin/grep dnslog /etc/passwd &> /dev/null
if [ $? -ne 0 ]
then
echo ">>> Adding user dnslog ..."
/usr/sbin/useradd -d /dev/null -s /bin/false -g nofiles \
dnslog &> /dev/null
fi
if [ ! -e ${mypath}/${mycachedir} ]
then
/usr/bin/dnscache-conf dnscache dnslog \
${mypath}/${mycachedir} ${myip}
else
ewarn "*** dnscache directory currently exists, nothing done."
fi
echo
echo
einfo "Configure a forward for dnscache?"
echo
echo "dnscache can be configured to forward queries to another"
echo "nameserver (such as the nameserver of your ISP) rather than "
echo "perform the lookups itself. If you would like to enable this "
echo "forwarding mode (a good idea most of the time), then enter the "
echo "IP's of your forwarding nameservers now,"
echo "otherwise just hit Enter."
echo
read -p "enter forward-to IP> " myforward
echo
if [ "$myforward" != "" ]
then
echo $myforward > ${mypath}/${mycachedir}/root/servers/\@
echo -n "1" > ${mypath}/${mycachedir}/env/FORWARDONLY
read -p "enter forward-to IP [hit Enter to stop]> " myforward
while [ "$myforward" != "" ]
do
echo $myforward >> ${mypath}/${mycachedir}/root/servers/\@
read -p "enter forward-to IP [hit Enter to stop]> " myforward
done
echo ">>> Setting up forwarding..."
fi
if [ "$myip" != "127.0.0.1" ]
then
echo
echo
einfo "Configuring clients"
echo
echo "dnscache by default only allows 127.0.0.1 to access it."
echo "You have to specify the IP addresses of the clients"
echo "that shall be allowed to use dnscache."
echo
echo "1.2.3.4 would allow host 1.2.3.4"
echo "1.2.3 would allow all hosts underneath 1.2.3.x"
echo
echo "Just hit Enter if you do not want to specify clients!"
echo
read -p "Enter IP> " myclientip
while [ "$myclientip" != "" ]
do
touch ${mypath}/${mycachedir}/root/ip/${myclientip}
read -p "Enter IP (hit Enter to stop)>" myclientip
done
fi
echo
echo
einfo "Misc"
echo
if [ ! -e /var/log/dnscache ]
then
echo ">>> linking /var/log/${mycachedir} to the $mycachedir log..."
ln -s ${mypath}/${mycachedir}/log/main /var/log/${mycachedir}
fi
if [ -e /etc/resolv.conf ]
then
/usr/bin/grep $myip /etc/resolv.conf &> /dev/null
if [ $? -ne 0 ]
then
echo ">>> Backing up /etc/resolv.conf to resolv.conf.orig..."
cp /etc/resolv.conf /etc/resolv.conf.orig
cat /etc/resolv.conf.orig | grep -v nameserver > /etc/resolv.conf
echo ">>> Removed nameserver entries from resolv.conf..."
echo nameserver $myip >> /etc/resolv.conf
echo
echo ">>> Added \"nameserver ${myip}\" to /etc/resolv.conf!"
else
echo ">>> ${myip} is already in /etc/resolv.conf - nothing done!"
fi
else
echo nameserver $myip >> /etc/resolv.conf
echo
echo ">>> Added \"nameserver ${myip}\" to /etc/resolv.conf!"
fi
#TODO
#configure cachsize - $mypath/env/CACHESIZE
#TODO
#configure datalimit - $mypath/env/DATALIMIT
echo
echo
einfo "Start service"
echo
echo "dnscache is ready for startup."
echo "Do you want dnscache to be started and"
echo "supervised by daemontools now?"
echo
echo "This requires svscan (daemontools) to be running currently and"
echo "monitoring /service !!"
echo
echo '(press control-C to abort)'
read
# check in /mnt/.init.d to find svscan link in running...
# if not running execute /etc/init.d/svscan start
# Don't make symbolic links to / !
# use ../ instead as it gives trouble in chrooted environments
# By Kalin KOZHUHAROV <kalin@ThinRope.net>
local fixedroot_path=`echo ${mypath} | sed -e 's#^/#../#'`
cd /service
ln -sf ${fixedroot_path}/${mycachedir} .
echo
echo
einfo "Installation successfull"
echo
}
# check for root user
if [ `id -u` -ne 0 ]
then
eerror "${0}: must be root."
exit 1
fi
# run setup
setup
|