510f84ae21679bcd3c60224b05f9839de9d11d46
[live-boot-grml.git] / debian / patches / 15_networking_grml.patch
1 #! /bin/sh /usr/share/dpatch/dpatch-run
2 ## 15_networking_grml.dpatch by Christian Hofstaedtler <ch@grml.org>
3 ## Licensed under GPLv2+.
4 ##
5 ## All lines beginning with `## DP:' are a description of the patch.
6 ## DP: Ship our own networking script, which is compatible with the kernel's
7 ## DP: notion of ip= as well as resolvconf.
8
9 @DPATCH@
10
11 diff a/scripts/live-bottom/23networking_grml b/scripts/live-bottom/23networking_grml
12 Index: live-boot-grml/components/9990-grml-networking.sh
13 ===================================================================
14 --- /dev/null   1970-01-01 00:00:00.000000000 +0000
15 +++ live-boot-grml/components/9990-grml-networking.sh   2014-03-08 16:34:29.800254396 +0100
16 @@ -0,0 +1,120 @@
17 +#!/bin/sh
18 +
19 +#set -e
20 +
21 +Grml_Networking () {
22 +
23 +if [ -n "${NONETWORKING}" ]; then
24 +   return 0
25 +fi
26 +
27 +modprobe af_packet # req'd for DHCP
28 +
29 +# initialize udev
30 +# (this /might/ be required for firmware loading to complete)
31 +if grep -q noudev /proc/cmdline; then
32 +   log_begin_msg "Networking: Skipping udev as requested via bootoption noudev."
33 +else
34 +   udevadm trigger
35 +   udevadm settle
36 +fi
37 +
38 +if [ -n "${IP}" ]; then
39 +   # call into initramfs-tools provided network setup functions, so basic
40 +   # networking is fine.
41 +   log_begin_msg "Networking: Waiting for basic network to come up..."
42 +   configure_networking
43 +fi
44 +
45 +# prepare a new /etc/network/interfaces file (and, possibly, a new /etc/resolv.conf)
46 +IFFILE="/root/etc/network/interfaces"
47 +if [ -L /root/etc/resolv.conf ] ; then
48 +  # assume we have resolvconf
49 +  RESOLVCONF=/root/etc/resolvconf/resolv.conf.d/base
50 +else
51 +  RESOLVCONF="/root/etc/resolv.conf"
52 +fi
53 +
54 +# config for loopback networking
55 +cat > $IFFILE << EOF
56 +# Initially generated on boot by initramfs' 23networking.
57 +
58 +auto lo
59 +iface lo inet loopback
60 +
61 +EOF
62 +
63 +unset HOSTNAME
64 +
65 +# generate config for each present network device
66 +for interface in /sys/class/net/eth* /sys/class/net/ath* /sys/class/net/wlan*; do
67 +    [ -e ${interface} ] || continue
68 +    interface=$(basename ${interface})
69 +    method="dhcp"
70 +
71 +    # NODHCP or a previously run ipconfig mean that ifupdown should never
72 +    # touch this interface (IP-stack wise).
73 +    netconfig=/run/net-${interface}.conf
74 +    if [ -n "$NODHCP" ] || [ -e "${netconfig}" ]; then
75 +        method="manual"
76 +    fi
77 +
78 +    # if boot option "nodhcp" is set but also boot option "dhcp" is
79 +    # set, then dhcp should win over it as we default to dhcp and if
80 +    # nodhcp is used as default boot option but "dhcp" is added then it
81 +    # would be confusing to not get a working network setup
82 +    if [ "$DHCP" = "true" ] ; then
83 +        method="dhcp"
84 +    fi
85 +
86 +    cat >> $IFFILE << EOF
87 +allow-hotplug ${interface}
88 +iface ${interface} inet ${method}
89 +EOF
90 +
91 +    # DNS for resolvconf and /etc/resolv.conf
92 +    if [ -e "${netconfig}" ]; then
93 +        . "${netconfig}"
94 +        if [ -n "${DNSDOMAIN}" ]; then
95 +            echo "    dns-search ${DNSDOMAIN}" >> $IFFILE
96 +        fi
97 +        # make sure we don't have any 0.0.0.0 nameservers
98 +        IPV4DNSLIST=""
99 +        for IPV4DNS in ${IPV4DNS0} ${IPV4DNS1}; do
100 +            [ -n "${IPV4DNS}" ] || continue
101 +            [ "${IPV4DNS}" != "0.0.0.0" ] || continue
102 +            IPV4DNSLIST="${IPV4DNSLIST}${IPV4DNS} "
103 +        done
104 +        if [ -n "${IPV4DNSLIST}" ]; then
105 +            echo "    dns-nameservers ${IPV4DNSLIST}" >> $IFFILE
106 +            for IPV4DNS in ${IPV4DNSLIST}; do
107 +                echo "nameserver ${IPV4DNS}" >> $RESOLVCONF
108 +            done
109 +        fi
110 +    fi
111 +
112 +    if [ -z "$NODHCPHOSTNAME" -a -n "$HOSTNAME" ]; then
113 +        echo $HOSTNAME > /root/etc/hostname
114 +    fi
115 +
116 +    unset DEVICE IPV4ADDR IPV4BROADCAST IPV4NETMASK IPV4GATEWAY IPV4DNS0 IPV4DNS1 HOSTNAME DNSDOMAIN NISDOMAIN ROOTSERVER ROOTPATH filename
117 +    unset IPV4DNS IPV4DNSLIST
118 +
119 +    echo>> $IFFILE
120 +done
121 +
122 +# dns bootoption
123 +if [ -n "$DNSSERVER1" ]
124 +then
125 +       # disable any existing entries
126 +       if [ -r $RESOLVCONF ]
127 +       then
128 +               sed -i 's/nameserver/# nameserver/' $RESOLVCONF
129 +       fi
130 +       for i in $DNSSERVER1 $DNSSERVER2
131 +       do
132 +               echo "nameserver $i" >> $RESOLVCONF
133 +       done
134 +fi
135 +
136 +}
137 Index: live-boot-grml/components/9990-main.sh
138 ===================================================================
139 --- live-boot-grml.orig/components/9990-main.sh 2014-03-08 16:27:40.668243817 +0100
140 +++ live-boot-grml/components/9990-main.sh      2014-03-08 16:27:40.664244286 +0100
141 @@ -195,6 +195,8 @@
142  
143         Swap
144  
145 +       Grml_Networking
146 +
147         case "${UNIONFS}" in
148                 unionfs-fuse)
149                         umount "${rootmnt}/dev"
150 Index: live-boot-grml/components/9990-cmdline-old
151 ===================================================================
152 --- live-boot-grml.orig/components/9990-cmdline-old     2014-03-08 16:27:34.117012248 +0100
153 +++ live-boot-grml/components/9990-cmdline-old  2014-03-08 16:33:20.536378749 +0100
154 @@ -33,6 +33,8 @@
155                         nodhcp)
156                                 DHCP=""
157                                 export DHCP
158 +                               NODHCP="Yes"
159 +                               export NODHCP
160                                 ;;
161  
162                         ethdevice=*)
163 @@ -150,6 +152,11 @@
164                                 export NFS_COW
165                                 ;;
166  
167 +                       nodhcphostname)
168 +                               NODHCPHOSTNAME="Yes"
169 +                               export NODHCPHOSTNAME
170 +                               ;;
171 +
172                         nofstab)
173                                 NOFSTAB="true"
174                                 export NOFSTAB