debnet: drop pump command line (as pump isn't shipped any longer)
[grml-network.git] / sbin / debnet
1 #!/bin/sh -e
2 # Filename:      debnet
3 # Purpose:       scan for Debian-style network configs and enable it on the system
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under GPL v2+.
7 ################################################################################
8
9 . /etc/grml/lsb-functions
10
11 if [ "$1" = "-h" -o "$1" = "--help" ] ; then
12    echo "Usage: debnet"
13    echo "Looks for /etc/network/interfaces on all volumes and uses it to"
14    echo "configure the running system."
15    echo "WARNING: The networking subsystem will be restarted."
16    exit 0
17 fi
18
19 DEVICES="$(< /proc/partitions tail -n +3 | awk '($4 !~ /loop[0-9]+/) {print "/dev/"$4}' | tr "\n" " ")"
20 DEVICES="$DEVICES $(ls /dev/mapper/*)"
21 FOUND_DEBNET=""
22
23 eindent
24 if ! mount | grep '/mnt ' >/dev/null 2>&1 ; then
25   for i in $DEVICES; do
26    if mount -o ro -t auto "$i" /mnt >/dev/null 2>&1; then
27      einfo "Scanning on $i"
28        if [ -f /mnt/etc/network/interfaces ]; then
29          einfo "/etc/network/interfaces found on ${i}" ; eend 0
30          FOUND_DEBNET="$i"
31          break
32        fi
33      umount /mnt
34    fi
35   done
36
37   if [ -n "$FOUND_DEBNET" ]; then
38     einfo "Stopping network."
39       /etc/init.d/networking stop >/dev/null 2>&1 ; eend $?
40     einfo "Copying Debian network configuration from $FOUND_DEBNET to running system."
41       rm -rf /etc/network/run
42       cp -a /mnt/etc/network /etc
43       rm -rf /etc/network/run
44       mkdir /etc/network/run
45       umount /mnt ; eend $?
46     einfo "Starting network."
47       invoke-rc.d networking start ; eend $?
48   else
49     eerror "/etc/network/interfaces not found on external partitions." ; eend 1
50   fi
51   eoutdent
52 else
53  eerror "Error: /mnt already mounted." ; eend 1
54 fi
55
56 # EOF