Moving initramfs-tools entry-point to backends.
[debian-live-boot.git] / scripts / boot / 9990-networking.sh
blobd9607b795d1093b508bd07a0a624728f1fbaae8b
1 #!/bin/sh
3 #set -e
5 do_netsetup ()
7 modprobe -q af_packet # For DHCP
9 udevadm trigger
10 udevadm settle
12 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
13 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
15 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
16 then
17 # support for Syslinux IPAPPEND parameter
18 # it sets the BOOTIF variable on the kernel parameter
20 if [ -n "${BOOTIF}" ]
21 then
22 # pxelinux sets BOOTIF to a value based on the mac address of the
23 # network card used to PXE boot, so use this value for DEVICE rather
24 # than a hard-coded device name from initramfs.conf. this facilitates
25 # network booting when machines may have multiple network cards.
26 # pxelinux sets BOOTIF to 01-$mac_address
28 # strip off the leading "01-", which isn't part of the mac
29 # address
30 temp_mac=${BOOTIF#*-}
32 # convert to typical mac address format by replacing "-" with ":"
33 bootif_mac=""
34 IFS='-'
35 for x in $temp_mac
37 if [ -z "$bootif_mac" ]
38 then
39 bootif_mac="$x"
40 else
41 bootif_mac="$bootif_mac:$x"
43 done
44 unset IFS
46 # look for devices with matching mac address, and set DEVICE to
47 # appropriate value if match is found.
49 for device in /sys/class/net/*
51 if [ -f "$device/address" ]
52 then
53 current_mac=$(cat "$device/address")
55 if [ "$bootif_mac" = "$current_mac" ]
56 then
57 DEVICE=${device##*/}
58 break
61 done
64 # if ethdevice was not specified on the kernel command line
65 # make sure we try to get a working network configuration
66 # for *every* present network device (except for loopback of course)
67 if [ -z "$ETHDEVICE" ]
68 then
69 echo "If you want to boot from a specific device use bootoption ethdevice=..."
70 for device in /sys/class/net/*
72 dev=${device##*/}
73 if [ "$dev" != "lo" ]
74 then
75 ETHDEVICE="$ETHDEVICE $dev"
77 done
80 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
81 for device in $(echo $ETHDEVICE | sed 's/,/ /g')
83 devlist="$devlist $device"
84 done
86 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
87 # an endless loop; if execution fails give it two further tries, that's
88 # why we use '$devlist $devlist $devlist' for the other for loop
89 for dev in $devlist $devlist $devlist
91 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
92 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
93 jobid=$!
94 sleep "$ETHDEV_TIMEOUT" ; sleep 1
95 if [ -r /proc/"$jobid"/status ]
96 then
97 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
98 kill -9 $jobid
101 # if configuration of device worked we should have an assigned
102 # IP address, if so let's use the device as $DEVICE for later usage.
103 # simple and primitive approach which seems to work fine
104 if ifconfig $dev | grep -q 'inet.*addr:'
105 then
106 export DEVICE="$dev"
107 break
109 done
110 else
111 for interface in ${DEVICE}; do
112 ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config
114 [ -e /run/net-${interface}.conf ] && . /run/net-${interface}.conf
116 if [ "$IPV4ADDR" != "0.0.0.0" ]
117 then
118 break
120 done
123 for interface in ${DEVICE}
125 # source relevant ipconfig output
126 OLDHOSTNAME=${HOSTNAME}
128 [ -e /run/net-${interface}.conf ] && . /run/net-${interface}.conf
130 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
131 export HOSTNAME
133 if [ -n "${interface}" ]
134 then
135 HWADDR="$(cat /sys/class/net/${interface}/address)"
138 if [ ! -e "/etc/resolv.conf" ]
139 then
140 echo "Creating /etc/resolv.conf"
142 if [ -n "${DNSDOMAIN}" ]
143 then
144 echo "domain ${DNSDOMAIN}" > /etc/resolv.conf
145 echo "search ${DNSDOMAIN}" >> /etc/resolv.conf
148 for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1}
150 if [ -n "$i" ] && [ "$i" != 0.0.0.0 ]
151 then
152 echo "nameserver $i" >> /etc/resolv.conf
154 done
157 # Check if we have a network device at all
158 if ! ls /sys/class/net/"$interface" > /dev/null 2>&1 && \
159 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
160 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
161 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
162 ! ls /sys/class/net/ra0 > /dev/null 2>&1
163 then
164 panic "No supported network device found, maybe a non-mainline driver is required."
166 done