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