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

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