This commit was manufactured by cvs2svn to create tag
[opensuse:installation-images.git] / data / root / etc / create_interface
1 #!/bin/sh
2
3 # Create interface
4 #
5 # Olaf Hering <olh@suse.de>
6 # Michal Svec <msvec@suse.cz>
7 # Martin Vidner <mvidner@suse.cz>
8 # Ihno Krumreich <ihno@suse.de>
9 #
10 # $Id: create_interface,v 1.14.2.4 2004/06/22 15:46:23 snwint Exp $
11
12 ROOT=$1
13 INSTALLINF=/etc/install.inf
14 # files copied to $ROOT at the end of script
15 HARDWAREDIR=/etc/sysconfig/hardware/
16 DEVICEDIR=$ROOT/etc/sysconfig/network/
17 ROUTINGFILE=$ROOT/etc/sysconfig/network/routes
18 HOSTFILE=$ROOT/etc/HOSTNAME
19 RESFILE=$ROOT/etc/resolv.conf
20 DOMFILE=$ROOT/etc/defaultdomain
21 DHCPFILE=$ROOT/etc/sysconfig/network/dhcp
22 DHCPFILETMP=$ROOT/etc/sysconfig/network/dhcp.tmp
23 CONFIGFILE=$ROOT/etc/sysconfig/network/config
24 CONFIGFILETMP=$ROOT/etc/sysconfig/network/config.tmp
25 MODCONFFILE=$ROOT/etc/modules.conf
26 MODCONFFILETMP=$ROOT/etc/modules.conf.tmp
27 # INSTALLINF=netsetup.inf
28 # INSTALLINF=install.inf
29 # DEVICEDIR=
30 # ROUTINGFILE=routes
31 #
32
33 if [ -f $INSTALLINF ]
34 then
35
36 #
37 #       Get configuration for the installation device
38 #
39         NETDEV=`grep Netdevice: $INSTALLINF | grep -v sit0 | uniq | sed -e 's/Netdevice: \\(.*\\)/\\1/'`
40         eval `getcfg -f hwcfg- -d /etc/sysconfig/hardware $NETDEV`
41
42
43 #
44 #       Create hardware configuration file if it doesn't exist
45 #
46         if [ "$HWD_CONFIG_N" -gt 0 ] ; then
47             # hwcfg file exist, do not modify it
48             eval HWD_CONFIG=\$HWD_CONFIG_$((HWD_CONFIG_N-1))
49             myhwcfg=${HWD_CONFIG}
50         elif [ "$HWD_BUS_N" -gt 0 ] ; then
51             # use bus info
52             eval HWD_BUSNAME=\$HWD_BUSNAME_$((HWD_BUS_N-1))
53             eval HWD_BUSID=\$HWD_BUSID_$((HWD_BUS_N-1))
54             myhwcfg=hwcfg-bus-${HWD_BUSNAME}-${HWD_BUSID}
55         else
56             # use static name
57             myhwcfg=hwcfg-static-0
58         fi
59         : hwcfg $myhwcfg
60         HARDWAREFILE=${HARDWAREDIR}$myhwcfg
61
62         if [ ! -f ${HARDWAREFILE} ] ; then
63             # Here save Aliases and Options for $NETDEV
64             MODULE=`grep "Alias: $NETDEV" $INSTALLINF | uniq | sed -e "s/Alias: $NETDEV \\(.*\\)/\\1/"`
65             MODULE_OPTIONS=`grep "Options: $NETDEV" $INSTALLINF | uniq | sed -e "s/Options: $NETDEV \\(.*\\)/\\1/"`
66             echo "STARTMODE='auto'" > $HARDWAREFILE
67             echo "MODULE='$MODULE'" >> $HARDWAREFILE
68             echo "MODULE_OPTIONS='$MODULE_OPTIONS'" >> $HARDWAREFILE
69         fi
70
71 #
72 #       Create interface file
73 #
74         # interface config
75         # always use by-bus for qeth, hsi, ctc, and lcs
76         if echo "$myhwcfg"|grep -E "(qeth|hsi|ctc|lcs)" 
77         then
78         # use by-bus naming
79                 myifcfg=ifcfg-$myhwcfg
80         elif [ -z "$HWD_ID" ] ; then
81         # use kernel name
82                 myifcfg=ifcfg-$NETDEV
83         else
84         # use LLA address
85                 myifcfg=ifcfg-${HWD_DEVTYPE}-id-${HWD_ID}
86         fi
87         : ifcfg $myifcfg
88         DEVICEFILE=${DEVICEDIR}$myifcfg
89
90         # Choose correct boot protocol (#23708)
91         BOOTPROTO="dhcp"
92         if grep -q 'NetConfig:.*static' $INSTALLINF; then
93                 BOOTPROTO="static"
94         else
95                 sed "s/^DHCLIENT_SET_HOSTNAME=.*/DHCLIENT_SET_HOSTNAME=\"yes\"/" < $DHCPFILE > $DHCPFILETMP
96                 [ $? -eq 0 ] && mv $DHCPFILETMP $DHCPFILE
97         fi
98         echo "BOOTPROTO=\"$BOOTPROTO\"" > $DEVICEFILE
99
100         # Include UNIQUE number (#25739)
101         UNIQUE=`grep "^NetUniqueID:" $INSTALLINF | uniq | sed -e 's/NetUniqueID: \\(.*\\)/\\1/'`
102         echo "UNIQUE=\"$UNIQUE\"" >> $DEVICEFILE
103
104         echo "STARTMODE=\"onboot\"" >> $DEVICEFILE
105         IP=`grep "^IP:" $INSTALLINF | uniq | sed -e 's/IP: \\(.*\\)/\\1/'`
106         echo "IPADDR=\"$IP\"" >> $DEVICEFILE
107         IP_MTU=`grep "^IP_MTU:" $INSTALLINF | uniq | sed -e 's/IP_MTU: \\(.*\\)/\\1/'`
108         [ -n "$IP_MTU" ] && echo "MTU=\"$IP_MTU\"" >> $DEVICEFILE
109
110 #
111 #       Create pointopoint Interfaces
112 #
113
114         PTOP=`grep Pointopoint: $INSTALLINF | uniq | sed -e 's/Pointopoint: \\(.*\\)/\\1/'`
115         [ -n "$PTOP" ] && echo "REMOTE_IPADDR=\"$PTOP\"" >> $DEVICEFILE
116 #
117 #       create broadcast-interface
118 #
119         NWMASK=`grep Netmask: $INSTALLINF | uniq | sed -e 's/Netmask: \\(.*\\)/\\1/'`
120         [ -n "$NWMASK" ] && echo "NETMASK=\"$NWMASK\"" >> $DEVICEFILE
121         NW=`grep Network: $INSTALLINF | uniq | sed -e 's/Network: \\(.*\\)/\\1/'`
122         [ -n "$NW" ] && echo "NETWORK=\"$NW\"" >> $DEVICEFILE
123         NWBROADCAST=`grep Broadcast: $INSTALLINF | uniq | sed -e 's/Broadcast: \\(.*\\)/\\1/'`
124         [ -n "$NWBROADCAST" ] && echo "BROADCAST=\"$NWBROADCAST\"" >> $DEVICEFILE
125
126 #       
127 #       Create routingfile
128 #
129         GW=`grep Gateway: $INSTALLINF | uniq | sed -e 's/Gateway: \\(.*\\)/\\1/'`
130         # do not specify the interface, #39401
131         [ -n "$GW" ] && echo "default $GW - -" >> $ROUTINGFILE
132
133 #
134 #       Create /etc/HOSTNAME
135 #
136         HOSTNAME=`grep Machinename: $INSTALLINF | uniq | sed -e 's/Machinename: \\(.*\\)/\\1/'`
137         [ -n "$HOSTNAME" ] && echo "$HOSTNAME" > $HOSTFILE
138
139 #
140 #       Create /etc/resolv.conf
141 #
142         DOMAIN=`grep Domain: $INSTALLINF | uniq | sed -e 's/Domain: \\(.*\\)/\\1/'`
143         NAMESERVER=`grep Nameserver: $INSTALLINF | uniq | sed -e 's/Nameserver: \\(.*\\)/\\1/'`
144         if test ! -f "$RESFILE"
145         then
146                 [ -n "$DOMAIN" ] && echo "domain $DOMAIN" >> $RESFILE
147                 [ -n "$NAMESERVER" ] && echo "nameserver $NAMESERVER" >> $RESFILE
148         fi
149
150 #
151 #       Create /etc/defaultdomain
152 #
153         [ -n "$DOMAIN" -a ! -f "$DOMFILE" ] && echo "$DOMAIN" >> $DOMFILE
154         WAIT_FOR_INTERFACES=`grep ConnectWait: $INSTALLINF | uniq | sed -e 's/ConnectWait: \\(.*\\)/\\1/'`
155         if [ -n "$WAIT_FOR_INTERFACES" ]
156         then
157
158 #
159 #       WAIT_FOR_INTERFACES is not zero. Put the value into the file
160 #       We are the first to modify this file. Default is zero
161 #
162                 sed "s/^WAIT_FOR_INTERFACES=.*/WAIT_FOR_INTERFACES=$WAIT_FOR_INTERFACES/" < $CONFIGFILE > $CONFIGFILETMP
163                 [ $? -eq 0 ] && mv $CONFIGFILETMP $CONFIGFILE
164         fi
165         chroot $ROOT chkconfig network on
166 fi
167 #
168 #       Copy all hwcfg-files to the installed system
169 #
170 # Originally only for s390, now also the NETDEV hwcfg
171 ERG=`ls /etc/sysconfig/hardware/hwcfg-* 2> /dev/null`
172 if [ $? = 0 ]
173 then
174         cp /etc/sysconfig/hardware/hwcfg-* $ROOT/etc/sysconfig/hardware
175 fi
176 :