add debnet [Closes: issue374]
authorChristian Hofstaedtler <ch@grml.org>
Mon, 6 Dec 2010 22:12:33 +0000 (23:12 +0100)
committerChristian Hofstaedtler <ch@grml.org>
Mon, 6 Dec 2010 22:12:50 +0000 (23:12 +0100)
Moved from grml-autoconfig.

debian/control
sbin/debnet [new file with mode: 0755]

index 37c3ea1..054b90e 100644 (file)
@@ -18,6 +18,7 @@ Description: network related helper scripts
  This package provides scripts for network related
  tasks which should make life easier. Like:
  .
+  * debnet: scans harddisks for Debian-style network config
   * grml-ap: set up your box as access point
   * grml-bridge: set up your box as bridge
   * grml-network: interface for several network related tasks
diff --git a/sbin/debnet b/sbin/debnet
new file mode 100755 (executable)
index 0000000..36376f9
--- /dev/null
@@ -0,0 +1,57 @@
+#!/bin/sh -e
+# Filename:      debnet
+# Purpose:       scan for Debian-style network configs and enables it on the system
+# Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
+# Bug-Reports:   see http://grml.org/bugs/
+# License:       This file is licensed under the GPL v2.
+################################################################################
+
+. /etc/grml/lsb-functions
+
+if [ "$1" = "-h" -o "$1" = "--help" ] ; then
+   echo "Usage: debnet"
+   echo "Looks for /etc/network/interfaces on all volumes and uses it to"
+   echo "configure the running system."
+   echo "WARNING: The networking subsystem will be restarted."
+   exit 0
+fi
+
+DEVICES="$(< /proc/partitions tail -n +3 | awk '{print "/dev/"$4}' | tr "\n" " ")"
+DEVICES="$DEVICES $(ls /dev/mapper/*)"
+FOUND_DEBNET=""
+
+eindent
+if ! mount | grep '/mnt ' >/dev/null 2>&1 ; then
+   for i in $DEVICES; do
+    if mount -o ro -t auto "$i" /mnt >/dev/null 2>&1; then
+        einfo "Scanning on $i"
+      if [ -f /mnt/etc/network/interfaces ]; then
+        einfo "/etc/network/interfaces found on ${i}" ; eend 0
+        FOUND_DEBNET="$i"
+        break
+      fi
+      umount /mnt
+    fi
+   done
+
+  if [ -n "$FOUND_DEBNET" ]; then
+    einfo "Stopping network."
+      pump -k >/dev/null 2>&1
+      /etc/init.d/networking stop >/dev/null 2>&1 ; eend $?
+    einfo "Copying Debian network configuration from $FOUND_DEBNET to running system."
+      rm -rf /etc/network/run
+      cp -a /mnt/etc/network /etc
+      rm -rf /etc/network/run
+      mkdir /etc/network/run
+      umount /mnt ; eend $?
+    einfo "Starting network."
+      invoke-rc.d networking start ; eend $?
+  else
+    eerror "/etc/network/interfaces not found." ; eend 1
+  fi
+  eoutdent
+else
+ eerror "Error: /mnt already mounted." ; eend 1
+fi
+
+# EOF