Move check for block device to mount_persistence_media().
[debian-live-boot.git] / components / 9990-networking.sh
blobdbdc9133431954f9059af52e38bc0b6838fa19bc
1 #!/bin/sh
3 #set -e
5 Device_from_bootif ()
7 # support for Syslinux IPAPPEND parameter
8 # it sets the BOOTIF variable on the kernel parameter
10 if [ -n "${BOOTIF}" ]
11 then
12 # pxelinux sets BOOTIF to a value based on the mac address of the
13 # network card used to PXE boot, so use this value for DEVICE rather
14 # than a hard-coded device name from initramfs.conf. this facilitates
15 # network booting when machines may have multiple network cards.
16 # pxelinux sets BOOTIF to 01-$mac_address
18 # strip off the leading "01-", which isn't part of the mac
19 # address
20 temp_mac=${BOOTIF#*-}
22 # convert to typical mac address format by replacing "-" with ":"
23 bootif_mac=""
24 IFS='-'
25 for x in $temp_mac
27 if [ -z "$bootif_mac" ]
28 then
29 bootif_mac="$x"
30 else
31 bootif_mac="$bootif_mac:$x"
33 done
34 unset IFS
36 # look for devices with matching mac address, and set DEVICE to
37 # appropriate value if match is found.
39 for device in /sys/class/net/*
41 if [ -f "$device/address" ]
42 then
43 current_mac=$(cat "$device/address")
45 if [ "$bootif_mac" = "$current_mac" ]
46 then
47 DEVICE=${device##*/}
48 break
51 done
55 do_netsetup ()
57 modprobe -q af_packet # For DHCP
59 udevadm trigger
60 udevadm settle
62 [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
63 echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
65 if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
66 then
67 # See if we can select the device from BOOTIF
68 Device_from_bootif
70 # if ethdevice was not specified on the kernel command line
71 # make sure we try to get a working network configuration
72 # for *every* present network device (except for loopback of course)
73 if [ -z "$ETHDEVICE" ]
74 then
75 echo "If you want to boot from a specific device use bootoption ethdevice=..."
76 for device in /sys/class/net/*
78 dev=${device##*/}
79 if [ "$dev" != "lo" ]
80 then
81 ETHDEVICE="$ETHDEVICE $dev"
83 done
86 # split args of ethdevice=eth0,eth1 into "eth0 eth1"
87 for device in $(echo $ETHDEVICE | sed 's/,/ /g')
89 devlist="$devlist $device"
90 done
92 # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
93 # an endless loop; if execution fails give it two further tries, that's
94 # why we use '$devlist $devlist $devlist' for the other for loop
95 for dev in $devlist $devlist $devlist
97 echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
98 ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
99 jobid=$!
100 sleep "$ETHDEV_TIMEOUT" ; sleep 1
101 if [ -r /proc/"$jobid"/status ]
102 then
103 echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
104 kill -9 $jobid
107 # if configuration of device worked we should have an assigned
108 # IP address, if so let's use the device as $DEVICE for later usage.
109 # simple and primitive approach which seems to work fine
110 if ifconfig $dev | grep -q 'inet.*addr:'
111 then
112 export DEVICE="$dev"
113 break
115 done
116 else
117 for interface in ${DEVICE}; do
118 ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config
120 [ -e /run/net-${interface}.conf ] && . /run/net-${interface}.conf
122 if [ "$IPV4ADDR" != "0.0.0.0" ]
123 then
124 break
126 done
129 for interface in ${DEVICE}
131 # source relevant ipconfig output
132 OLDHOSTNAME=${HOSTNAME}
134 [ -e /run/net-${interface}.conf ] && . /run/net-${interface}.conf
136 [ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
137 export HOSTNAME
139 if [ -n "${interface}" ]
140 then
141 HWADDR="$(cat /sys/class/net/${interface}/address)"
144 if [ ! -e "/etc/resolv.conf" ]
145 then
146 echo "Creating /etc/resolv.conf"
148 if [ -n "${DNSDOMAIN}" ]
149 then
150 echo "domain ${DNSDOMAIN}" > /etc/resolv.conf
151 echo "search ${DNSDOMAIN}" >> /etc/resolv.conf
154 for i in ${IPV4DNS0} ${IPV4DNS1} ${IPV4DNS1}
156 if [ -n "$i" ] && [ "$i" != 0.0.0.0 ]
157 then
158 echo "nameserver $i" >> /etc/resolv.conf
160 done
163 # Check if we have a network device at all
164 if ! ls /sys/class/net/"$interface" > /dev/null 2>&1 && \
165 ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
166 ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
167 ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
168 ! ls /sys/class/net/ra0 > /dev/null 2>&1
169 then
170 panic "No supported network device found, maybe a non-mainline driver is required."
172 done