f8aef45e4a969ef4e0a39d9e91ba82f49aa0463a
[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 --- /dev/null
13 +++ b/scripts/boot/9990-grml-networking.sh
14 @@ -0,0 +1,93 @@
15 +#!/bin/sh
16 +
17 +#set -e
18 +
19 +Grml_Networking () {
20 +
21 +if [ -n "${NONETWORKING}" ]; then
22 +   return 0
23 +fi
24 +
25 +modprobe af_packet # req'd for DHCP
26 +
27 +# initialize udev
28 +# (this /might/ be required for firmware loading to complete)
29 +if grep -q noudev /proc/cmdline; then
30 +   log_begin_msg "Networking: Skipping udev as requested via bootoption noudev."
31 +else
32 +   udevadm trigger
33 +   udevadm settle
34 +fi
35 +
36 +if [ -n "${IP}" ]; then
37 +   # call into initramfs-tools provided network setup functions, so basic
38 +   # networking is fine.
39 +   log_begin_msg "Networking: Waiting for basic network to come up..."
40 +   configure_networking
41 +fi
42 +
43 +# prepare a new /etc/network/interfaces file (and, possibly, a new /etc/resolv.conf)
44 +IFFILE="/root/etc/network/interfaces"
45 +RESOLVCONF="/root/etc/resolv.conf"
46 +
47 +# config for loopback networking
48 +cat > $IFFILE << EOF
49 +# Initially generated on boot by initramfs' 23networking.
50 +
51 +auto lo
52 +iface lo inet loopback
53 +
54 +EOF
55 +
56 +unset HOSTNAME
57 +
58 +# generate config for each present network device
59 +for interface in /sys/class/net/eth* /sys/class/net/ath* /sys/class/net/wlan*; do
60 +    [ -e ${interface} ] || continue
61 +    interface=$(basename ${interface})
62 +    method="dhcp"
63 +
64 +    # NODHCP or a previously run ipconfig mean that ifupdown should never
65 +    # touch this interface (IP-stack wise).
66 +    netconfig=/run/net-${interface}.conf
67 +    if [ -n "$NODHCP" ] || [ -e "${netconfig}" ]; then
68 +        method="manual"
69 +    fi
70 +
71 +    cat >> $IFFILE << EOF
72 +allow-hotplug ${interface}
73 +iface ${interface} inet ${method}
74 +EOF
75 +
76 +    # DNS for resolvconf and /etc/resolv.conf
77 +    if [ -e "${netconfig}" ]; then
78 +        . "${netconfig}"
79 +        if [ -n "${DNSDOMAIN}" ]; then
80 +            echo "    dns-search ${DNSDOMAIN}" >> $IFFILE
81 +        fi
82 +        # make sure we don't have any 0.0.0.0 nameservers
83 +        IPV4DNSLIST=""
84 +        for IPV4DNS in ${IPV4DNS0} ${IPV4DNS1}; do
85 +            [ -n "${IPV4DNS}" ] || continue
86 +            [ "${IPV4DNS}" != "0.0.0.0" ] || continue
87 +            IPV4DNSLIST="${IPV4DNSLIST}${IPV4DNS} "
88 +        done
89 +        if [ -n "${IPV4DNSLIST}" ]; then
90 +            echo "    dns-nameservers ${IPV4DNSLIST}" >> $IFFILE
91 +            for IPV4DNS in ${IPV4DNSLIST}; do
92 +                echo "nameserver ${IPV4DNS}" >> $RESOLVCONF
93 +            done
94 +        fi
95 +    fi
96 +
97 +    if [ -z "$NODHCPHOSTNAME" -a -n "$HOSTNAME" ]; then
98 +        echo $HOSTNAME > /root/etc/hostname
99 +    fi
100 +
101 +    unset DEVICE IPV4ADDR IPV4BROADCAST IPV4NETMASK IPV4GATEWAY IPV4DNS0 IPV4DNS1 HOSTNAME DNSDOMAIN NISDOMAIN ROOTSERVER ROOTPATH filename
102 +    unset IPV4DNS IPV4DNSLIST
103 +
104 +    echo>> $IFFILE
105 +done
106 +
107 +}
108 --- a/scripts/boot/9990-main.sh
109 +++ b/scripts/boot/9990-main.sh
110 @@ -197,6 +197,8 @@
111  
112         Swap
113  
114 +       Grml_Networking
115 +
116         case "${UNIONFS}" in
117                 unionfs-fuse)
118                         umount "${rootmnt}/dev"