summaryrefslogtreecommitdiffstats
path: root/server_wizard/scripts/do_it_net.sh
blob: 839dda54284c2e4f063555345bf270cd56973d03 (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
#!/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 for network
# change files : 
#  /etc/sysconfig/network
#  /etc/sysconfig/network-cripts/ifcfg-ethx
#  /etc/hosts
#  /etc/HOSTNAME
#

echo_debug "$(date) begin $0"

if [ ! -f /etc/sysconfig/network ]; then
	[ -d /etc/sysconfig ] || exit 1
	echo_debug "warning, no network file"
	echo "# warning, this file was not create during install $(date)"\
	> /etc/sysconfig/network
fi

bck_file /etc/sysconfig/network

# first loading values
. /etc/sysconfig/network

# default value for netmask
export wiz_ip_netmask=255.255.255.0

# configuring /etc/sysconfig/network

if [ "${FORWARD_IPV4}" = "false" ]; then
  echo_debug "putting FORWARD_IPV4 to \"yes\""
  chg_val /etc/sysconfig/network FORWARD_IPV4 yes
fi

if [ "${HOSTNAME}" != "${wiz_host_name}" ]; then
  echo_debug "changing hostname from ${HOSTNAME} to ${wiz_host_name}"
  chg_val /etc/sysconfig/network HOSTNAME ${wiz_host_name}  
fi

if [ "${DOMAINNAME}" != "${wiz_domain_name}" ]; then
  echo_debug "changing domain name from ${DOMAINNAME} to ${wiz_domain_name}"
  chg_val /etc/sysconfig/network DOMAINNAME ${wiz_domain_name}
fi

if [ "${NETWORKING}" != "yes" ]; then 
    echo_debug "WARNING, NETWORKING was ${NETWORKING}"
    chg_val /etc/sysconfig/network NETWORKING yes
fi

if [ "${GATEWAYDEV}" != "${wiz_extn_device}" ]; then
  echo_debug "changing GATEWAYDEV name from ${GATEWAYDEV} to ${wiz_extn_device}"
  chg_val /etc/sysconfig/network GATEWAYDEV ${wiz_extn_device}
fi

if [ "${GATEWAY}" != "${wiz_extn_gateway}" ]; then
  echo_debug "changing GATEWAY name from ${GATEWAY} to ${wiz_extn_gateway}"
  chg_val /etc/sysconfig/network GATEWAY ${wiz_extn_gateway}
fi


# now reloading
echo_debug "reloading net params"
. /etc/sysconfig/network

# configuring /etc/sysconfig/network-scripts/.
file="/etc/sysconfig/network-scripts/ifcfg-${wiz_device}"

if [ -f ${file} ]; then
    echo_debug "WARNING ${file} already exists, saved."
    bck_file ${file}
    oldip=`get_val ${file} IPADDR`
else
    oldip=""
    touch ${file}
fi


echo_debug "starting chg_val sequence"

chg_val ${file} DEVICE "${wiz_device}"
chg_val ${file} BOOTPROTO none
chg_val ${file} IPADDR "${wiz_ip_server}"
# by default, just accept ../24 network :
chg_val ${file} NETMASK "${wiz_ip_netmask}"
chg_val ${file} NETWORK "${wiz_ip_net}"
chg_val ${file} BROADCAST "${wiz_ip_net%.*}.255"
chg_val ${file} ONBOOT yes
chg_val ${file} IPXNETNUM_802_2 ""
chg_val ${file} IPXPRIMARY_802_2 no
chg_val ${file} IPXACTIVE_802_2 no
chg_val ${file} IPXNETNUM_802_3 ""
chg_val ${file} IPXPRIMARY_802_3 no
chg_val ${file} IPXACTIVE_802_3 no
chg_val ${file} IPXNETNUM_ETHERII ""
chg_val ${file} IPXPRIMARY_ETHERII no
chg_val ${file} IPXACTIVE_ETHERII no
chg_val ${file} IPXNETNUM_SNAP ""
chg_val ${file} IPXPRIMARY_SNAP no
chg_val ${file} IPXACTIVE_SNAP no

echo_debug "chg_val sequence ended"

#loading new values
. ${file}


# now setup of /etc/hosts
#
# <warning> all this assumes that ip address of server is hard coded
# in /etc/hosts, which may be wrong in some situations
#



# first, storing new hostname (/etc/sysconfig/network has been reloaded)
bck_file /etc/HOSTNAME
echo ${HOSTNAME} > /etc/HOSTNAME
hostname ${HOSTNAME}
echo_debug "done hostname"

hostalias=`echo ${HOSTNAME} |sed -e 's|^\([^.]*\)\..*$|\1|'`

# replacing . by \. for use in sed command
chgipaddr=`echo ${IPADDR} |sed -e 's/\./\\./g'`

TMPFILE=`mktemp /tmp/temp.XXXXXX` || exit 1
TMPFIL2=`mktemp /tmp/temp.XXXXXX` || exit 1
cat /etc/hosts > ${TMPFILE}
bck_file /etc/hosts
#cp -f /etc/hosts /var/tmp/wiz_bck/orig/

cat ${TMPFILE}|sed -e '/^[[:space:]]*'"${chgipaddr}"'[[:space:]]\{1,\}.*$/{
i \
# removed by mdk_serv script on '"$(date)"'
s//#&/
a \
'"${IPADDR}     ${HOSTNAME}   ${hostalias}"'
}
' > ${TMPFIL2}

if [ -z "`grep -E "^[[:space:]]*${chipaddr}[[:space:]]+" ${TMPFIL2}`" ]; then
    echo "${IPADDR}      ${HOSTNAME}   ${hostalias}" >> ${TMPFIL2}
fi



if [ -n "${oldip}" -a "${oldip}" != "${IPADDR}" ]; then
    chgoldip=`echo ${oldip} |sed -e 's/\./\\./g'`
    cat ${TMPFIL2}|sed -e '/^[[:space:]]*'"${chgoldip}"'[[:space:]]\{1,\}.*$/{
i \
# removed by mdk_serv script on '"$(date)"'
s//#&/
}
' > /etc/hosts
else
   cat ${TMPFIL2} > /etc/hosts
fi

rm -f ${TMPFIL2}
rm -f ${TMPFILE}

echo_debug "done /etc/hosts"



#
# </warning> see above
#

# storing network values in /etc/sysconfig/mdk_serv
echo_debug "storing network values"
${CWD}/scripts/do_it_last.sh

# restarting network
echo_debug "restarting network"
/etc/rc.d/init.d/network stop
/etc/rc.d/init.d/network start
echo_debug "done restarting network"

# all is ok
exit 10