home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2007 January, February, March & April
/
Chip-Cover-CD-2007-02.iso
/
boot
/
i386
/
root
/
sbin
/
create_interface
< prev
next >
Wrap
Text File
|
2006-11-29
|
7KB
|
215 lines
#!/bin/sh
# Create interface
#
# Olaf Hering <olh@suse.de>
# Michal Svec <msvec@suse.cz>
# Martin Vidner <mvidner@suse.cz>
# Ihno Krumreich <ihno@suse.de>
#
# $Id: create_interface 1833 2006-06-21 09:53:47Z snwint $
ROOT=$1
INSTALLINF=/etc/install.inf
# files copied to $ROOT at the end of script
HARDWAREDIR=/etc/sysconfig/hardware/
DEVICEDIR=$ROOT/etc/sysconfig/network/
ROUTINGFILE=$ROOT/etc/sysconfig/network/routes
HOSTFILE=$ROOT/etc/HOSTNAME
RESFILE=$ROOT/etc/resolv.conf
DOMFILE=$ROOT/etc/defaultdomain
DHCPFILE=$ROOT/etc/sysconfig/network/dhcp
DHCPFILETMP=$ROOT/etc/sysconfig/network/dhcp.tmp
CONFIGFILE=$ROOT/etc/sysconfig/network/config
CONFIGFILETMP=$ROOT/etc/sysconfig/network/config.tmp
MODCONFFILE=$ROOT/etc/modules.conf
MODCONFFILETMP=$ROOT/etc/modules.conf.tmp
# INSTALLINF=install.inf
# DEVICEDIR=
# ROUTINGFILE=routes
#
if [ -f $INSTALLINF ]
then
#
# Get configuration for the installation device
#
NETDEV=`grep Netdevice: $INSTALLINF | grep -v sit0 | uniq | sed -e 's/Netdevice: \\(.*\\)/\\1/'`
eval `getcfg -f hwcfg- -d /etc/sysconfig/hardware $NETDEV`
#
# Create hardware configuration file if it doesn't exist
#
if [ "$HWD_CONFIG_N" -gt 0 ] ; then
# hwcfg file exist, do not modify it
eval HWD_CONFIG=\$HWD_CONFIG_$((HWD_CONFIG_N-1))
myhwcfg=${HWD_CONFIG}
elif [ "$HWD_BUS_N" -gt 0 ] ; then
# use bus info
eval HWD_BUSNAME=\$HWD_BUSNAME_$((HWD_BUS_N-1))
eval HWD_BUSID=\$HWD_BUSID_$((HWD_BUS_N-1))
if test "${HWD_BUSNAME}" = "vio" -a -d /proc/iSeries
then
# Bug 159652 - LTC22358 - no hwcfg-static files created for iseries_veth
myhwcfg=hwcfg-static-0
else
myhwcfg=hwcfg-bus-${HWD_BUSNAME}-${HWD_BUSID}
fi
else
# use static name
myhwcfg=hwcfg-static-0
fi
: hwcfg $myhwcfg
HARDWAREFILE=${HARDWAREDIR}$myhwcfg
if [ ! -f ${HARDWAREFILE} ] ; then
# Here save Aliases and Options for $NETDEV
MODULE=`grep "Alias: $NETDEV" $INSTALLINF | uniq | sed -e "s/Alias: $NETDEV \\(.*\\)/\\1/"`
MODULE_OPTIONS=`grep "Options: $NETDEV" $INSTALLINF | uniq | sed -e "s/Options: $NETDEV \\(.*\\)/\\1/"`
echo "STARTMODE='auto'" > $HARDWAREFILE
echo "MODULE='$MODULE'" >> $HARDWAREFILE
echo "MODULE_OPTIONS='$MODULE_OPTIONS'" >> $HARDWAREFILE
fi
#
# Create interface file
#
# interface config
# always use getcfg names for S/390
if echo "$myhwcfg"|grep -E "(qeth|hsi|ctc|lcs|iucv)"
then
# use getcfg naming
myifcfg=ifcfg-${myhwcfg#static-}
elif [ -z "$HWD_ID" ] ; then
# use kernel name
myifcfg=ifcfg-$NETDEV
else
# use LLA address
myifcfg=ifcfg-${HWD_INTERFACETYPE_0}-id-${HWD_ID}
fi
: ifcfg $myifcfg
DEVICEFILE=/tmp/$myifcfg
TARGET_DEVICEFILE=${DEVICEDIR}$myifcfg
# Choose correct boot protocol (#23708)
BOOTPROTO="dhcp"
if grep -q 'NetConfig:.*static' $INSTALLINF; then
BOOTPROTO="static"
else
sed "s/^DHCLIENT_SET_HOSTNAME=.*/DHCLIENT_SET_HOSTNAME=\"yes\"/" < $DHCPFILE > $DHCPFILETMP
[ $? -eq 0 ] && mv $DHCPFILETMP $DHCPFILE
fi
echo "BOOTPROTO=\"$BOOTPROTO\"" > $DEVICEFILE
# Include UNIQUE number (#25739)
UNIQUE=`grep "^NetUniqueID:" $INSTALLINF | uniq | sed -e 's/NetUniqueID: \\(.*\\)/\\1/'`
echo "UNIQUE=\"$UNIQUE\"" >> $DEVICEFILE
# correct STARTMODE for root fs on a network device, #176804
STARTMODE=onboot
# `sed -n s;T;p` : print only if substitution succeeded
ROOTPART=`sed -n 's,^/dev/\([^[:space:]]*\)[[:space:]]*'${ROOT%/}'[[:space:]].*,\1,;T;p' /proc/mounts`
# translate from persistent names (#176804#c41)
ROOTPART=`readlink -f /dev/$ROOTPART`
ROOTPART=${ROOTPART#/dev/}
# use * and .. to get to the device containing ROOTPART
case `cd -P /sys/block/*/"$ROOTPART"/../device && pwd` in
*session*)
IS_ISCSI=true ;;
*)
IS_ISCSI=false ;;
esac
# TODO: NFS
if $IS_ISCSI; then
STARTMODE=nfsroot
fi
echo "STARTMODE=\"$STARTMODE\"" >> $DEVICEFILE
# do not write useless misleading info in case of dynamic config (#49131)
if [ "$BOOTPROTO" = "static" ]; then
IP=`grep "^IP:" $INSTALLINF | uniq | sed -e 's/IP: \\(.*\\)/\\1/'`
echo "IPADDR=\"$IP\"" >> $DEVICEFILE
fi
IP_MTU=`grep "^IP_MTU:" $INSTALLINF | uniq | sed -e 's/IP_MTU: \\(.*\\)/\\1/'`
[ -n "$IP_MTU" ] && echo "MTU=\"$IP_MTU\"" >> $DEVICEFILE
#
# Create pointopoint Interfaces
#
PTOP=`grep Pointopoint: $INSTALLINF | uniq | sed -e 's/Pointopoint: \\(.*\\)/\\1/'`
[ -n "$PTOP" ] && echo "REMOTE_IPADDR=\"$PTOP\"" >> $DEVICEFILE
#
# create broadcast-interface
#
# #49131
if [ "$BOOTPROTO" = "static" ]; then
NWMASK=`grep Netmask: $INSTALLINF | uniq | sed -e 's/Netmask: \\(.*\\)/\\1/'`
[ -n "$NWMASK" ] && echo "NETMASK=\"$NWMASK\"" >> $DEVICEFILE
NW=`grep Network: $INSTALLINF | uniq | sed -e 's/Network: \\(.*\\)/\\1/'`
[ -n "$NW" ] && echo "NETWORK=\"$NW\"" >> $DEVICEFILE
NWBROADCAST=`grep Broadcast: $INSTALLINF | uniq | sed -e 's/Broadcast: \\(.*\\)/\\1/'`
[ -n "$NWBROADCAST" ] && echo "BROADCAST=\"$NWBROADCAST\"" >> $DEVICEFILE
fi
#
# Create routingfile
#
GW=`grep Gateway: $INSTALLINF | uniq | sed -e 's/Gateway: \\(.*\\)/\\1/'`
# do not specify the interface, #39401
[ -n "$GW" ] && echo "default $GW - -" >> $ROUTINGFILE
#
# Create /etc/HOSTNAME
#
HOSTNAME=`grep Machinename: $INSTALLINF | uniq | sed -e 's/Machinename: \\(.*\\)/\\1/'`
[ -n "$HOSTNAME" ] && echo "$HOSTNAME" > $HOSTFILE
#
# Create /etc/resolv.conf
#
DOMAIN=`grep Domain: $INSTALLINF | uniq | sed -e 's/Domain: \\(.*\\)/\\1/'`
NAMESERVER=`grep Nameserver: $INSTALLINF | uniq | sed -e 's/Nameserver: \\(.*\\)/\\1/'`
if test ! -f "$RESFILE"
then
[ -n "$DOMAIN" ] && echo "domain $DOMAIN" >> $RESFILE
[ -n "$NAMESERVER" ] && echo "nameserver $NAMESERVER" >> $RESFILE
fi
#
# Create /etc/defaultdomain
#
[ -n "$DOMAIN" -a ! -f "$DOMFILE" ] && echo "$DOMAIN" >> $DOMFILE
WAIT_FOR_INTERFACES=`grep ConnectWait: $INSTALLINF | uniq | sed -e 's/ConnectWait: \\(.*\\)/\\1/'`
if [ -n "$WAIT_FOR_INTERFACES" ]
then
#
# WAIT_FOR_INTERFACES is not zero. Put the value into the file
# We are the first to modify this file. Default is zero
#
sed "s/^WAIT_FOR_INTERFACES=.*/WAIT_FOR_INTERFACES=$WAIT_FOR_INTERFACES/" < $CONFIGFILE > $CONFIGFILETMP
[ $? -eq 0 ] && mv $CONFIGFILETMP $CONFIGFILE
fi
chroot $ROOT chkconfig network on
if [ -f $TARGET_DEVICEFILE ] ; then
echo "$0: $TARGET_DEVICEFILE does already exist, keeping the original"
else
cp $DEVICEFILE $TARGET_DEVICEFILE
fi
fi
#
# Copy all hwcfg-files to the installed system
#
# Originally only for s390, now also the NETDEV hwcfg
ERG=`ls /etc/sysconfig/hardware/hwcfg-* 2> /dev/null`
if [ $? = 0 ]
then
cp /etc/sysconfig/hardware/hwcfg-* $ROOT/etc/sysconfig/hardware
fi
: