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