b70d687b6f159217a6d0f579dec7cbe42bc3858d
[live-boot-grml.git] / debian / patches / 27_support_static_ip.dpatch
1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## 27_support_staticip.dpatch by  <mru@grml.org>
3 ##
4 ## All lines beginning with `## DP:' are a description of the patch.
5 ## DP: No description.
6
7 @DPATCH@
8 diff --git a/scripts/live b/scripts/live
9 index 5681362..2d09e3f 100755
10 --- a/scripts/live
11 +++ b/scripts/live
12 @@ -91,9 +91,8 @@ Arguments ()
13                                 ;;
14
15                         ethdevice=*)
16 -                               DEVICE="${ARGUMENT#ethdevice=}"
17 -                               ETHDEVICE="${DEVICE}"
18 -                               export DEVICE ETHDEVICE
19 +                               ETHDEVICE="${ARGUMENT#ethdevice=}"
20 +                               export ETHDEVICE
21                                 ;;
22
23                         ethdevice-timeout=*)
24 @@ -150,13 +149,9 @@ Arguments ()
25                                 ;;
26
27                         ip=*)
28 -                               STATICIP="${ARGUMENT#ip=}"
29 -
30 -                               if [ -z "${STATICIP}" ]
31 -                               then
32 -                                       STATICIP="frommedia"
33 -                               fi
34 -
35 +                               # copy complete ip=args into staticip, and
36 +                               # keep multiple uses.
37 +                               STATICIP="${STATICIP} ${ARGUMENT}"
38                                 export STATICIP
39                                 ;;
40
41 @@ -598,6 +593,23 @@ copy_live_to ()
42         return 0
43  }
44
45 +get_ipconfig_para()
46 +{
47 +    if [ $# != 1 ] ; then
48 +        echo "Missin parameter for $0"
49 +        return
50 +    fi
51 +    devname=$1
52 +    for ip in ${STATICIP} ; do
53 +        case $ip in
54 +            *:$devname:*)
55 +            echo $ip
56 +            return
57 +            ;;
58 +        esac
59 +    done
60 +    echo $devname
61 +}
62  do_netsetup ()
63  {
64         modprobe -q af_packet # For DHCP
65 @@ -612,6 +624,20 @@ do_netsetup ()
66            [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
67         then
68
69 +       # Our modus operandi for getting a working network setup is this:
70 +       # * If ip=* is set, pass that to ipconfig and be done
71 +       # * Else, try dhcp on all devices in this order:
72 +       #   ethdevice= bootif= <all interfaces>
73 +
74 +       ALLDEVICES="$(cd /sys/class/net/ && ls -1 2>/dev/null | grep -v '^lo$' )"
75 +
76 +       # Turn on all interfaces before doing anything, to avoid timing problems
77 +       # during link negotiation.
78 +       echo "Net: Turning on all device links..."
79 +       for device in ${ALLDEVICES}; do
80 +               ipconfig -c none -d $device -t 1 2>/dev/null >/dev/null
81 +       done
82 +
83
84         # support for Syslinux IPAPPEND parameter
85         # it sets the BOOTIF variable on the kernel parameter
86 @@ -653,7 +679,7 @@ do_netsetup ()
87
88                                 if [ "$bootif_mac" = "$current_mac" ]
89                                 then
90 -                                       DEVICE=${device##*/}
91 +                                       ETHDEVICE="${device##*/},$ETHDEVICE" # use ethdevice
92                                         break
93                                 fi
94                         fi
95 @@ -678,37 +704,22 @@ do_netsetup ()
96                 devlist="$devlist $device"
97         done
98
99 -       # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
100 -       # an endless loop; iff execution fails give it two further tries, that's
101 -       # why we use '$devlist $devlist $devlist' for the other for loop
102 -       for dev in $devlist $devlist $devlist ; do
103 -               echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
104 -               ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
105 -               jobid=$!
106 -               sleep "$ETHDEV_TIMEOUT" ; sleep 1
107 -               if [ -r /proc/"$jobid"/status ] ; then
108 -                       echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
109 -                       kill -9 $jobid
110 -               fi
111 +       for dev in $devlist ; do
112 +               echo "Executing ipconfig -t $ETHDEV_TIMEOUT $(get_ipconfig_para $dev)"
113 +               ipconfig -t "$ETHDEV_TIMEOUT" $(get_ipconfig_para $dev) | tee -a /netboot.config
114
115                 # if configuration of device worked we should have an assigned
116                 # IP address, iff so let's use the according as $DEVICE for later usage
117                 # simple and primitive approach which seems to work fine
118 -               if ifconfig $dev | grep -q 'inet.*addr:' ; then
119 -                       export DEVICE="$dev"
120 -                       break
121 +               IPV4ADDR="0.0.0.0"
122 +               . /tmp/net-${device}.conf
123 +               if [ "${IPV4ADDR}" != "0.0.0.0" ]; then
124 +                       export DEVICE="$dev $DEVICE"
125 +                       # break  # exit loop as we just use the irst
126                 fi
127 +
128         done
129
130 -       else
131 -               for interface in ${DEVICE}; do
132 -                       ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config
133 -                       [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
134 -                       if [ "$IPV4ADDR" != "0.0.0.0" ]
135 -                       then
136 -                               break
137 -                       fi
138 -               done
139         fi
140
141         for interface in ${DEVICE}; do