Viitor_upstart/sbin/if_up
kueller 79b2635d46 Neue Version V963
git-svn-id: svn://svn.compuextreme.de/Viitor/V963/Viitor_upstart@5933 504e572c-2e33-0410-9681-be2bf7408885
2011-01-03 10:48:06 +00:00

126 lines
4.0 KiB
Bash
Executable File

#!/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ügung gestellt
#
#Lage dieser Datei im Archiv: $Source: /Data/cvs/ViitorMake/templates/Script.template,v $
#
#(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:if_up
#
#Letzte Änderung von: $Author: $
#Datum der letzten Änderung: $Date: $
#Version der Datei: $Revision: $
#
#$Log: $
#
source /etc/init.d/functions
DEV=$1
CheckForLink() {
NETDEVICE=$1
if [ -f /usr/sbin/ethtool ]; then
#Einige Dumme Interfaces (z.B. die VMware Emulationen) Zeiten
#den korrekten Status erst nach einem ifconfig up
WAITTIME=7
ZAHLER=0
if ! ethtool $NETDEVICE|grep -q "No data available"; then
while [ ${ZAHLER} -le ${WAITTIME} ]; do
if [ ! `ethtool $NETDEVICE|grep Link|awk '{print $3}'` == "yes" ]; then
(( ZAHLER++ ))
else
break
fi
sleep 1
done
if [ `ethtool $NETDEVICE|grep Link|awk '{print $3}'` == "yes" ]; then
touch /var/run/net_up
return 0
else
return 1
fi
else
touch /var/run/net_up
return 0
fi
else
touch /var/run/net_up
return 0
fi
}
if [ ! "$DEV" ]; then
echo "Usage: $0 <NetworkInterfaceName>"
exit 10
fi
#Check for files in /etc/sysconfig/net
#hostname.<if> will setup static ip for the interfaces, based
#on /etc/hosts (hostname) and /etc/networks (netmask/Broadcast)
#<if>.dhcp will do a dynamic setup for the interface with dhcp
if [ -f /etc/sysconfig/net/${DEV}.dhcp ]; then
#ok this is the dynamic part for setup ${DEV}
#first we have to startup interface to check interface type
ifconfig ${DEV} up
#Let check in /sys if the interface is a wireless interface
if [ -d /sys/class/net/${DEV}/wireless ]; then
#wireless interface need special setup..
/sbin/wlan_setup ${DEV}
#give wlan time to startup and create a link
sleep 1
fi
#let check if there is a link on the interface.
#only if there is a link, we will setup the interface..
if CheckForLink ${DEV}; then
echo -n "Setting up ${DEV} with dhcp"
dhclient -q ${DEV}
evaluate_retval
else
ifconfig ${DEV} down
fi
elif ls /etc/sysconfig/net/hostname.${DEV}* &>/dev/null; then
ifconfig ${DEV} up
if [ -d /sys/class/net/${DEV}/wireless ]; then
/sbin/wlan_setup ${DEV}
#give wlan time to startup and create a link
sleep 1
fi
if CheckForLink ${DEV}; then
for NETDEV in `ls /etc/sysconfig/net/hostname.${DEV}*|awk -F "." '{print $2}'`; do
HOST=`cat /etc/sysconfig/net/hostname.${NETDEV}|awk '{print $1}'`
IP=`grep $HOST /etc/hosts|awk '{print $1}'`
NETMASK=`getmask $IP`
SHMASK=`GetShortMask $NETMASK`
echo -n "setting up interface $NETDEV:IP=$IP NMASK=$NETMASK"
if [ "$NETMASK" = "" ]; then
DEV=`echo $NETDEV|cut -d ":" -f 1`
$DEBUG ip addr add $IP broadcast + dev $DEV
$DEBUG ip link set $DEV up
else
DEV=`echo $NETDEV|cut -d ":" -f 1`
$DEBUG ip addr add $IP/$SHMASK broadcast + dev $DEV
$DEBUG ip link set $DEV up
fi
done
else
ifconfig ${DEV} down
fi
fi