Refresh debian/patches/07_support_findiso.dpatch.
[live-initramfs-grml.git] / debian / patches / 10_support_ethdevice.dpatch
1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## 10_support_ethdevice.dpatch by <mika@grml.org>
3 ##
4 ## All lines beginning with `## DP:' are a description of the patch.
5 ## DP: Support bootoptions ethdevice and ethdevice-timeout for
6 ## DP: specifying from which device you want to boot from and
7 ## DP: using which timeout (being 30 seconds if unconfigured), if
8 ## DP: ethdevice is not specified try to get a working network
9 ## DP: configuration for each existing network device.
10
11 @DPATCH@
12 diff -urNad live-initramfs-grml~/scripts/live live-initramfs-grml/scripts/live
13 --- live-initramfs-grml~/scripts/live   2009-12-29 22:00:53.858638095 +0100
14 +++ live-initramfs-grml/scripts/live    2009-12-29 22:04:16.588656569 +0100
15 @@ -66,6 +66,16 @@
16                                 set -x
17                                 ;;
18  
19 +                       ethdevice=*)
20 +                               ETHDEVICE="${ARGUMENT#ethdevice=}"
21 +                               export ETHDEVICE
22 +                               ;;
23 +
24 +                       ethdevice-timeout=*)
25 +                               ETHDEV_TIMEOUT="${ARGUMENT#ethdevice-timeout=}"
26 +                               export ETHDEV_TIMEOUT
27 +                               ;;
28 +
29                         fetch=*)
30                                  FETCH="${ARGUMENT#fetch=}"
31                                  export FETCH
32 @@ -739,7 +749,48 @@
33                 udevsettle
34         fi
35  
36 -       ipconfig ${DEVICE} | tee /netboot.config
37 +       # if ethdevice was not specified on the kernel command line
38 +       # make sure we try to get a working network configuration
39 +       # for *every* present network device (except for loopback of course)
40 +       if [ -z "$ETHDEVICE" ] ; then
41 +               echo "If you want to boot from a specific device use bootoption ethdevice=..."
42 +               for device in /sys/class/net/*; do
43 +                       dev=${device##*/} ;
44 +                       if [ "$dev" != "lo" ] ; then
45 +                               ETHDEVICE="$ETHDEVICE $dev"
46 +                       fi
47 +               done
48 +       fi
49 +
50 +       # split args of ethdevice=eth0,eth1 into "eth0 eth1"
51 +       for device in $(echo $ETHDEVICE | sed 's/,/ /g') ; do
52 +               devlist="$devlist $device"
53 +       done
54 +
55 +       [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
56 +       echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
57 +
58 +       # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
59 +       # an endless loop; iff execution fails give it two further tries, that's
60 +       # why we use '$devlist $devlist $devlist' for the other for loop
61 +       for dev in $devlist $devlist $devlist ; do
62 +               echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
63 +               ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
64 +               jobid=$!
65 +               sleep "$ETHDEV_TIMEOUT" ; sleep 1
66 +               if [ -r /proc/"$jobid"/status ] ; then
67 +                       echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
68 +                       kill -9 $jobid
69 +               fi
70 +
71 +               # if configuration of device worked we should have an assigned
72 +               # IP address, iff so let's use the according as $DEVICE for later usage
73 +               # simple and primitive approach which seems to work fine
74 +               if ifconfig $dev | grep -q 'inet.*addr:' ; then
75 +                       export DEVICE="$dev"
76 +                       break
77 +               fi
78 +       done
79  
80         # source relevant ipconfig output
81         OLDHOSTNAME=${HOSTNAME}
82 @@ -748,7 +799,8 @@
83         export HOSTNAME
84  
85         # Check if we have a network device at all
86 -       if ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
87 +       if ! ls /sys/class/net/"$DEVICE" > /dev/null 2>&1 && \
88 +          ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
89            ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
90            ! ls /sys/class/net/ath0 > /dev/null 2>&1 && \
91            ! ls /sys/class/net/ra0 > /dev/null 2>&1