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