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