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

Last change on this file since 3178 was 3178, checked in by Bruno Cornec, 11 years ago

Fix #713 by correcting typo (Victor Gattegno)

  • Property svn:executable set to *
File size: 4.9 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-`
[3178]20iproute=`grep netfs-route /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
[740]21ipconf=""
[2255]22pre=""
23post=""
[2380]24export netfsmount=`grep netfs-server-mount /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
[1983]25export imgname=`grep iso-prefix /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
[740]26if [ "$imgname" = "" ]; then
[801]27 export imgname="mondorescue"
[740]28fi
[2380]29export dirimg=`grep netfs-server-path /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
[740]30if [ "$dirimg" = "" ]; then
[801]31 export dirimg="/"
[740]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`
[2887]37 echo $i | grep -qi hwaddr= && hwaddr=`echo $i | cut -d= -f2`
[740]38 echo $i | grep -qi ipconf= && ipconf=`echo $i | cut -d= -f2`
[2380]39 echo $i | grep -qi netfsmount= && export netfsmount=`echo $i | cut -d= -f2`
[2498]40 echo $i | grep -qi netfsopt= && export netfsopt=`echo $i | cut -d= -f2`
[801]41 echo $i | grep -qi prefix= && export imgname=`echo $i | cut -d= -f2`
[2380]42 echo $i | grep -qi netfspath= && export dirimg=`echo $i | cut -d= -f2`
[2255]43 echo $i | grep -qi pre= && pre=`echo $i | cut -d= -f2`
44 echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
[2380]45 echo $i | grep -qi proto= && proto=`echo $i | cut -d= -f2`
[3168]46 echo $i | grep -qi iproute= && iproute=`echo $i | cut -d= -f2`
[740]47done
48
[1830]49if [ "$ipdev" != "" ] || [ "$ipconf" != "" ]; then
50 # Network configuration stored during archive
51 # or on cmdline so network wanted => starting it
[740]52 LogIt "Starting Network..."
53
[1830]54 # Activate loobback
55 ifconfig lo 127.0.0.1
[740]56
[1830]57 echo "$ipconf" | grep -q "dhcp"
58 if [ $? -eq 0 ]; then
[740]59 ipdev=`echo $ipconf | cut -d: -f1`
[1830]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
[2887]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
[1830]83 LogIt "Configuring $ipdev statically ($ipaddress/$ipnetmask)"
84 ifconfig $ipdev $ipaddress netmask $ipnetmask broadcast $ipbroadcast
85 route add default gw $ipgateway
[2887]86
[740]87 fi
88
[3168]89 # Leave time to the stack to wake up (reported by some users)
[2887]90 sleep 5
91
[3168]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
[1830]99 # ping server helps waking interface up
[2380]100 LogIt "Pinging Remote server..."
101 netfs_server_ipaddr=`echo $netfsmount | cut -d: -f1 | cut -d@ -f2`
102 ping -c $ipcount $netfs_server_ipaddr
[740]103
[2380]104 # Which is our protocol for file sharing
105 if [ "$proto" = "" ]; then
106 LogIt "No protocol specified, defaulting to NFS"
[2709]107 proto="nfs"
[2380]108 fi
109
110 if [ "$proto" = "sshfs" ]; then
111 LogIt "Mounting SSHFS share ($netfsmount) on /tmp/isodir..."
[2438]112 # We need a correct console for ssh
113 ln -sf /dev/console /dev/tty
[2498]114 sshfs -o ro,StrictHostKeyChecking=no $netfsopt $netfsmount /tmp/isodir
[3111]115 elif [ "$proto" = "smbfs" ]; then
116 LogIt "Mounting SMBFS share ($netfsmount) on /tmp/isodir..."
117 mount -t cifs $netfsopt $netfsmount /tmp/isodir -o ro
[2380]118 elif [ "$proto" != "" ]; then
[2951]119 if [ -x /sbin/rpcbind ]; then
120 "Startng rpcbind daemon..."
121 /sbin/rpcbind &
122 fi
[2380]123 LogIt "Mounting Network share ($netfsmount) on /tmp/isodir..."
124 touch /etc/mtab
[2498]125 mount -t $proto -o nolock,ro $netfsopt $netfsmount /tmp/isodir
[2380]126 else
127 LogIt "Unknown protocol $proto"
128 fi
[1830]129
[2380]130 LogIt "Mounting Remote image ${imgname}-1.iso in $dirimg on /mnt/cdrom in loopback"
[1927]131 mount -o ro,loop -t iso9660 /tmp/isodir/$dirimg/${imgname}-1.iso /mnt/cdrom
[2253]132
[2380]133 # Save the scripts on the Network share locally
[2255]134 if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
135 cp $pre /tmp
136 LogIt "Copying $pre under /tmp"
[2253]137 fi
[2255]138 if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
139 cp $post /tmp
140 LogIt "Copying $post under /tmp"
141 fi
[1830]142fi
Note: See TracBrowser for help on using the repository browser.