source: branches/2.2.10/mindi/rootfs/sbin/start-netfs @ 2709

Last change on this file since 2709 was 2709, checked in by bruno, 7 years ago

r4196@localhost: bruno | 2011-01-27 20:01:42 +0100

  • Really fix the proto bug in start-netfs !
  • Property svn:executable set to *
File size: 4.4 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
12ipconf=""
13pre=""
14post=""
15ipdev=""
16ipaddress=""
17ipnetmask=""
18ipbroadcast=""
19ipgateway=""
20proto=""
21netfsmount=""
22imgname=""
23dirimg=""
24
25# Get info from config file
26if [ -f $MINDI_CACHE/mondorestore.cfg ]; then
27    ipdev=`grep netfs-dev $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
28    ipaddress=`grep netfs-client-ipaddr $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
29    ipnetmask=`grep netfs-client-netmask $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
30    ipbroadcast=`grep netfs-client-broadcast $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
31    ipgateway=`grep netfs-client-defgw $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
32    proto=`grep netfs-proto $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
33    export netfsmount=`grep netfs-server-mount $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
34    export imgname=`grep iso-prefix $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
35    export dirimg=`grep netfs-server-path $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
36fi
37
38if [ "$imgname" = "" ]; then
39    export imgname="mondorescue"
40fi
41if [ "$dirimg" = "" ]; then
42    export dirimg="/"
43fi
44
45# info from cmdline are predominent
46for i in `cat $CMDLINE` ; do
47    echo $i | grep -qi ping= && ipcount=`echo $i | cut -d= -f2`
48    echo $i | grep -qi ipconf= && ipconf=`echo $i | cut -d= -f2`
49    echo $i | grep -qi netfsmount= && export netfsmount=`echo $i | cut -d= -f2`
50    echo $i | grep -qi netfsopt= && export netfsopt=`echo $i | cut -d= -f2`
51    echo $i | grep -qi prefix= && export imgname=`echo $i | cut -d= -f2`
52    echo $i | grep -qi netfspath= && export dirimg=`echo $i | cut -d= -f2`
53    echo $i | grep -qi pre= && pre=`echo $i | cut -d= -f2`
54    echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
55    echo $i | grep -qi proto= && proto=`echo $i | cut -d= -f2`
56done
57
58if [ "$ipdev" != "" ] || [ "$ipconf" != "" ]; then
59    # Network configuration stored during archive
60    # or on cmdline so network wanted => starting it
61    LogIt "Starting Network..."
62
63    # Activate loobback
64    ifconfig lo 127.0.0.1
65
66    echo "$ipconf" | grep -q "dhcp"
67    if [ $? -eq 0 ]; then
68        ipdev=`echo $ipconf | cut -d: -f1`
69        dhc="/sbin/dhclient"
70        if [ ! -x $dhc ]; then
71            dhc="/sbin/dhcpcd"
72            if [ ! -x $dhc ]; then
73                dhc="/sbin/udhcpc"
74                if [ ! -x $dhc ]; then
75                    dhc=""
76                else
77                    dhc="$dhc -i"
78                fi
79            fi
80        fi
81        if [ -x $dhc ]; then
82            LogIt "Making DHCP request on $ipdev with $dhc"
83            $dhc $ipdev
84        else
85            LogIt "Unable to make a DHCP request on $ipdev - no client found"
86        fi
87    else
88        if [ "$ipconf" != "" ]; then
89            ipdev=`echo $ipconf | cut -d: -f1`
90            ipaddress=`echo $ipconf | cut -d: -f2`
91            ipnetmask=`echo $ipconf | cut -d: -f3`
92            ipbroadcast=`echo $ipconf | cut -d: -f4`
93            ipgateway=`echo $ipconf | cut -d: -f5`
94        fi
95        LogIt "Configuring $ipdev statically ($ipaddress/$ipnetmask)"
96        ifconfig $ipdev $ipaddress netmask $ipnetmask broadcast $ipbroadcast
97        route add default gw $ipgateway
98    fi
99
100    # ping server helps waking interface up
101    netfs_server_ipaddr=`echo $netfsmount | cut -d: -f1 | cut -d@ -f2`
102    if [ $netfs_server_ipaddr != "" ]; then
103        LogIt "Pinging Remote server $netfs_server_ipaddr ($ipcount times)..."
104        ping -c $ipcount $netfs_server_ipaddr 
105    fi
106
107    # Which is our protocol for file sharing
108    if [ "$proto" = "" ]; then
109        LogIt "No protocol specified, defaulting to NFS"
110        proto="nfs"
111    fi
112
113    if [ "$netfsmount" != "" ]; then
114        if [ "$proto" = "sshfs" ]; then
115            LogIt "Mounting SSHFS share ($netfsmount) on /tmp/isodir..."
116            # We need a correct console for ssh
117            ln -sf /dev/console /dev/tty
118            sshfs -o ro,StrictHostKeyChecking=no $netfsopt $netfsmount /tmp/isodir
119        elif [ "$proto" != "" ]; then
120            LogIt "Mounting Network share ($netfsmount) on /tmp/isodir..."
121            touch /etc/mtab
122            mount -t $proto -o nolock,ro $netfsopt $netfsmount /tmp/isodir
123        else
124            LogIt "Unknown protocol $proto"
125        fi
126
127        # In all these cases we should have an image
128        LogIt "Mounting Remote image ${imgname}-1.iso in $dirimg on /mnt/cdrom in loopback"
129        mount -o ro,loop -t iso9660 /tmp/isodir/$dirimg/${imgname}-1.iso /mnt/cdrom
130    else
131        LogIt "No image to mount"
132    fi
133   
134    # Save the scripts on the Network share locally
135    if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
136        cp $pre /tmp
137        LogIt "Copying $pre under /tmp"
138    fi
139    if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
140        cp $post /tmp
141        LogIt "Copying $post under /tmp"
142    fi
143fi
Note: See TracBrowser for help on using the repository browser.