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