Ship our own networking script
authorChristian Hofstaedtler <ch@grml.org>
Fri, 26 Jun 2015 12:49:43 +0000 (14:49 +0200)
committerEvgeni Golov <evgeni@debian.org>
Fri, 26 Jun 2015 12:51:32 +0000 (14:51 +0200)
which is compatible with the kernel's notion of ip= as well as resolvconf.

components/9990-cmdline-old
components/9990-grml-networking.sh [new file with mode: 0644]
components/9990-main.sh

index cccd8f2..2f566bb 100755 (executable)
@@ -33,6 +33,8 @@ Cmdline_old ()
                        nodhcp)
                                DHCP=""
                                export DHCP
                        nodhcp)
                                DHCP=""
                                export DHCP
+                               NODHCP="Yes"
+                               export NODHCP
                                ;;
 
                        ethdevice=*)
                                ;;
 
                        ethdevice=*)
@@ -150,6 +152,11 @@ Cmdline_old ()
                                export NFS_COW
                                ;;
 
                                export NFS_COW
                                ;;
 
+                       nodhcphostname)
+                               NODHCPHOSTNAME="Yes"
+                               export NODHCPHOSTNAME
+                               ;;
+
                        nofstab)
                                NOFSTAB="true"
                                export NOFSTAB
                        nofstab)
                                NOFSTAB="true"
                                export NOFSTAB
diff --git a/components/9990-grml-networking.sh b/components/9990-grml-networking.sh
new file mode 100644 (file)
index 0000000..f4031cd
--- /dev/null
@@ -0,0 +1,120 @@
+#!/bin/sh
+
+#set -e
+
+Grml_Networking () {
+
+if [ -n "${NONETWORKING}" ]; then
+   return 0
+fi
+
+modprobe af_packet # req'd for DHCP
+
+# initialize udev
+# (this /might/ be required for firmware loading to complete)
+if grep -q noudev /proc/cmdline; then
+   log_begin_msg "Networking: Skipping udev as requested via bootoption noudev."
+else
+   udevadm trigger
+   udevadm settle
+fi
+
+if [ -n "${IP}" ]; then
+   # call into initramfs-tools provided network setup functions, so basic
+   # networking is fine.
+   log_begin_msg "Networking: Waiting for basic network to come up..."
+   configure_networking
+fi
+
+# prepare a new /etc/network/interfaces file (and, possibly, a new /etc/resolv.conf)
+IFFILE="/root/etc/network/interfaces"
+if [ -L /root/etc/resolv.conf ] ; then
+  # assume we have resolvconf
+  RESOLVCONF=/root/etc/resolvconf/resolv.conf.d/base
+else
+  RESOLVCONF="/root/etc/resolv.conf"
+fi
+
+# config for loopback networking
+cat > $IFFILE << EOF
+# Initially generated on boot by initramfs' 23networking.
+
+auto lo
+iface lo inet loopback
+
+EOF
+
+unset HOSTNAME
+
+# generate config for each present network device
+for interface in /sys/class/net/eth* /sys/class/net/ath* /sys/class/net/wlan*; do
+    [ -e ${interface} ] || continue
+    interface=$(basename ${interface})
+    method="dhcp"
+
+    # NODHCP or a previously run ipconfig mean that ifupdown should never
+    # touch this interface (IP-stack wise).
+    netconfig=/run/net-${interface}.conf
+    if [ -n "$NODHCP" ] || [ -e "${netconfig}" ]; then
+        method="manual"
+    fi
+
+    # if boot option "nodhcp" is set but also boot option "dhcp" is
+    # set, then dhcp should win over it as we default to dhcp and if
+    # nodhcp is used as default boot option but "dhcp" is added then it
+    # would be confusing to not get a working network setup
+    if [ "$DHCP" = "true" ] ; then
+        method="dhcp"
+    fi
+
+    cat >> $IFFILE << EOF
+allow-hotplug ${interface}
+iface ${interface} inet ${method}
+EOF
+
+    # DNS for resolvconf and /etc/resolv.conf
+    if [ -e "${netconfig}" ]; then
+        . "${netconfig}"
+        if [ -n "${DNSDOMAIN}" ]; then
+            echo "    dns-search ${DNSDOMAIN}" >> $IFFILE
+        fi
+        # make sure we don't have any 0.0.0.0 nameservers
+        IPV4DNSLIST=""
+        for IPV4DNS in ${IPV4DNS0} ${IPV4DNS1}; do
+            [ -n "${IPV4DNS}" ] || continue
+            [ "${IPV4DNS}" != "0.0.0.0" ] || continue
+            IPV4DNSLIST="${IPV4DNSLIST}${IPV4DNS} "
+        done
+        if [ -n "${IPV4DNSLIST}" ]; then
+            echo "    dns-nameservers ${IPV4DNSLIST}" >> $IFFILE
+            for IPV4DNS in ${IPV4DNSLIST}; do
+                echo "nameserver ${IPV4DNS}" >> $RESOLVCONF
+            done
+        fi
+    fi
+
+    if [ -z "$NODHCPHOSTNAME" -a -n "$HOSTNAME" ]; then
+        echo $HOSTNAME > /root/etc/hostname
+    fi
+
+    unset DEVICE IPV4ADDR IPV4BROADCAST IPV4NETMASK IPV4GATEWAY IPV4DNS0 IPV4DNS1 HOSTNAME DNSDOMAIN NISDOMAIN ROOTSERVER ROOTPATH filename
+    unset IPV4DNS IPV4DNSLIST
+
+    echo>> $IFFILE
+done
+
+# dns bootoption
+if [ -n "$DNSSERVER1" ]
+then
+       # disable any existing entries
+       if [ -r $RESOLVCONF ]
+       then
+               sed -i 's/nameserver/# nameserver/' $RESOLVCONF
+       fi
+       for i in $DNSSERVER1 $DNSSERVER2
+       do
+               echo "nameserver $i" >> $RESOLVCONF
+       done
+fi
+
+}
index 512c624..3151db0 100755 (executable)
@@ -192,6 +192,8 @@ Live ()
 
        Swap
 
 
        Swap
 
+       Grml_Networking
+
        exec 1>&6 6>&-
        exec 2>&7 7>&-
        kill ${tailpid}
        exec 1>&6 6>&-
        exec 2>&7 7>&-
        kill ${tailpid}