Adding debian version 2.0~a1-1.
[live-boot-grml.git] / scripts / live-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" ] &&
34    [ "$NETBOOT" = "" ] &&
35    [ "$FETCH" = "" ] &&
36    [ "$FTPFS" = "" ] &&
37    [ "$HTTPFS" = "" ]
38 then
39     # Not a net boot : nothing to do
40     exit 0
41 fi
42
43 # we want to do some basic IP
44 modprobe -q af_packet
45
46 # Available Ethernet interfaces ?
47 l_interfaces=""
48 echo "Waiting for ethernet card(s) up... If this fails, maybe the ethernet card is not supported by the kernel `uname -r`?"
49 while [ -z "$l_interfaces" ]; do
50   l_interfaces="$(cd /sys/class/net/ && ls -d eth* 2>/dev/null)"
51 done
52
53 if [ $(echo $l_interfaces | wc -w) -lt 2 ]; then
54         # only one interface : no choice
55         echo "DEVICE=$l_interfaces" >> /conf/param.conf
56         exit 0
57 fi
58
59 # If user force to use specific device, write it
60 for ARGUMENT in $(cat /proc/cmdline); do
61     case "${ARGUMENT}" in
62         live-netdev=*)
63         NETDEV="${ARGUMENT#live-netdev=}"
64         echo "DEVICE=$NETDEV" >> /conf/param.conf
65         echo "Found live-netdev parameter in /proc/cmdline. Force to use network device $NETDEV."
66         exit 0
67         ;;
68     esac
69 done
70
71 while true; do
72         echo -n "Looking for a connected Ethernet interface ..."
73
74         for interface in $l_interfaces; do
75                 # ATTR{carrier} is not set if this is not done
76                 echo -n " $interface ?"
77                 ipconfig -c none -d $interface -t 1 >/dev/null 2>&1
78         done
79
80         echo ''
81
82         for step in 1 2 3 4 5; do
83                 for interface in $l_interfaces; do
84                         carrier=$(cat /sys/class/net/$interface/carrier \
85                                 2>/dev/null)
86                         # link detected
87                         if [ "$carrier" = 1 ]; then
88                                 echo " found $interface."
89                                 # inform initrd's init script :
90                                 echo "DEVICE=$interface" >> /conf/param.conf
91                                 exit 0
92                         fi
93                 done
94                 # wait a bit
95                 sleep 1
96         done
97 done