fixed missing NS problem (bug #35812)
[opensuse:installation-images.git] / data / root / etc / create_interface
1 #!/bin/sh
2
3 # Create interface and chandev entry
4 #
5 # Olaf Hering <olh@suse.de>
6 # Michal Svec <msvec@suse.cz>
7 # Ihno Krumreich <ihno@suse.de>
8 #
9 # $Id: create_interface,v 1.13 2004/03/15 10:17:44 uli Exp $
10
11 ROOT=$1
12 INSTALLINF=/etc/install.inf
13 CHANDEVCONF=$ROOT/etc/chandev.conf
14 DEVICEDIR=$ROOT/etc/sysconfig/network/
15 ROUTINGFILE=$ROOT/etc/sysconfig/network/routes
16 HOSTFILE=$ROOT/etc/HOSTNAME
17 RESFILE=$ROOT/etc/resolv.conf
18 DOMFILE=$ROOT/etc/defaultdomain
19 DHCPFILE=$ROOT/etc/sysconfig/network/dhcp
20 DHCPFILETMP=$ROOT/etc/sysconfig/network/dhcp.tmp
21 CONFIGFILE=$ROOT/etc/sysconfig/network/config
22 CONFIGFILETMP=$ROOT/etc/sysconfig/network/config.tmp
23 MODCONFFILE=$ROOT/etc/modules.conf
24 MODCONFFILETMP=$ROOT/etc/modules.conf.tmp
25 # INSTALLINF=netsetup.inf
26 # INSTALLINF=install.inf
27 # CHANDEVCONF=chandev.conf
28 # DEVICEDIR=
29 # ROUTINGFILE=routes
30 #
31
32 if [ -f $INSTALLINF ]
33 then
34
35 #       Check for chandev
36 #       CHANDEV=`grep Chandev: $INSTALLINF | uniq | sed -e 's/Chandev: \\(.*\\)/\\1/'`
37 #       [ -n "$CHANDEV" ] && echo $CHANDEV >> $CHANDEVCONF
38 #
39 #       Create modules.conf Entry (alias)
40 #
41         MODCONF=`grep Alias: $INSTALLINF | uniq | sed -e 's/Alias: \\(.*\\)/\\1/'`
42         if [ -n "$MODCONF" ]
43         then
44                 set -- $MODCONF
45                 if [ $# -eq 2 ]
46                 then
47                         egrep "alias[[:space:]]*$1[[:space:]]*" $MODCONFFILE 2>&1 > /dev/null
48                         if [ $? -eq 0 ]
49                         then
50 #                               Entry found
51                                 egrep -v "alias[[:space:]]*$1[[:space:]]*" $MODCONFFILE > $MODCONFFILETMP
52                                 [ $? -eq 0 ] && mv $MODCONFFILETMP $MODCONFFILE
53                                 
54                         fi
55                         echo "alias $MODCONF" >> $MODCONFFILE
56                 fi
57         fi
58
59 #
60 #       Create modules.conf Entry (Options)
61 #
62         MODCONF=`grep Options: $INSTALLINF | uniq | sed -e 's/Options: \\(.*\\)/\\1/'`
63         if [ -n "$MODCONF" ]
64         then
65                 egrep "options[[:space:]]*$1[[:space:]]*" $MODCONFFILE 2>&1 > /dev/null
66                 if [ $? -eq 0 ]
67                 then
68 #                       Entry found
69                         egrep -v "options[[:space:]]*$1[[:space:]]*" $MODCONFFILE > $MODCONFFILETMP
70                         [ $? -eq 0 ] && mv $MODCONFFILETMP $MODCONFFILE
71                         
72                 fi
73                 echo "options $MODCONF" >> $MODCONFFILE
74         fi
75
76 #
77 #       Create interfacefile
78 #
79         NETDEV=`grep Netdevice: $INSTALLINF | grep -v sit0 | uniq | sed -e 's/Netdevice: \\(.*\\)/\\1/'`
80         DEVICEFILE=${DEVICEDIR}ifcfg-$NETDEV
81
82         # Choose correct boot protocol (#23708)
83         BOOTPROTO="dhcp"
84         if grep -q 'NetConfig:.*static' $INSTALLINF; then
85                 BOOTPROTO="static"
86         else
87                 sed "s/^DHCLIENT_SET_HOSTNAME=.*/DHCLIENT_SET_HOSTNAME=\"yes\"/" < $DHCPFILE > $DHCPFILETMP
88                 [ $? -eq 0 ] && mv $DHCPFILETMP $DHCPFILE
89         fi
90         echo "BOOTPROTO=\"$BOOTPROTO\"" > $DEVICEFILE
91
92         # Include UNIQUE number (#25739)
93         UNIQUE=`grep "^NetUniqueID:" $INSTALLINF | uniq | sed -e 's/NetUniqueID: \\(.*\\)/\\1/'`
94         echo "UNIQUE=\"$UNIQUE\"" >> $DEVICEFILE
95
96         echo "STARTMODE=\"onboot\"" >> $DEVICEFILE
97         IP=`grep "^IP:" $INSTALLINF | uniq | sed -e 's/IP: \\(.*\\)/\\1/'`
98         echo "IPADDR=\"$IP\"" >> $DEVICEFILE
99         IP_MTU=`grep "^IP_MTU:" $INSTALLINF | uniq | sed -e 's/IP_MTU: \\(.*\\)/\\1/'`
100         [ -n "$IP_MTU" ] && echo "MTU=\"$IP_MTU\"" >> $DEVICEFILE
101
102 #
103 #       Create pointopoint Interfaces
104 #
105
106         PTOP=`grep Pointopoint: $INSTALLINF | uniq | sed -e 's/Pointopoint: \\(.*\\)/\\1/'`
107         [ -n "$PTOP" ] && echo "REMOTE_IPADDR=\"$PTOP\"" >> $DEVICEFILE
108 #
109 #       create broadcast-interface
110 #
111         NWMASK=`grep Netmask: $INSTALLINF | uniq | sed -e 's/Netmask: \\(.*\\)/\\1/'`
112         [ -n "$NWMASK" ] && echo "NETMASK=\"$NWMASK\"" >> $DEVICEFILE
113         NW=`grep Network: $INSTALLINF | uniq | sed -e 's/Network: \\(.*\\)/\\1/'`
114         [ -n "$NW" ] && echo "NETWORK=\"$NW\"" >> $DEVICEFILE
115         NWBROADCAST=`grep Broadcast: $INSTALLINF | uniq | sed -e 's/Broadcast: \\(.*\\)/\\1/'`
116         [ -n "$NWBROADCAST" ] && echo "BROADCAST=\"$NWBROADCAST\"" >> $DEVICEFILE
117
118 #       
119 #       Create routingfile
120 #
121         GW=`grep Gateway: $INSTALLINF | uniq | sed -e 's/Gateway: \\(.*\\)/\\1/'`
122         [ -n "$GW" ] && echo "default $GW 0.0.0.0 $NETDEV" >> $ROUTINGFILE
123
124 #
125 #       Create /etc/HOSTNAME
126 #
127         HOSTNAME=`grep Machinename: $INSTALLINF | uniq | sed -e 's/Machinename: \\(.*\\)/\\1/'`
128         [ -n "$HOSTNAME" ] && echo "$HOSTNAME" > $HOSTFILE
129
130 #
131 #       Create /etc/resolv.conf
132 #
133         DOMAIN=`grep Domain: $INSTALLINF | uniq | sed -e 's/Domain: \\(.*\\)/\\1/'`
134         NAMESERVER=`grep Nameserver: $INSTALLINF | uniq | sed -e 's/Nameserver: \\(.*\\)/\\1/'`
135         if test ! -f "$RESFILE"
136         then
137                 [ -n "$DOMAIN" ] && echo "domain $DOMAIN" >> $RESFILE
138                 [ -n "$NAMESERVER" ] && echo "nameserver $NAMESERVER" >> $RESFILE
139         fi
140
141 #
142 #       Create /etc/defaultdomain
143 #
144         [ -n "$DOMAIN" -a ! -f "$DOMFILE" ] && echo "$DOMAIN" >> $DOMFILE
145         WAIT_FOR_INTERFACES=`grep ConnectWait: $INSTALLINF | uniq | sed -e 's/ConnectWait: \\(.*\\)/\\1/'`
146         if [ -n "$WAIT_FOR_INTERFACES" ]
147         then
148
149 #
150 #       WAIT_FOR_INTERFACES is not zero. Put the value into the file
151 #       We are the first to modify this file. Default is zero
152 #
153                 sed "s/^WAIT_FOR_INTERFACES=.*/WAIT_FOR_INTERFACES=$WAIT_FOR_INTERFACES/" < $CONFIGFILE > $CONFIGFILETMP
154                 [ $? -eq 0 ] && mv $CONFIGFILETMP $CONFIGFILE
155         fi
156         chroot $ROOT chkconfig network on
157 fi
158 #
159 #       Copy all hwcfg-files to the installed system
160 #
161 ERG=`ls /etc/sysconfig/hardware/hwcfg-* 2> /dev/null`
162 if [ $? = 0 ]
163 then
164         cp /etc/sysconfig/hardware/hwcfg-* $ROOT/etc/sysconfig/hardware
165 fi
166 :