Rebase against version 1.136.2-2
[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 if [ -x /sbin/udevadm ]
50 then
51         # lenny
52         udevadm trigger
53         udevadm settle
54 else
55         # etch
56         udevtrigger
57         udevsettle
58 fi
59
60 if [ -z "${NETBOOT}" -a -n "${STATICIP}" -a "${STATICIP}" != "frommedia" ]
61 then
62         parsed=$(echo "${STATICIP}" | sed -e 's/:/ /g')
63
64         for ifline in ${parsed}
65         do
66                 ifname="$(echo ${ifline} | cut -f1 -d ',')"
67                 ifaddress="$(echo ${ifline} | cut -f2 -d ',')"
68                 ifnetmask="$(echo ${ifline} | cut -f3 -d ',')"
69                 ifgateway="$(echo ${ifline} | cut -f4 -d ',')"
70
71 cat >> "${IFFILE}" << EOF
72 auto ${ifname}
73 iface ${ifname} inet static
74     address ${ifaddress}
75     netmask ${ifnetmask}
76     gateway ${ifgateway}
77
78 EOF
79
80         done
81 else
82         if [ -z "${NETBOOT}" ]
83         then
84                 # default, dhcp assigned
85                 method="dhcp"
86         else
87                 # make sure that the preconfigured interface would not get reassigned by dhcp
88                 # on startup by ifup script - otherwise our root fs might be disconnected!
89                 method="manual"
90         fi
91
92         # iterate the physical interfaces and add them to the interfaces list
93         if [ "${method}" != dhcp ] || [ ! -x /root/usr/sbin/NetworkManager ]
94         then
95                 for interface in /sys/class/net/eth* /sys/class/net/ath* /sys/class/net/wlan*
96                 do
97                         [ -e ${interface} ] || continue
98                         i="$(basename ${interface})"
99
100 cat >> "${IFFILE}" << EOF
101 auto ${i}
102 iface ${i} inet ${method}
103
104 EOF
105
106                 done
107         fi
108
109         if [ ! -f /root/etc/resolv.conf ] || [ -z "$(cat /root/etc/resolv.conf)" ]
110         then
111                 if [ -f /netboot.config ]
112                 then
113                         # create a resolv.conf if it is not present or empty
114                         cp /netboot.config /root/var/log/netboot.config
115
116                         rc_search=$(cat netboot.config | awk '/domain/{print $3}')
117                         rc_server0=$(cat netboot.config | awk '/dns0/{print $5}')
118                         rc_server1=$(cat netboot.config | awk '/dns0/{print $8}')
119                         rc_server0="nameserver ${rc_server0}"
120
121                         if [ "${rc_server1}" = "0.0.0.0" ]
122                         then
123                                 rc_server1=""
124                         else
125                                 rc_server1="nameserver ${rc_server1}"
126                         fi
127
128 cat > /root/etc/resolv.conf << EOF
129 # /etc/resolv.conf
130 # Autogenerated by live-initramfs
131 search ${rc_search}
132 domain ${rc_search}
133 ${rc_server0}
134 ${rc_server1}
135 EOF
136
137                         cat /root/etc/resolv.conf >> /root/var/log/netboot.config
138                 fi
139         fi
140 fi
141
142 #if [ ! -x /root/usr/sbin/NetworkManager ]
143 #then
144 #       for i in eth0 eth1 eth2 ath0 wlan0
145 #       do
146 #               grep -q "iface ${i}" ${IFFILE} && continue
147 #
148 #cat >> "${IFFILE}" << EOF
149 #auto ${i}
150 #iface ${i} inet dhcp
151 #
152 #EOF
153 #
154 #       done
155 #fi
156
157 log_end_msg