Fix patch offsets for quilt patches
[live-boot-grml.git] / debian / patches / 27_support_static_ip.patch
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
9 --- a/scripts/live
10 +++ b/scripts/live
11 @@ -110,9 +110,8 @@
12                                 ;;
13  
14                         ethdevice=*)
15 -                               DEVICE="${ARGUMENT#ethdevice=}"
16 -                               ETHDEVICE="${DEVICE}"
17 -                               export DEVICE ETHDEVICE
18 +                               ETHDEVICE="${ARGUMENT#ethdevice=}"
19 +                               export ETHDEVICE
20                                 ;;
21  
22                         ethdevice-timeout=*)
23 @@ -179,13 +178,9 @@
24                                 ;;
25  
26                         ip=*)
27 -                               STATICIP="${ARGUMENT#ip=}"
28 -
29 -                               if [ -z "${STATICIP}" ]
30 -                               then
31 -                                       STATICIP="frommedia"
32 -                               fi
33 -
34 +                               # copy complete ip=args into staticip, and
35 +                               # keep multiple uses.
36 +                               STATICIP="${STATICIP} ${ARGUMENT}"
37                                 export STATICIP
38                                 ;;
39  
40 @@ -667,6 +662,24 @@
41         return 0
42  }
43  
44 +get_ipconfig_para()
45 +{
46 +       if [ $# != 1 ] ; then
47 +               echo "Missin parameter for $0"
48 +               return
49 +       fi
50 +       devname=$1
51 +       for ip in ${STATICIP} ; do
52 +               case $ip in
53 +                       *:$devname:*)
54 +                       echo $ip
55 +                       return
56 +                       ;;
57 +               esac
58 +       done
59 +       echo $devname
60 +}
61 +
62  do_netsetup ()
63  {
64         modprobe -q af_packet # For DHCP
65 @@ -677,9 +690,19 @@
66         [ -n "$ETHDEV_TIMEOUT" ] || ETHDEV_TIMEOUT=15
67         echo "Using timeout of $ETHDEV_TIMEOUT seconds for network configuration."
68  
69 -       if [ -z "${NETBOOT}" ] && [ -z "${FETCH}" ] && \
70 -          [ -z "${HTTPFS}" ] && [ -z "${FTPFS}" ]
71 -       then
72 +       # Our modus operandi for getting a working network setup is this:
73 +       # * If ip=* is set, pass that to ipconfig and be done
74 +       # * Else, try dhcp on all devices in this order:
75 +       #   ethdevice= bootif= <all interfaces>
76 +
77 +       ALLDEVICES="$(cd /sys/class/net/ && ls -1 2>/dev/null | grep -v '^lo$' )"
78 +
79 +       # Turn on all interfaces before doing anything, to avoid timing problems
80 +       # during link negotiation.
81 +       echo "Net: Turning on all device links..."
82 +       for device in ${ALLDEVICES}; do
83 +               ipconfig -c none -d $device -t 1 2>/dev/null >/dev/null
84 +       done
85  
86  
87         # support for Syslinux IPAPPEND parameter
88 @@ -722,7 +745,7 @@
89  
90                                 if [ "$bootif_mac" = "$current_mac" ]
91                                 then
92 -                                       DEVICE=${device##*/}
93 +                                       ETHDEVICE="${device##*/},$ETHDEVICE" # use ethdevice
94                                         break
95                                 fi
96                         fi
97 @@ -734,12 +757,7 @@
98         # for *every* present network device (except for loopback of course)
99         if [ -z "$ETHDEVICE" ] ; then
100                 echo "If you want to boot from a specific device use bootoption ethdevice=..."
101 -               for device in /sys/class/net/*; do
102 -                       dev=${device##*/} ;
103 -                       if [ "$dev" != "lo" ] ; then
104 -                               ETHDEVICE="$ETHDEVICE $dev"
105 -                       fi
106 -               done
107 +        ETHDEVICE="$ALLDEVICES"
108         fi
109  
110         # split args of ethdevice=eth0,eth1 into "eth0 eth1"
111 @@ -747,38 +765,27 @@
112                 devlist="$devlist $device"
113         done
114  
115 -       # this is tricky (and ugly) because ipconfig sometimes just hangs/runs into
116 -       # an endless loop; iff execution fails give it two further tries, that's
117 -       # why we use '$devlist $devlist $devlist' for the other for loop
118 -       for dev in $devlist $devlist $devlist ; do
119 -               echo "Executing ipconfig -t $ETHDEV_TIMEOUT $dev"
120 -               ipconfig -t "$ETHDEV_TIMEOUT" $dev | tee -a /netboot.config &
121 -               jobid=$!
122 -               sleep "$ETHDEV_TIMEOUT" ; sleep 1
123 -               if [ -r /proc/"$jobid"/status ] ; then
124 -                       echo "Killing job $jobid for device $dev as ipconfig ran into recursion..."
125 -                       kill -9 $jobid
126 +       for dev in $devlist ; do
127 +               param="$(get_ipconfig_para $dev)"
128 +               if [ -n "$NODHCP" ] && [ "$param" = "$dev" ] ; then
129 +                       echo "Ignoring network device $dev due to nodhcp." | tee -a /live-boot.log
130 +                       continue
131                 fi
132 +               echo "Executing ipconfig -t $ETHDEV_TIMEOUT $param"
133 +               ipconfig -t "$ETHDEV_TIMEOUT" "$param" | tee -a /netboot.config
134  
135                 # if configuration of device worked we should have an assigned
136                 # IP address, iff so let's use the according as $DEVICE for later usage
137                 # simple and primitive approach which seems to work fine
138 -               if ifconfig $dev | grep -q 'inet.*addr:' ; then
139 -                       export DEVICE="$dev"
140 -                       break
141 +               IPV4ADDR="0.0.0.0"
142 +               . /tmp/net-${device}.conf
143 +               if [ "${IPV4ADDR}" != "0.0.0.0" ]; then
144 +                       export DEVICE="$dev $DEVICE"
145 +                       # break  # exit loop as we just use the irst
146                 fi
147 -       done
148  
149 -       else
150 -               for interface in ${DEVICE}; do
151 -                       ipconfig -t "$ETHDEV_TIMEOUT" ${interface} | tee /netboot-${interface}.config
152 -                       [ -e /tmp/net-${interface}.conf ] && . /tmp/net-${interface}.conf
153 -                       if [ "$IPV4ADDR" != "0.0.0.0" ]
154 -                       then
155 -                               break
156 -                       fi
157 -               done
158 -       fi
159 +       done
160 +       unset devlist
161  
162         for interface in ${DEVICE}; do
163                 # source relevant ipconfig output