source: branches/3.0/mindi/rootfs/sbin/start-netfs @ 3168

Last change on this file since 3168 was 3168, checked in by bruno, 6 years ago
  • Fix #697 by adding the iproute parameter at boot time to support addition of static routes
  • Property svn:executable set to *
File size: 4.9 KB
Line 
1#!/bin/sh
2#
3# $Id$
4#
5# This script sets up the network + Network FS environment if needed.
6#
7
8
9# number of ping
10ipcount=3
11
12# Get info from config file
13ipdev=`grep netfs-dev /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
14hwaddr=`grep netfs-client-hwaddr /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
15ipaddress=`grep netfs-client-ipaddr /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
16ipnetmask=`grep netfs-client-netmask /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
17ipbroadcast=`grep netfs-client-broadcast /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
18ipgateway=`grep netfs-client-defgw /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
19proto=`grep netfs-proto /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
20iptoute=`grep netfs-route /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
21ipconf=""
22pre=""
23post=""
24export netfsmount=`grep netfs-server-mount /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
25export imgname=`grep iso-prefix /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
26if [ "$imgname" = "" ]; then
27    export imgname="mondorescue"
28fi
29export dirimg=`grep netfs-server-path /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
30if [ "$dirimg" = "" ]; then
31    export dirimg="/"
32fi
33
34# info from cmdline are predominent
35for i in `cat /proc/cmdline` ; do
36    echo $i | grep -qi ping= && ipcount=`echo $i | cut -d= -f2`
37    echo $i | grep -qi hwaddr= && hwaddr=`echo $i | cut -d= -f2`
38    echo $i | grep -qi ipconf= && ipconf=`echo $i | cut -d= -f2`
39    echo $i | grep -qi netfsmount= && export netfsmount=`echo $i | cut -d= -f2`
40    echo $i | grep -qi netfsopt= && export netfsopt=`echo $i | cut -d= -f2`
41    echo $i | grep -qi prefix= && export imgname=`echo $i | cut -d= -f2`
42    echo $i | grep -qi netfspath= && export dirimg=`echo $i | cut -d= -f2`
43    echo $i | grep -qi pre= && pre=`echo $i | cut -d= -f2`
44    echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
45    echo $i | grep -qi proto= && proto=`echo $i | cut -d= -f2`
46    echo $i | grep -qi iproute= && iproute=`echo $i | cut -d= -f2`
47done
48
49if [ "$ipdev" != "" ] || [ "$ipconf" != "" ]; then
50    # Network configuration stored during archive
51    # or on cmdline so network wanted => starting it
52    LogIt "Starting Network..."
53
54    # Activate loobback
55    ifconfig lo 127.0.0.1
56
57    echo "$ipconf" | grep -q "dhcp"
58    if [ $? -eq 0 ]; then
59        ipdev=`echo $ipconf | cut -d: -f1`
60        LogIt "Making DHCP request on $ipdev"
61        udhcpc -i $ipdev
62    else
63        if [ "$ipconf" != "" ]; then
64            ipdev=`echo $ipconf | cut -d: -f1`
65            ipaddress=`echo $ipconf | cut -d: -f2`
66            ipnetmask=`echo $ipconf | cut -d: -f3`
67            ipbroadcast=`echo $ipconf | cut -d: -f4`
68            ipgateway=`echo $ipconf | cut -d: -f5`
69        fi
70
71        # If same system, map to the right MAC address
72        hwaddr_found=`ifconfig $ipdev | /bin/grep HWaddr | awk '{print $NF}'`
73        if [ "$hwaddr" != "$hwaddr_found" ]; then
74            ipdev_new=`ifconfig -a | /bin/grep $hwaddr | awk '{print $1}'`
75            if [ "$ipdev_new" != "" ]; then
76                LogIt "Interface $ipdev changed to $ipdev_new (MAC: $hwaddr)"
77                ipdev=$ipdev_new
78            else
79                LogIt "NOTE: Interface $ipdev kept despite it doesn't match the $hwaddr MAC address"
80            fi
81        fi
82
83        LogIt "Configuring $ipdev statically ($ipaddress/$ipnetmask)"
84        ifconfig $ipdev $ipaddress netmask $ipnetmask broadcast $ipbroadcast
85        route add default gw $ipgateway
86
87    fi
88
89    # Leave time to the stack to wake up (reported by some users)
90    sleep 5
91
92    # Handle a potential static route
93    if [ _"$iproute" != _"" ]; then
94        iproute=`echo $iproute | perl -pi -e 's|:| |g'`
95        LogIt "Adding static route with route add $iproute"
96        route add $iproute
97    fi
98
99    # ping server helps waking interface up
100    LogIt "Pinging Remote server..."
101    netfs_server_ipaddr=`echo $netfsmount | cut -d: -f1 | cut -d@ -f2`
102    ping -c $ipcount $netfs_server_ipaddr 
103
104    # Which is our protocol for file sharing
105    if [ "$proto" = "" ]; then
106        LogIt "No protocol specified, defaulting to NFS"
107        proto="nfs"
108    fi
109
110    if [ "$proto" = "sshfs" ]; then
111        LogIt "Mounting SSHFS share ($netfsmount) on /tmp/isodir..."
112        # We need a correct console for ssh
113        ln -sf /dev/console /dev/tty
114        sshfs -o ro,StrictHostKeyChecking=no $netfsopt $netfsmount /tmp/isodir
115    elif [ "$proto" = "smbfs" ]; then
116        LogIt "Mounting SMBFS share ($netfsmount) on /tmp/isodir..."
117        mount -t cifs $netfsopt $netfsmount /tmp/isodir -o ro
118    elif [ "$proto" != "" ]; then
119        if [ -x /sbin/rpcbind ]; then
120            "Startng rpcbind daemon..."
121            /sbin/rpcbind &
122        fi
123        LogIt "Mounting Network share ($netfsmount) on /tmp/isodir..."
124        touch /etc/mtab
125        mount -t $proto -o nolock,ro $netfsopt $netfsmount /tmp/isodir
126    else
127        LogIt "Unknown protocol $proto"
128    fi
129   
130    LogIt "Mounting Remote image ${imgname}-1.iso in $dirimg on /mnt/cdrom in loopback"
131    mount -o ro,loop -t iso9660 /tmp/isodir/$dirimg/${imgname}-1.iso /mnt/cdrom
132
133    # Save the scripts on the Network share locally
134    if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
135        cp $pre /tmp
136        LogIt "Copying $pre under /tmp"
137    fi
138    if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
139        cp $post /tmp
140        LogIt "Copying $post under /tmp"
141    fi
142fi
Note: See TracBrowser for help on using the repository browser.