summaryrefslogtreecommitdiffstats
path: root/dns_wizard/scripts/do_it_dns.sh
blob: 84807609aa4740f77a482a1257d17bea1d4a3f22 (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
#!/bin/bash
# 
# Wizard
#
# Copyright (C) 2000 Mandrakesoft.
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# See file LICENSE for further informations on licensing terms.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
# 
# Authors: Jerome Dumonteil, Maurizio De Cecco, Enzo Maggi
# icons: Helene Durosini <ln@mandrakesoft.com>
# <corporate@mandrakesoft.com> http://www.mandrakesoft.com

# script for wizard dns configuration
#
# install default dns configuration for server
# assuming all dependencies are ok

wiz_ip_net=`get_var wiz_ip_net`
wiz_ip_server=`get_var wiz_ip_server`
wiz_domain_name=`get_var wiz_domain_name`
wiz_host_name=`get_var wiz_host_name`
s_trunc=${wiz_ip_net%.*}
ds=${wiz_ip_server##*.}
host=${wiz_host_name%%.*}


# change serial number
# $1 : file
up_serial(){
TMPFILE=`mktemp /tmp/temp.XXXXXX` || exit 1
cat $1 > ${TMPFILE}
serial_nbm=$(date "+%Y%m%d00")
serial_f=`sed -ne "s/^\([[:space:]]*\)\([0-9]*\)\([[:space:]]*;[[:space:]]*Serial.*$\)/\2/p" ${TMPFILE}`
serial_f=$((${serial_f}+1))
if [ ${serial_f} -le ${serial_nbm} ]; then
	serial_f=${serial_nbm}
fi

cat ${TMPFILE}\
|sed -e "s/^\([[:space:]]*\)\([0-9]*\)\([[:space:]]*;[[:space:]]*Serial.*$\)/\1${serial_f}\3/"\
> $1
rm -f ${TMPFILE}
}







# host.conf
bck_file /etc/host.conf
cat ${CWD}/scripts/host.conf.default > /etc/host.conf

# named.conf
file=/etc/named.conf
bck_file ${file}

echo_debug "now putting ${file} configuration"

reversenet=`echo ${wiz_ip_net}|sed -e 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.[0-9]*$/\3\.\2\.\1/'`
echo_debug "reversenet : ${reversenet}"

cat ${CWD}/scripts/named.conf.default > /var/tmp/named.conf.default

if [ -z "${wiz_ext_dns1}" ]; then
	TMPFILE=`mktemp /tmp/temp.XXXXXX` || exit 1
	cat /var/tmp/named.conf.default > ${TMPFILE}
	cat ${TMPFILE}|sed -e "s/^.*__ISPNS1__.*$/\/\/&/" >/var/tmp/named.conf.default
	rm -f ${TMPFILE}
fi
if [ -z "${wiz_ext_dns2}" ]; then
	TMPFILE=`mktemp /tmp/temp.XXXXXX` || exit 1
	cat /var/tmp/named.conf.default > ${TMPFILE}
	cat ${TMPFILE}|sed -e "s/^.*__ISPNS2__.*$/\/\/&/" >/var/tmp/named.conf.default
	rm -f ${TMPFILE}
fi

cat /var/tmp/named.conf.default \
|sed "s|__ISPNS1__|${wiz_ext_dns1}|g" \
|sed "s|__ISPNS2__|${wiz_ext_dns2}|g" \
|sed "s|__dname__|${wiz_domain_name}|g" \
|sed "s|__revnet__|${reversenet}|g" \
|sed "s|__net__|${s_trunc}|g" \
> ${file}

# Bug fix for bind 9:
touch /etc/rndc.key

# root.hints
file=/var/named/root.hints
bck_file ${file}

cat ${CWD}/scripts/root.hints.default > ${file}

# 127.0.0.rev
file=/var/named/127.0.0.rev
bck_file ${file}

cat ${CWD}/scripts/127.0.0.rev.default \
|sed "s|__hname__|${wiz_host_name}|g" \
> ${file}

up_serial ${file}

# ipnet.rev

file=/var/named/${s_trunc}.rev
echo_debug "config about ${file}"
bck_file ${file}

cat ${CWD}/scripts/ipnet.rev.default > /var/tmp/ipnet.rev.default

cat /var/tmp/ipnet.rev.default \
|sed "s|__dname__|${wiz_domain_name}|g" \
|sed "s|__hname__|${wiz_host_name}|g" \
|sed "s|__revnet__|${reversenet}|g" \
|sed "s|__nb__|${ds}|g" \
> ${file}

up_serial ${file}

# domain.db
file=/var/named/${wiz_domain_name}.db
bck_file ${file}
echo_debug "config ${file}"

cat ${CWD}/scripts/domain.db.default > /var/tmp/domain.db.default

cat /var/tmp/domain.db.default \
|sed "s|__dname__|${wiz_domain_name}|g" \
|sed "s|__hname__|${wiz_host_name}|g" \
|sed "s|__ip__|${wiz_ip_server}|g" \
|sed "s|__host__|${host}|g" \
> ${file}

up_serial ${file}

# resolv.conf
file=/etc/resolv.conf
bck_file ${file}
echo_debug "config ${file}"

echo -e "\
domain ${wiz_domain_name}\n\
nameserver ${wiz_ip_server}\n\
" > ${file}




# restarting bind
/sbin/chkconfig --level 235 named on
/etc/rc.d/init.d/named restart


file=/etc/sysconfig/mdk_serv
wiz_caching_dns="1"
chg_val ${file} wiz_caching_dns ${wiz_caching_dns} s
# all is ok
exit 10