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.2 2004/05/21 12:25:29 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         if [ -z "$HWD_ID" ] ; then
76         # use kernel name
77                 myifcfg=ifcfg-$NETDEV
78         else
79         # use LLA address
80                 myifcfg=ifcfg-${HWD_DEVTYPE}-id-${HWD_ID}
81         fi
82         : ifcfg $myifcfg
83         DEVICEFILE=${DEVICEDIR}$myifcfg
84
85         # Choose correct boot protocol (#23708)
86         BOOTPROTO="dhcp"
87         if grep -q 'NetConfig:.*static' $INSTALLINF; then
88                 BOOTPROTO="static"
89         else
90                 sed "s/^DHCLIENT_SET_HOSTNAME=.*/DHCLIENT_SET_HOSTNAME=\"yes\"/" < $DHCPFILE > $DHCPFILETMP
91                 [ $? -eq 0 ] && mv $DHCPFILETMP $DHCPFILE
92         fi
93         echo "BOOTPROTO=\"$BOOTPROTO\"" > $DEVICEFILE
94
95         # Include UNIQUE number (#25739)
96         UNIQUE=`grep "^NetUniqueID:" $INSTALLINF | uniq | sed -e 's/NetUniqueID: \\(.*\\)/\\1/'`
97         echo "UNIQUE=\"$UNIQUE\"" >> $DEVICEFILE
98
99         echo "STARTMODE=\"onboot\"" >> $DEVICEFILE
100         IP=`grep "^IP:" $INSTALLINF | uniq | sed -e 's/IP: \\(.*\\)/\\1/'`
101         echo "IPADDR=\"$IP\"" >> $DEVICEFILE
102         IP_MTU=`grep "^IP_MTU:" $INSTALLINF | uniq | sed -e 's/IP_MTU: \\(.*\\)/\\1/'`
103         [ -n "$IP_MTU" ] && echo "MTU=\"$IP_MTU\"" >> $DEVICEFILE
104
105 #
106 #       Create pointopoint Interfaces
107 #
108
109         PTOP=`grep Pointopoint: $INSTALLINF | uniq | sed -e 's/Pointopoint: \\(.*\\)/\\1/'`
110         [ -n "$PTOP" ] && echo "REMOTE_IPADDR=\"$PTOP\"" >> $DEVICEFILE
111 #
112 #       create broadcast-interface
113 #
114         NWMASK=`grep Netmask: $INSTALLINF | uniq | sed -e 's/Netmask: \\(.*\\)/\\1/'`
115         [ -n "$NWMASK" ] && echo "NETMASK=\"$NWMASK\"" >> $DEVICEFILE
116         NW=`grep Network: $INSTALLINF | uniq | sed -e 's/Network: \\(.*\\)/\\1/'`
117         [ -n "$NW" ] && echo "NETWORK=\"$NW\"" >> $DEVICEFILE
118         NWBROADCAST=`grep Broadcast: $INSTALLINF | uniq | sed -e 's/Broadcast: \\(.*\\)/\\1/'`
119         [ -n "$NWBROADCAST" ] && echo "BROADCAST=\"$NWBROADCAST\"" >> $DEVICEFILE
120
121 #       
122 #       Create routingfile
123 #
124         GW=`grep Gateway: $INSTALLINF | uniq | sed -e 's/Gateway: \\(.*\\)/\\1/'`
125         # do not specify the interface, #39401
126         [ -n "$GW" ] && echo "default $GW - -" >> $ROUTINGFILE
127
128 #
129 #       Create /etc/HOSTNAME
130 #
131         HOSTNAME=`grep Machinename: $INSTALLINF | uniq | sed -e 's/Machinename: \\(.*\\)/\\1/'`
132         [ -n "$HOSTNAME" ] && echo "$HOSTNAME" > $HOSTFILE
133
134 #
135 #       Create /etc/resolv.conf
136 #
137         DOMAIN=`grep Domain: $INSTALLINF | uniq | sed -e 's/Domain: \\(.*\\)/\\1/'`
138         NAMESERVER=`grep Nameserver: $INSTALLINF | uniq | sed -e 's/Nameserver: \\(.*\\)/\\1/'`
139         if test ! -f "$RESFILE"
140         then
141                 [ -n "$DOMAIN" ] && echo "domain $DOMAIN" >> $RESFILE
142                 [ -n "$NAMESERVER" ] && echo "nameserver $NAMESERVER" >> $RESFILE
143         fi
144
145 #
146 #       Create /etc/defaultdomain
147 #
148         [ -n "$DOMAIN" -a ! -f "$DOMFILE" ] && echo "$DOMAIN" >> $DOMFILE
149         WAIT_FOR_INTERFACES=`grep ConnectWait: $INSTALLINF | uniq | sed -e 's/ConnectWait: \\(.*\\)/\\1/'`
150         if [ -n "$WAIT_FOR_INTERFACES" ]
151         then
152
153 #
154 #       WAIT_FOR_INTERFACES is not zero. Put the value into the file
155 #       We are the first to modify this file. Default is zero
156 #
157                 sed "s/^WAIT_FOR_INTERFACES=.*/WAIT_FOR_INTERFACES=$WAIT_FOR_INTERFACES/" < $CONFIGFILE > $CONFIGFILETMP
158                 [ $? -eq 0 ] && mv $CONFIGFILETMP $CONFIGFILE
159         fi
160         chroot $ROOT chkconfig network on
161 fi
162 #
163 #       Copy all hwcfg-files to the installed system
164 #
165 # Originally only for s390, now also the NETDEV hwcfg
166 ERG=`ls /etc/sysconfig/hardware/hwcfg-* 2> /dev/null`
167 if [ $? = 0 ]
168 then
169         cp /etc/sysconfig/hardware/hwcfg-* $ROOT/etc/sysconfig/hardware
170 fi
171 :