source: MondoRescue/branches/2.2.9/mindi/rootfs/sbin/start-netfs@ 3320

Last change on this file since 3320 was 3320, checked in by Bruno Cornec, 9 years ago
  • Re-add (thanks git BTW) the 2.2.9 branch which had been destroyed in the move to 3.0
  • Property svn:executable set to *
File size: 4.3 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-`
20ipconf=""
21pre=""
22post=""
23export netfsmount=`grep netfs-server-mount /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
24export imgname=`grep iso-prefix /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
25if [ "$imgname" = "" ]; then
26 export imgname="mondorescue"
27fi
28export dirimg=`grep netfs-server-path /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
29if [ "$dirimg" = "" ]; then
30 export dirimg="/"
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`
36 echo $i | grep -qi hwaddr= && hwaddr=`echo $i | cut -d= -f2`
37 echo $i | grep -qi ipconf= && ipconf=`echo $i | cut -d= -f2`
38 echo $i | grep -qi netfsmount= && export netfsmount=`echo $i | cut -d= -f2`
39 echo $i | grep -qi netfsopt= && export netfsopt=`echo $i | cut -d= -f2`
40 echo $i | grep -qi prefix= && export imgname=`echo $i | cut -d= -f2`
41 echo $i | grep -qi netfspath= && export dirimg=`echo $i | cut -d= -f2`
42 echo $i | grep -qi pre= && pre=`echo $i | cut -d= -f2`
43 echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
44 echo $i | grep -qi proto= && proto=`echo $i | cut -d= -f2`
45done
46
47if [ "$ipdev" != "" ] || [ "$ipconf" != "" ]; then
48 # Network configuration stored during archive
49 # or on cmdline so network wanted => starting it
50 LogIt "Starting Network..."
51
52 # Activate loobback
53 ifconfig lo 127.0.0.1
54
55 echo "$ipconf" | grep -q "dhcp"
56 if [ $? -eq 0 ]; then
57 ipdev=`echo $ipconf | cut -d: -f1`
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
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
81 LogIt "Configuring $ipdev statically ($ipaddress/$ipnetmask)"
82 ifconfig $ipdev $ipaddress netmask $ipnetmask broadcast $ipbroadcast
83 route add default gw $ipgateway
84
85 fi
86
87 # Leave time to the satck to wake up (reported by some users)
88 sleep 5
89
90 # ping server helps waking interface up
91 LogIt "Pinging Remote server..."
92 netfs_server_ipaddr=`echo $netfsmount | cut -d: -f1 | cut -d@ -f2`
93 ping -c $ipcount $netfs_server_ipaddr
94
95 # Which is our protocol for file sharing
96 if [ "$proto" = "" ]; then
97 LogIt "No protocol specified, defaulting to NFS"
98 proto="nfs"
99 fi
100
101 if [ "$proto" = "sshfs" ]; then
102 LogIt "Mounting SSHFS share ($netfsmount) on /tmp/isodir..."
103 # We need a correct console for ssh
104 ln -sf /dev/console /dev/tty
105 sshfs -o ro,StrictHostKeyChecking=no $netfsopt $netfsmount /tmp/isodir
106 elif [ "$proto" != "" ]; then
107 LogIt "Mounting Network share ($netfsmount) on /tmp/isodir..."
108 touch /etc/mtab
109 mount -t $proto -o nolock,ro $netfsopt $netfsmount /tmp/isodir
110 else
111 LogIt "Unknown protocol $proto"
112 fi
113
114 LogIt "Mounting Remote image ${imgname}-1.iso in $dirimg on /mnt/cdrom in loopback"
115 mount -o ro,loop -t iso9660 /tmp/isodir/$dirimg/${imgname}-1.iso /mnt/cdrom
116
117 # Save the scripts on the Network share locally
118 if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
119 cp $pre /tmp
120 LogIt "Copying $pre under /tmp"
121 fi
122 if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
123 cp $post /tmp
124 LogIt "Copying $post under /tmp"
125 fi
126fi
Note: See TracBrowser for help on using the repository browser.