ViitorSetup/VSetup_functionNet

244 lines
7.5 KiB
Plaintext
Raw Normal View History

#!/bin/bash
#Framework, welches ein komplettes Linux System aus den Sourcen erstellt
#dieses Framework wird im CVS Repository
#:pserver:cvs.compuextreme.de:/Data/cvs zur Verf<72>gung gestellt
#
#Lage dieser Datei im Archiv: $Source: $
#
#(c) 2003 Harald Kueller, Germany
#This program is free software; you can redistribute it and/or
#modify ist 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.
#
#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.
#
#Script:
#BasisScript ViitorSetup
#Funktionsammlung zur Netzwerk Konfiguration in ViitorLinux
#
#Letzte <20>nderung von: $Author: $
#Datum der letzten <20>nderung: $Date: $
#Version der Datei: $Revision: $
#
#$Log: $
source /etc/init.d/functions
GetNetConfigType() {
DEVICE=$1
TYPE=`$DIALOGPRG --stdout --clear --title "Viitor Setup Programm" \
--radiolist "Select Configuration Type for Device $1" 0 0 3 \
Dynamic dhcp true \
Static Manual false`
if [ "$TYPE" == "Static" ]; then
GetStaticNetConfig $1
else
if [ "$INSTALLROOT" ]; then
touch $INSTALLROOT/etc/sysconfig/net/eth0.dhcp
else
touch /etc/sysconfig/net/eth0.dhcp
fi
fi
}
GetStaticNetConfig() {
DEVICE=$1
AKT_IP=`/sbin/ifconfig $DEVICE|grep inet|awk '{print $2}'|cut -d":" -f 2
`
AKT_MASK=`/sbin/ifconfig $DEVICE|grep inet|awk '{print $4}'|cut -d":" -f 2`
AKT_HOSTNAME=`getent hosts $AKT_IP|awk '{print $2}'`
if [ "$DIALOGPRG" == "dialog" ]; then
IP_INFO=`dialog --stdout --form \
"Insert your Network Information" 10 35 0 \
"IP Adress:" 1 1 "$AKT_IP" 1 12 15 0 \
"Hostname :" 2 1 "$AKT_HOSTNAME" 2 12 15 0 \
"Net Mask :" 3 1 "$AKT_MASK" 3 12 15 0 `
if [ $? == "0" ]; then
IP=`echo $IP_INFO|awk '{ print $1 }'`
HN=`echo $IP_INFO|awk '{ print $2 }'`
NM=`echo $IP_INFO|awk '{ print $3 }'`
else
return 1;
fi
else
IP_INFO=`Xdialog --stdout --title "ViitorLinux Network Setup" \
--3inputsbox "Insert IP and Hostname" 20 0 \
"IP Adress:" "$AKT_IP" \
"Hostname :" "$AKT_HOSTNAME" \
"Net Mask :" "$AKT_MASK"`
if [ $? == "0" ]; then
IP=`echo $IP_INFO|awk -F"/" '{ print $1 }'`
HN=`echo $IP_INFO|awk -F"/" '{ print $2 }'`
GW=`echo $IP_INFO|awk -F"/" '{ print $3 }'`
else
return 1;
fi
NETADDR=`getnetaddr $IP $NM`
if [ "$INSTALLROOT" ]; then
NMFILE=$INSTALLROOT/etc/netmasks
HOSTFILE=$INSTALLROOT/etc/hosts
else
NMFILE=/etc/netmasks
HOSTFILE=/etc/hosts
fi
if [ ! -f /etc/netmasks ]; then
touch $NMFILE
fi
if grep $NETADDR /etc/netmasks; then
sed -e "s/$NETADDR.*$/$NETADDR $NM" $NMFILE >/tmp/netmasks
mv /tmp/netmasks $NMFILE
else
echo "$NETADDR $NM" >>$NMFILE
fi
if grep $HN /etc/hosts; then
sed -e "s/$IP.*$/$IP $HN/" $HOSTFILE >/tmp/hosts
mv /tmp/hosts $HOSTFILE
else
echo "$IP $HN" >>$HOSTFILE
fi
if [ "$INSTALLROOT" ]; then
echo $HN >$INSTALLROOT/etc/sysconfig/net/hostname.$DEVICE
else
echo $HN >/etc/sysconfig/net/hostname.$DEVICE
fi
fi
}
GetNameServiceType() {
TYPE=`$DIALOGPRG --title "Select Nameservice" --clear --stdout \
--radiolist "Which Nameservice should i use?" 0 0 3 \
"DNS " "Use DNS only" off \
"NIS " "Use NIS only" off \
"both" "Use NIS and DNS" on`
}
GetDNSInformation() {
DNS_SEARCH=`grep search /etc/resolv.conf|sed -e "s/search *//"`
DNS_IP=`grep nameserver /etc/resolv.conf|sed -e "s/nameserver *//"`
DNS_DOMAIN=`grep domain /etc/resolv.conf|sed -e "s/domain *//"`
RESOLVFILE=/etc/resolve.conf
if [ $INSTALLROOT ]; then
$RESOLVFILE=$INSTALLROOT/$RESOLVFILE
fi
if [ "$DIALOGPRG" == "dialog" ]; then
DNS_INFO=`dialog --stdout --form \
"Insert your DNS Information" 10 35 0 \
"DNS Server Adress:" 1 1 "$DNS_IP" 1 12 15 0 \
"DNS Domain Name :" 2 1 "$DNS_DOMAIN" 2 12 15 0 \
"DNS Search List :" 3 1 "$DNS_SEARCH" 3 12 15 0`
if [ $? == "0" ]; then
DNS_IP=`echo $DNS_INFO|awk '{print $1}'`
DNS_DOMAIN=`echo $DNS_INFO|awk '{print $2}'`
DNS_SEARCH=`echo $DNS_INFO|awk '{print $3}'`
echo "domain $DNS_DOMAIN" >$RESOLVFILE
echo "search $DNS_SEARCH" >>$RESOLVFILE
echo "nameserver $DNS_IP" >>$RESOLVFILE
fi
else
DNS_INFO=`Xdialog --stdout --title "ViitorLinuxNetwork Setup" \
--3inputsbox "Insert your DNS Information" 20 0 \
"DNS Server Adress:" "$DNS_IP" \
"DNS Domain Name :" "$DNS_DOMAIN" \
"DNS Search List :" "$DNS_SEARCH"`
if [ $? == "0" ]; then
DNS_IP=`echo $DNS_INFO|awk -F "/" '{print $1}'`
DNS_DOMAIN=`echo $DNS_INFO|awk -F "/" '{print $2}'`
DNS_SEARCH=`echo $DNS_INFO|awk -F "/" '{print $3}'`
echo "domain $DNS_DOMAIN" >$RESOLVFILE
echo "search $DNS_SEARCH" >>$RESOLVFILE
echo "nameserver $DNS_IP" >>$RESOLVFILE
fi
fi
if [ $? == "0" ]; then
DNS_IP=`echo $DNS_INFO|awk -F "/" '{print $1}'`
DNS_DOMAIN=`echo $DNS_INFO|awk -F "/" '{print $2}'`
DNS_SEARCH=`echo $DNS_INFO|awk -F "/" '{print $3}'`
echo "domain $DNS_DOMAIN" >$RESOLVFILE
echo "search $DNS_SEARCH" >>$RESOLVFILE
echo "nameserver $DNS_IP" >>$RESOLVFILE
fi
}
GetNISInformation() {
if ypwhich >/dev/null 2>&1; then
NIS_IP=`ypwhich`
NIS_IP=`ping -c 1 $NIS_IP| \
head -n 1| \
awk '{print $3}'| \
sed -e "s/[():]//g"`
fi
NIS_DOMAIN=`domainname`
if [ "$DIALOGPRG" == "dialog" ]; then
NIS_INFO=`dialog --stdout --form \
"Insert your NIS Information" 10 35 0 \
"NIS Server :" 1 1 "$NIS_IP" 1 12 15 0 \
"NIS Domain :" 2 1 "$NIS_DOMAIN" 2 12 15 0`
if [ $? == "0" ]; then
NIS_IP=`echo $NIS_INFO|awk '{print $1}'`
NIS_DOMAIN=`echo $NIS_INFO|awk '{print $2}'`
fi
else
NIS_INFO=`Xdialog --stdout --title "ViitorLinuxNetwork Setup" \
--2inputsbox "Insert your NIS Information" 20 0 \
"NIS Server :" "$NIS_IP" \
"NIS Domain :" "$NIS_DOMAIN"`
if [ $? == "0" ]; then
NIS_IP=`echo $NIS_INFO|awk -F "/" '{print $1}'`
NIS_DOMAIN=`echo $NIS_INFO|awk -F "/" '{print $2}'`
fi
fi
}
GetNetDevices() {
ifconfig -a|sed -e "/^ /d" -e "/^$/d"|awk '{print $1}'
}
GetDeviceIP() {
DEVICE=$1
ifconfig $DEVICE|grep inet|cut -d":" -f 2 |awk '{print $1}'
}
SelectNetDevices() {
NumEntrys=0
unset DIALOGCFG
for i in `GetNetDevices`; do
IP=`GetDeviceIP $i`
DIALOGCFG=$DIALOGCFG" $i $IP false"
(( NumEntrys = $NumEntrys + 1 ))
done
DIALOGCFG=$DIALOGCFG" Select Nameservice false"
DIALOGCFG=$DIALOGCFG" Enter DefaultGateway false"
DIALOGCFG=$DIALOGCFG" Exit Netsetup true"
(( NumEntrys = $NumEntrys + 3 ))
$DIALOGPRG --stdout --clear --title "Viitor Setup Programm" \
--radiolist "Select Network Device" 0 0 $NumEntrys \
$DIALOGCFG
}
GetDefaultGateway() {
DEFROUTFILE=/etc/sysconfig/net/defaultrouter
if [ "$INSTALLROOT" ]; then
DEFROUTFILE=$INSTALLROOT/$DEFROUTFILE
fi
AKT_ROUTER=`/sbin/ip route list|grep default|awk '{print $3}'`
GW=`$DIALOGPRG --stdout --title "ViitorLinux Network Setup" \
--inputbox "Specify your default gateway" 20 0 \
"$AKT_ROUTER"`
if [ ! "$GW" ]; then
if [ -f $DEFROUTFILE ]; then
rm $DEFROUTFILE
fi
else
echo $GW >$DEFROUTFILE
fi
}