summaryrefslogtreecommitdiffstats
path: root/dhcp_wizard/scripts/do_it_dhcp.sh
blob: 5141b8c0dba29154d1d26372e0bd7d9ca4ceba00 (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
#!/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 network configuration
#
# install default dhcpd configuration for dhcp server
# assuming all dependencies are ok

echo_debug "in $0"

cfg_file=/etc/sysconfig/mdk_serv
# loading  var
wiz_device=`get_var wiz_device`
echo_debug "wiz_device=$wiz_device"
wiz_host_name=`get_var wiz_host_name`
echo_debug "wiz_host_name=$wiz_host_name"
wiz_ip_net=`get_var wiz_ip_net`
echo_debug "wiz_ip_net=$wiz_ip_net"
wiz_ip_netmask=`get_var wiz_ip_netmask`
echo_debug "wiz_ip_netmask=$wiz_ip_netmask"
wiz_domain_name=`get_var wiz_domain_name`
echo_debug "wiz_domain_name=$wiz_domain_name"
wiz_ip_server=`get_var wiz_ip_server`
echo_debug "=wiz_ip_server=$wiz_ip_server"

echo_debug "wiz_ip_range1 is $wiz_ip_range1"
echo_debug "wiz_ip_range2 is $wiz_ip_range2"
chg_val ${cfg_file} wiz_ip_range1 "${wiz_ip_range1}" s
chg_val ${cfg_file} wiz_ip_range2 "${wiz_ip_range2}" s

# patch to rewrite when got new file about dhcp with INTERFACES value
# currently, I put the device to configure as dhcp server
# in /etc/sysconfig/dhcpd

# ok, the new init.d/dhcp is not as wanted, still need a patch

#[ -f /etc/sysconfig/dhcpd ] && cp -f /etc/sysconfig/dhcpd /var/tmp/wiz_bck/orig/dhcpd
bck_file /etc/sysconfig/dhcpd
echo "INTERFACES=${wiz_device}" > /etc/sysconfig/dhcpd

# ok, the new init.d/dhcp is not as wanted, still need a patch
# now patching /etc/rc.d/init.d/dhcpd if needed

if [ -z "`grep INTERFACES /etc/rc.d/init.d/dhcpd`" ]; then
	echo_debug "now patching etc/rc.d/init.d/dhcpd"
	bck_file /etc/rc.d/init.d/dhcpd
	cat /etc/rc.d/init.d/dhcpd.mdk_orig.1 \
|sed -e '/daemon \/usr\/sbin\/dhcpd/{
i \
        if [ -f /etc/sysconfig/dhcpd ]; then\
          . /etc/sysconfig/dhcpd\
          DEV=$INTERFACES\
        fi
        }' > /etc/rc.d/init.d/dhcpd
	
#old version	patch /etc/rc.d/init.d/dhcpd < ${CWD}/scripts/dhcpd.patch

fi


# dhcpd.conf

bck_file /etc/dhcpd.conf

echo_debug "now putting dhcpd config file"

cat ${CWD}/scripts/dhcpd.conf.default \
|sed "s|__hname__|${wiz_host_name}|g" \
|sed "s|__net__|${wiz_ip_net}|g" \
|sed "s|__ip__|${wiz_ip_server}|g" \
|sed "s|__mask__|${wiz_ip_netmask}|g" \
|sed "s|__rng1__|${wiz_ip_range1}|g" \
|sed "s|__rng2__|${wiz_ip_range2}|g" \
|sed "s|__dname__|${wiz_domain_name}|g" \
> /etc/dhcpd.conf

touch /var/dhcpd/dhcpd.leases


# modifying webmin config

echo_debug "modifying webmin config"

file="/etc/webmin/dhcpd/config"
if [ -f ${file} ]; then
	chg_val ${file} lease_file "/var/dhcpd/dhcpd.leases"
	chg_val ${file} interfaces "${wiz_device}"
fi


# this part of script to be played at the very end

echo_debug "restarting services"

/etc/rc.d/init.d/dhcpd restart


# all is ok
exit 10