summaryrefslogtreecommitdiffstats
path: root/server_wizard/scripts/do_it_net.sh
diff options
context:
space:
mode:
Diffstat (limited to 'server_wizard/scripts/do_it_net.sh')
-rwxr-xr-xserver_wizard/scripts/do_it_net.sh207
1 files changed, 207 insertions, 0 deletions
diff --git a/server_wizard/scripts/do_it_net.sh b/server_wizard/scripts/do_it_net.sh
new file mode 100755
index 00000000..839dda54
--- /dev/null
+++ b/server_wizard/scripts/do_it_net.sh
@@ -0,0 +1,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
+