dracut-systemd/dracut-initqueue: only start service if really needed
[dracut.git] / modules.d / 80cms / cms-write-ifcfg.sh
blobeb10ae2176ce76ecb3b5b012a0b394173ec45b31
1 #!/bin/bash
3 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
5 mkdir -m 0755 -p /run/initramfs/state/etc/sysconfig/network-scripts
7 function cms_write_config()
9 . /tmp/cms.conf
10 SUBCHANNELS="$(echo $SUBCHANNELS | sed 'y/ABCDEF/abcdef/')"
11 OLDIFS=$IFS
12 IFS=,
13 read -a subch_array <<< "indexzero,$SUBCHANNELS"
14 IFS=$OLDIFS
15 devbusid=${subch_array[1]}
16 if [ "$NETTYPE" = "ctc" ]; then
17 driver="ctcm"
18 else
19 driver=$NETTYPE
22 DEVICE=$(cd /sys/devices/${driver}/$devbusid/net/ && set -- * && [ "$1" != "*" ] && echo $1)
24 uuid=$(cat /proc/sys/kernel/random/uuid)
26 IFCFGFILE=/run/initramfs/state/etc/sysconfig/network-scripts/ifcfg-$DEVICE
28 strglobin "$IPADDR" '*:*:*' && ipv6=1
30 # to please NetworkManager on startup in loader before loader reconfigures net
31 cat > /etc/sysconfig/network << EOF
32 HOSTNAME=$HOSTNAME
33 EOF
34 echo "$HOSTNAME" > /etc/hostname
35 if [ "$ipv6" ]; then
36 echo "NETWORKING_IPV6=yes" >> /etc/sysconfig/network
37 else
38 echo "NETWORKING=yes" >> /etc/sysconfig/network
41 cat > $IFCFGFILE << EOF
42 DEVICE=$DEVICE
43 UUID=$uuid
44 ONBOOT=yes
45 BOOTPROTO=static
46 MTU=$MTU
47 SUBCHANNELS=$SUBCHANNELS
48 EOF
49 if [ "$ipv6" ]; then
50 cat >> $IFCFGFILE << EOF
51 IPV6INIT=yes
52 IPV6_AUTOCONF=no
53 IPV6ADDR=$IPADDR/$NETMASK
54 IPV6_DEFAULTGW=$GATEWAY
55 EOF
56 else
57 cat >> $IFCFGFILE << EOF
58 IPADDR=$IPADDR
59 NETMASK=$NETMASK
60 BROADCAST=$BROADCAST
61 GATEWAY=$GATEWAY
62 EOF
64 if [ "$ipv6" ]; then
65 DNS1=$(set -- ${DNS/,/ }; echo $1)
66 DNS2=$(set -- ${DNS/,/ }; echo $2)
67 else
68 DNS1=$(set -- ${DNS/:/ }; echo $1)
69 DNS2=$(set -- ${DNS/:/ }; echo $2)
71 # real DNS config for NetworkManager to generate /etc/resolv.conf
72 [ "$DNS1" != "" ] && echo "DNS1=$DNS1" >> $IFCFGFILE
73 [ "$DNS2" != "" ] && echo "DNS2=$DNS2" >> $IFCFGFILE
74 # just to please loader's readNetInfo && writeEnabledNetInfo
75 # which eats DNS1,DNS2,... and generates it themselves based on DNS
76 if [ "$ipv6" ]; then
77 [ "$DNS" != "" ] && echo "DNS=\"$DNS\"" >> $IFCFGFILE
78 else
79 [ "$DNS" != "" ] && echo "DNS=\"${DNS/:/,}\"" >> $IFCFGFILE
81 # colons in SEARCHDNS already replaced with spaces above for /etc/resolv.conf
82 [ "$SEARCHDNS" != "" ] && echo "DOMAIN=\"$SEARCHDNS\"" >> $IFCFGFILE
83 [ "$NETTYPE" != "" ] && echo "NETTYPE=$NETTYPE" >> $IFCFGFILE
84 [ "$PEERID" != "" ] && echo "PEERID=$PEERID" >> $IFCFGFILE
85 [ "$PORTNAME" != "" ] && echo "PORTNAME=$PORTNAME" >> $IFCFGFILE
86 [ "$CTCPROT" != "" ] && echo "CTCPROT=$CTCPROT" >> $IFCFGFILE
87 [ "$MACADDR" != "" ] && echo "MACADDR=$MACADDR" >> $IFCFGFILE
88 optstr=""
89 for option in LAYER2 PORTNO; do
90 [ -z "${!option}" ] && continue
91 [ -n "$optstr" ] && optstr=${optstr}" "
92 optstr=${optstr}$(echo ${option} | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/')"="${!option}
93 done
94 # write single quotes since network.py removes double quotes but we need quotes
95 echo "OPTIONS='$optstr'" >> $IFCFGFILE
96 unset option
97 unset optstr
98 unset DNS1
99 unset DNS2
100 echo "files /etc/sysconfig/network-scripts" >> /run/initramfs/rwtab
101 echo "files /var/lib/dhclient" >> /run/initramfs/rwtab
104 [ -f /tmp/cms.conf ] && cms_write_config