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