Removing etch compatibility.
[live-boot-grml.git] / scripts / init-premount / select_eth_device
1 #!/bin/sh
2
3 # Original script by Andreas Teuchert <ant+dl@hsg-kl.de>
4 # Modified by Frédéric Boiteux <fboiteux@calistel.com>
5
6 PREREQ="blacklist udev"
7
8 prereqs()
9 {
10         echo "$PREREQ"
11 }
12
13 case $1 in
14 # get pre-requisites
15 prereqs)
16         prereqs
17         exit 0
18         ;;
19 esac
20
21 # Boot type in initramfs's config
22 bootconf=$(egrep '^BOOT=' /conf/initramfs.conf | tail -1)
23
24 # can be superseded by command line (used by Debian-Live's netboot for example)
25 for ARGUMENT in $(cat /proc/cmdline); do
26         case "${ARGUMENT}" in
27                 netboot=*)
28                         NETBOOT="${ARGUMENT#netboot=}"
29                         ;;
30         esac
31 done
32
33 if [ "$bootconf" != "BOOT=nfs" ] && [ "$NETBOOT" = "" ]; then
34         # Not a net boot : nothing to do
35         exit 0
36 fi
37
38 # be sure this has been run (*should* be done by scripts/init-premount/udev)
39 udevadm trigger
40 udevadm settle
41
42 # we want to do some basic IP
43 modprobe -q af_packet
44
45 # Available Ethernet interfaces ?
46 l_interfaces=$(cd /sys/class/net/ && ls -d eth* 2>/dev/null)
47
48 if [ $(echo $l_interfaces | wc -w) -lt 2 ]; then
49         # only one interface : no choice
50         echo "DEVICE=$l_interfaces" >> /conf/param.conf
51         exit 0
52 fi
53
54 while true; do
55         echo -n "Looking for a connected Ethernet interface ..."
56
57         for interface in $l_interfaces; do
58                 # ATTR{carrier} is not set if this is not done
59                 echo -n " $interface ?"
60                 ipconfig -c none -d $interface -t 1 >/dev/null 2>&1
61         done
62
63         echo ''
64
65         for step in 1 2 3 4 5; do
66                 for interface in $l_interfaces; do
67                         carrier=$(cat /sys/class/net/$interface/carrier \
68                                 2>/dev/null)
69                         # link detected
70                         if [ "$carrier" = 1 ]; then
71                                 echo " found $interface."
72                                 # inform initrd's init script :
73                                 echo "DEVICE=$interface" >> /conf/param.conf
74                                 exit 0
75                         fi
76                 done
77                 # wait a bit
78                 sleep 1
79         done
80 done