Initial checkin
[live-initramfs-grml.git] / scripts / live-bottom / 23networking
1 #!/bin/sh
2
3 #set -e
4
5 # initramfs-tools header
6
7 PREREQ=""
8
9 prereqs()
10 {
11         echo "${PREREQ}"
12 }
13
14 case "${1}" in
15         prereqs)
16                 prereqs
17                 exit 0
18                 ;;
19 esac
20
21 # live-initramfs header
22
23 if [ -n "${NONETWORKING}" ]
24 then
25         exit 0
26 fi
27
28 . /scripts/live-functions
29
30 log_begin_msg "Preconfiguring networking..."
31
32 # live-initramfs script
33
34 IFFILE="/root/etc/network/interfaces"
35
36 if [ "${STATICIP}" = "frommedia" -a -e  "${IFFILE}" ]
37 then
38         # will use existent /etc/network/interfaces
39         log_end_msg
40         exit 0
41 fi
42
43 cat > "${IFFILE}" << EOF
44 auto lo
45 iface lo inet loopback
46
47 EOF
48
49 udevtrigger
50 udevsettle
51
52 if [ -z "${NETBOOT}" -a -n "${STATICIP}" -a "${STATICIP}" != "frommedia" ]
53 then
54         parsed=$(echo "${STATICIP}" | sed -e 's/:/ /g')
55
56         for ifline in ${parsed}
57         do
58                 ifname="$(echo ${ifline} | cut -f1 -d ',')"
59                 ifaddress="$(echo ${ifline} | cut -f2 -d ',')"
60                 ifnetmask="$(echo ${ifline} | cut -f3 -d ',')"
61                 ifgateway="$(echo ${ifline} | cut -f4 -d ',')"
62
63 cat >> "${IFFILE}" << EOF
64 auto ${ifname}
65 iface ${ifname} inet static
66     address ${ifaddress}
67     netmask ${ifnetmask}
68     gateway ${ifgateway}
69
70 EOF
71
72         done
73 else
74         if [ -z "${NETBOOT}" ]
75         then
76                 # default, dhcp assigned
77                 method="dhcp"
78         else
79                 # make sure that the preconfigured interface would not get reassigned by dhcp
80                 # on startup by ifup script - otherwise our root fs might be disconnected!
81                 method="manual"
82         fi
83
84         # iterate the physical interfaces and add them to the interfaces list
85         if [ "${method}" != dhcp ] || [ ! -x /root/usr/sbin/NetworkManager ]
86         then
87                 for interface in /sys/class/net/eth* /sys/class/net/ath* /sys/class/net/wlan*
88                 do
89                         [ -e ${interface} ] || continue
90                         i="$(basename ${interface})"
91
92 cat >> "${IFFILE}" << EOF
93 auto ${i}
94 iface ${i} inet ${method}
95
96 EOF
97
98                 done
99         fi
100
101         if [ ! -f /root/etc/resolv.conf -a -f /netboot.config ]
102         then
103                 # create a resolv.conf if it is not present
104                 cp /netboot.config /root/var/log/netboot.config
105
106                 rc_search=$(cat netboot.config | awk '/domain/{print $3}')
107                 rc_server0=$(cat netboot.config | awk '/dns0/{print $5}')
108                 rc_server1=$(cat netboot.config | awk '/dns0/{print $8}')
109                 rc_server0="nameserver ${rc_server0}"
110
111                 if [ "${rc_server1}" = "0.0.0.0" ]
112                 then
113                         rc_server1=""
114                 else
115                         rc_server1="nameserver ${rc_server1}"
116                 fi
117
118 cat > /root/etc/resolv.conf << EOF
119 # /etc/resolv.conf
120 # Autogenerated by live-initramfs
121 search ${rc_search}
122 domain ${rc_search}
123 ${rc_server0}
124 ${rc_server1}
125 EOF
126
127                 cat /root/etc/resolv.conf >> /root/var/log/netboot.config
128         fi
129 fi
130
131 #if [ ! -x /root/usr/sbin/NetworkManager ]
132 #then
133 #       for i in eth0 eth1 eth2 ath0 wlan0
134 #       do
135 #               grep -q "iface ${i}" ${IFFILE} && continue
136 #
137 #cat >> "${IFFILE}" << EOF
138 #auto ${i}
139 #iface ${i} inet dhcp
140 #
141 #EOF
142 #
143 #       done
144 #fi
145
146 log_end_msg