source: MondoRescue/branches/3.2/mindi/rootfs/usr/sbin/start-netfs@ 3279

Last change on this file since 3279 was 3279, checked in by Bruno Cornec, 10 years ago
  • flaws_str should be NULL if no error detected not ""
  • Try to redirect back fd at restore time before launching mondorestore to avoid garbage in log
  • 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
[3271]13ipdev=`grep netfs-dev /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
14hwaddr=`grep netfs-client-hwaddr /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
15ipaddress=`grep netfs-client-ipaddr /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
16ipnetmask=`grep netfs-client-netmask /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
17ipbroadcast=`grep netfs-client-broadcast /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
18ipgateway=`grep netfs-client-defgw /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
19proto=`grep netfs-proto /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
20iproute=`grep netfs-route /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
[740]21ipconf=""
[2255]22pre=""
23post=""
[3271]24export netfsmount=`grep netfs-server-mount /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
25export imgname=`grep iso-prefix /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
[740]26if [ "$imgname" = "" ]; then
[801]27 export imgname="mondorescue"
[740]28fi
[3278]29export dirimg=`grep iso-dir /tmp/mondorestore.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
[3271]72 if [ "$hwaddr" != "" ]; then
73 hwaddr_found=`ifconfig $ipdev | grep HWaddr | awk '{print $NF}'`
74 if [ "$hwaddr" != "$hwaddr_found" ]; then
75 ipdev_new=`ifconfig -a | grep $hwaddr | awk '{print $1}'`
76 if [ "$ipdev_new" != "" ]; then
77 LogIt "Interface $ipdev changed to $ipdev_new (MAC: $hwaddr)"
78 ipdev=$ipdev_new
79 else
80 LogIt "NOTE: Interface $ipdev kept despite it doesn't match the $hwaddr MAC address"
81 fi
[2887]82 fi
83 fi
84
[1830]85 LogIt "Configuring $ipdev statically ($ipaddress/$ipnetmask)"
86 ifconfig $ipdev $ipaddress netmask $ipnetmask broadcast $ipbroadcast
87 route add default gw $ipgateway
[2887]88
[740]89 fi
90
[3168]91 # Leave time to the stack to wake up (reported by some users)
[2887]92 sleep 5
93
[3168]94 # Handle a potential static route
95 if [ _"$iproute" != _"" ]; then
96 iproute=`echo $iproute | perl -pi -e 's|:| |g'`
97 LogIt "Adding static route with route add $iproute"
98 route add $iproute
99 fi
100
[1830]101 # ping server helps waking interface up
[2380]102 LogIt "Pinging Remote server..."
103 netfs_server_ipaddr=`echo $netfsmount | cut -d: -f1 | cut -d@ -f2`
104 ping -c $ipcount $netfs_server_ipaddr
[740]105
[2380]106 # Which is our protocol for file sharing
107 if [ "$proto" = "" ]; then
108 LogIt "No protocol specified, defaulting to NFS"
[2709]109 proto="nfs"
[2380]110 fi
111
112 if [ "$proto" = "sshfs" ]; then
113 LogIt "Mounting SSHFS share ($netfsmount) on /tmp/isodir..."
[2438]114 # We need a correct console for ssh
115 ln -sf /dev/console /dev/tty
[2498]116 sshfs -o ro,StrictHostKeyChecking=no $netfsopt $netfsmount /tmp/isodir
[3111]117 elif [ "$proto" = "smbfs" ]; then
118 LogIt "Mounting SMBFS share ($netfsmount) on /tmp/isodir..."
[3279]119 mount -t cifs $netfsmount /tmp/isodir -o ro $netfsopt
[2380]120 elif [ "$proto" != "" ]; then
[2951]121 if [ -x /sbin/rpcbind ]; then
[3271]122 echo "Starting rpcbind daemon..."
[3261]123 /sbin/rpcbind -w &
[2951]124 fi
[2380]125 LogIt "Mounting Network share ($netfsmount) on /tmp/isodir..."
126 touch /etc/mtab
[2498]127 mount -t $proto -o nolock,ro $netfsopt $netfsmount /tmp/isodir
[2380]128 else
129 LogIt "Unknown protocol $proto"
130 fi
[1830]131
[2380]132 LogIt "Mounting Remote image ${imgname}-1.iso in $dirimg on /mnt/cdrom in loopback"
[1927]133 mount -o ro,loop -t iso9660 /tmp/isodir/$dirimg/${imgname}-1.iso /mnt/cdrom
[2253]134
[2380]135 # Save the scripts on the Network share locally
[2255]136 if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
137 cp $pre /tmp
138 LogIt "Copying $pre under /tmp"
[2253]139 fi
[2255]140 if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
141 cp $post /tmp
142 LogIt "Copying $post under /tmp"
143 fi
[1830]144fi
Note: See TracBrowser for help on using the repository browser.