- added getcfg & create_interface (#35624)
[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 2004/04/01 12:39:50 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 $NETDEV`
41
42
43 #
44 #       Create hardware configuration file
45 #
46         # hardware config
47         if [ "$HWD_BUS_N" -gt 0 ] ; then
48         # use bus info
49                 eval HWD_BUSNAME=\$HWD_BUSNAME_$((HWD_BUS_N-1))
50                 eval HWD_BUSID=\$HWD_BUSID_$((HWD_BUS_N-1))
51                 myhwcfg=hwcfg-bus-${HWD_BUSNAME}-${HWD_BUSID}
52         else
53         # use static name
54                 myhwcfg=hwcfg-static-0
55         fi
56         : hwcfg $myhwcfg
57         HARDWAREFILE=${HARDWAREDIR}$myhwcfg
58
59         # Here save Aliases and Options for $NETDEV
60         MODULE=`grep "Alias: $NETDEV" $INSTALLINF | uniq | sed -e "s/Alias: $NETDEV \\(.*\\)/\\1/"`
61         MODULE_OPTIONS=`grep "Options: $NETDEV" $INSTALLINF | uniq | sed -e "s/Options: $NETDEV \\(.*\\)/\\1/"`
62         echo "STARTMODE='auto'" > $HARDWAREFILE
63         echo "MODULE='$MODULE'" >> $HARDWAREFILE
64         echo "MODULE_OPTIONS='$MODULE_OPTIONS'" >> $HARDWAREFILE
65
66 #
67 #       Create interface file
68 #
69         # interface config
70         if [ -z "$HWD_ID" ] ; then
71         # use kernel name
72                 myifcfg=ifcfg-$NETDEV
73         else
74         # use LLA address
75                 myifcfg=ifcfg-${HWD_DEVTYPE}-id-${HWD_ID}
76         fi
77         : ifcfg $myifcfg
78         DEVICEFILE=${DEVICEDIR}$myifcfg
79
80         # Choose correct boot protocol (#23708)
81         BOOTPROTO="dhcp"
82         if grep -q 'NetConfig:.*static' $INSTALLINF; then
83                 BOOTPROTO="static"
84         else
85                 sed "s/^DHCLIENT_SET_HOSTNAME=.*/DHCLIENT_SET_HOSTNAME=\"yes\"/" < $DHCPFILE > $DHCPFILETMP
86                 [ $? -eq 0 ] && mv $DHCPFILETMP $DHCPFILE
87         fi
88         echo "BOOTPROTO=\"$BOOTPROTO\"" > $DEVICEFILE
89
90         # Include UNIQUE number (#25739)
91         UNIQUE=`grep "^NetUniqueID:" $INSTALLINF | uniq | sed -e 's/NetUniqueID: \\(.*\\)/\\1/'`
92         echo "UNIQUE=\"$UNIQUE\"" >> $DEVICEFILE
93
94         echo "STARTMODE=\"onboot\"" >> $DEVICEFILE
95         IP=`grep "^IP:" $INSTALLINF | uniq | sed -e 's/IP: \\(.*\\)/\\1/'`
96         echo "IPADDR=\"$IP\"" >> $DEVICEFILE
97         IP_MTU=`grep "^IP_MTU:" $INSTALLINF | uniq | sed -e 's/IP_MTU: \\(.*\\)/\\1/'`
98         [ -n "$IP_MTU" ] && echo "MTU=\"$IP_MTU\"" >> $DEVICEFILE
99
100 #
101 #       Create pointopoint Interfaces
102 #
103
104         PTOP=`grep Pointopoint: $INSTALLINF | uniq | sed -e 's/Pointopoint: \\(.*\\)/\\1/'`
105         [ -n "$PTOP" ] && echo "REMOTE_IPADDR=\"$PTOP\"" >> $DEVICEFILE
106 #
107 #       create broadcast-interface
108 #
109         NWMASK=`grep Netmask: $INSTALLINF | uniq | sed -e 's/Netmask: \\(.*\\)/\\1/'`
110         [ -n "$NWMASK" ] && echo "NETMASK=\"$NWMASK\"" >> $DEVICEFILE
111         NW=`grep Network: $INSTALLINF | uniq | sed -e 's/Network: \\(.*\\)/\\1/'`
112         [ -n "$NW" ] && echo "NETWORK=\"$NW\"" >> $DEVICEFILE
113         NWBROADCAST=`grep Broadcast: $INSTALLINF | uniq | sed -e 's/Broadcast: \\(.*\\)/\\1/'`
114         [ -n "$NWBROADCAST" ] && echo "BROADCAST=\"$NWBROADCAST\"" >> $DEVICEFILE
115
116 #       
117 #       Create routingfile
118 #
119         GW=`grep Gateway: $INSTALLINF | uniq | sed -e 's/Gateway: \\(.*\\)/\\1/'`
120         [ -n "$GW" ] && echo "default $GW 0.0.0.0 $NETDEV" >> $ROUTINGFILE
121
122 #
123 #       Create /etc/HOSTNAME
124 #
125         HOSTNAME=`grep Machinename: $INSTALLINF | uniq | sed -e 's/Machinename: \\(.*\\)/\\1/'`
126         [ -n "$HOSTNAME" ] && echo "$HOSTNAME" > $HOSTFILE
127
128 #
129 #       Create /etc/resolv.conf
130 #
131         DOMAIN=`grep Domain: $INSTALLINF | uniq | sed -e 's/Domain: \\(.*\\)/\\1/'`
132         NAMESERVER=`grep Nameserver: $INSTALLINF | uniq | sed -e 's/Nameserver: \\(.*\\)/\\1/'`
133         if test ! -f "$RESFILE"
134         then
135                 [ -n "$DOMAIN" ] && echo "domain $DOMAIN" >> $RESFILE
136                 [ -n "$NAMESERVER" ] && echo "nameserver $NAMESERVER" >> $RESFILE
137         fi
138
139 #
140 #       Create /etc/defaultdomain
141 #
142         [ -n "$DOMAIN" -a ! -f "$DOMFILE" ] && echo "$DOMAIN" >> $DOMFILE
143         WAIT_FOR_INTERFACES=`grep ConnectWait: $INSTALLINF | uniq | sed -e 's/ConnectWait: \\(.*\\)/\\1/'`
144         if [ -n "$WAIT_FOR_INTERFACES" ]
145         then
146
147 #
148 #       WAIT_FOR_INTERFACES is not zero. Put the value into the file
149 #       We are the first to modify this file. Default is zero
150 #
151                 sed "s/^WAIT_FOR_INTERFACES=.*/WAIT_FOR_INTERFACES=$WAIT_FOR_INTERFACES/" < $CONFIGFILE > $CONFIGFILETMP
152                 [ $? -eq 0 ] && mv $CONFIGFILETMP $CONFIGFILE
153         fi
154         chroot $ROOT chkconfig network on
155 fi
156 #
157 #       Copy all hwcfg-files to the installed system
158 #
159 # Originally only for s390, now also the NETDEV hwcfg
160 ERG=`ls /etc/sysconfig/hardware/hwcfg-* 2> /dev/null`
161 if [ $? = 0 ]
162 then
163         cp /etc/sysconfig/hardware/hwcfg-* $ROOT/etc/sysconfig/hardware
164 fi
165 :