backport Allow-selecting-boot-eth-dev-by-MAC-address.patch from upstream
[live-boot-grml.git] / debian / patches / 0001-Allow-selecting-boot-eth-dev-by-MAC-address.patch
1 From e951deaaeeb2b7badc5a6f53c6af18c1504289ee Mon Sep 17 00:00:00 2001
2 From: Riccardo Murri <riccardo.murri@gmail.com>
3 Date: Fri, 19 Jun 2015 17:50:52 +0200
4 Subject: [PATCH] Allow selecting boot eth dev by MAC address
5
6 ---
7  components/9990-select-eth-device.sh | 101 +++++++++++++++++++++--------------
8  1 file changed, 61 insertions(+), 40 deletions(-)
9
10 diff --git a/components/9990-select-eth-device.sh b/components/9990-select-eth-device.sh
11 index df00666..6bc67fd 100755
12 --- a/components/9990-select-eth-device.sh
13 +++ b/components/9990-select-eth-device.sh
14 @@ -49,21 +49,32 @@ Select_eth_device ()
15                         return
16                 fi
17  
18 -               # If user force to use specific device, write it
19 -               for ARGUMENT in ${LIVE_BOOT_CMDLINE}
20 -               do
21 -                       case "${ARGUMENT}" in
22 -                               live-netdev=*)
23 -                               NETDEV="${ARGUMENT#live-netdev=}"
24 -                               echo "DEVICE=$NETDEV" >> /conf/param.conf
25 -                               echo "Found live-netdev parameter, forcing to to use network device $NETDEV."
26 -                               return
27 -                               ;;
28 -                       esac
29 -               done
30 -       else
31 -               l_interfaces="$DEVICE"
32 -       fi
33 +                # If user force to use specific device, write it
34 +                for ARGUMENT in ${LIVE_BOOT_CMDLINE}
35 +                do
36 +                        case "${ARGUMENT}" in
37 +                                live-netdev=*)
38 +                                NETDEV="${ARGUMENT#live-netdev=}"
39 +                                # net device could be specified by MAC address
40 +                                hex="[0-9A-Fa-f][0-9A-Fa-f]"
41 +                                case "${NETDEV}" in
42 +                                    ${hex}:${hex}:${hex}:${hex}:${hex}:${hex})
43 +                                        # MAC address; record it and select later
44 +                                        netdev_mac_addr="${NETDEV}"
45 +                                        ;;
46 +                                    *)
47 +                                        # interface name
48 +                                        echo "DEVICE=$NETDEV" >> /conf/param.conf
49 +                                        echo "Found live-netdev parameter, forcing to to use network device $NETDEV."
50 +                                        return
51 +                                        ;;
52 +                                esac
53 +                                ;;
54 +                        esac
55 +                done
56 +        else
57 +                l_interfaces="$DEVICE"
58 +        fi
59  
60         found_eth_dev=""
61         while true
62 @@ -79,30 +90,40 @@ Select_eth_device ()
63  
64                 echo ''
65  
66 -               for step in 1 2 3 4 5
67 -               do
68 -                       for interface in $l_interfaces
69 -                       do
70 -                               carrier=$(cat /sys/class/net/$interface/carrier \
71 -                                       2>/dev/null)
72 -                               # link detected
73 +                for step in 1 2 3 4 5
74 +                do
75 +                        for interface in $l_interfaces
76 +                        do
77 +                            if [ -z "$netdev_mac_addr" ]; then
78 +                                carrier=$(cat /sys/class/net/$interface/carrier \
79 +                                        2>/dev/null)
80 +                                # link detected
81  
82 -                               case "${carrier}" in
83 -                                       1)
84 -                                               echo "Connected $interface found"
85 -                                               # inform initrd's init script :
86 -                                               found_eth_dev="$found_eth_dev $interface"
87 -                                               ;;
88 -                               esac
89 -                       done
90 -                       if [ -n "$found_eth_dev" ]
91 -                       then
92 -                               echo "DEVICE='$found_eth_dev'" >> /conf/param.conf
93 -                               return
94 -                       else
95 -                               # wait a bit
96 -                               sleep 1
97 -                       fi
98 -               done
99 -       done
100 +                                case "${carrier}" in
101 +                                        1)
102 +                                                echo "Connected $interface found"
103 +                                                # inform initrd's init script :
104 +                                                found_eth_dev="$found_eth_dev $interface"
105 +                                                ;;
106 +                                esac
107 +                            else
108 +                                # MAC addr given, check for that
109 +                                mac_addr=$(ifconfig "$interface" \
110 +                                                  | grep HWaddr \
111 +                                                  | { read _ _ _ _ mac_addr; echo $mac_addr; })
112 +                                if [ "$mac_addr" = "$netdev_mac_addr" ]; then
113 +                                    found_eth_dev="$interface"
114 +                                fi
115 +                            fi
116 +                        done
117 +                        if [ -n "$found_eth_dev" ]
118 +                        then
119 +                                echo "DEVICE='$found_eth_dev'" >> /conf/param.conf
120 +                                return
121 +                        else
122 +                                # wait a bit
123 +                                sleep 1
124 +                        fi
125 +                done
126 +        done
127  }
128 -- 
129 2.5.0
130