summaryrefslogtreecommitdiff
blob: 376d28fcae5893ec2641eeab858f5d218622f87f (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
#!/bin/bash

#
# source functions.sh for einfo, eerror and ewarn
. /sbin/functions.sh

setup() {
	echo
	echo
	einfo "tinydns Setup"
	echo
	echo ">>> More information on this package can be found at"
	echo ">>> http://cr.yp.to/djbdns/tinydns.html"
	echo
	echo "If you have previously setup tinydns, those directories will"
	echo "not be overwritten.  To redo setup, delete your"
	echo "tinydns dir tree first."
	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 tinydns installed?"
	echo "Ex. /var would install dnscache in /var/tinydns."
	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

	# check for existance of users tinydns and dnslog:
	echo
	echo
	einfo "Checking for tinydns 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 tinydns /etc/passwd &> /dev/null
	if [ $? -ne 0 ]
	then
		echo ">>> Adding user tinydns ..."
		/usr/sbin/useradd -d /dev/null -s /bin/false -g nofiles \
			tinydns &> /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


	# grab interfaces
	addrs=`ifconfig -a | grep "inet addr" | cut -f2 -d":" | cut -f1 -d" "`

	echo "Specify an address to which tinydns should bind."
	echo "NOTICE: tinydns must be able to bind to port 53 on "
	echo "choosen ip address! udp by tinydns - tcp by axfrdns"
	echo "Usually this is NOT 127.0.0.1"
	echo "Currently running IP addresses:"
	echo
	echo $addrs
	echo

	while [ "$myip" = "" ]
	do
		read -p "IP to bind nameserver to>" myip
	done
	echo

	if [ ! -e ${mypath}/tinydns ]
	then
		einfo "Setting up tinydns..."
		/usr/bin/tinydns-conf tinydns dnslog \
			${mypath}/tinydns $myip
	else
		ewarn "*** tinydns directory currently exists, nothing done."
	fi

	#add afxrdns
	if [ ! -e ${mypath}/axfrdns ]
	then
		einfo "Setting up axfrdns..."
		/usr/bin/axfrdns-conf tinydns dnslog \
			${mypath}/axfrdns ${mypath}/tinydns $myip
	else
		ewarn "*** axfrdns directory currently exists, nothing done."
	fi

	#grant access to axfrdns

	echo
	echo
	einfo "Start service"
	echo
	echo "tinydns is ready for startup."
	echo "Do you want dnscache to be started and"
	echo "supervised by daemontools now?"

	echo
	echo "This requires daemontools to supervise"
	echo "/service !!"
	echo
	echo '(press control-C to abort)'
	read

	# 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}/tinydns .
	ln -sf ${fixedroot_path}/axfrdns .

	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