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

Last change on this file since 3440 was 3440, checked in by Bruno Cornec, 10 years ago

replace perl usage by tr as perl is not yet available for start-netfs

  • Property svn:executable set to *
File size: 5.1 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/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
14# MAC address in uppercases
15hwaddr=`grep netfs-client-hwaddr /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2- | tr '[a-z]' '[A-Z]'`
16ipaddress=`grep netfs-client-ipaddr /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
17ipnetmask=`grep netfs-client-netmask /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
18ipbroadcast=`grep netfs-client-broadcast /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
19ipgateway=`grep netfs-client-defgw /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
20proto=`grep netfs-proto /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
21iproute=`grep netfs-route /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
22ipconf=""
23pre=""
24post=""
25export netfsmount=`grep netfs-server-mount /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
26export imgname=`grep iso-prefix /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
27if [ "$imgname" = "" ]; then
28 export imgname="mondorescue"
29fi
30export dirimg=`grep iso-dir /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
31if [ "$dirimg" = "" ]; then
32 export dirimg="/"
33fi
34
35# info from cmdline are predominent
36for i in `cat /proc/cmdline` ; do
37 echo $i | grep -qi ping= && ipcount=`echo $i | cut -d= -f2`
38 echo $i | grep -qi hwaddr= && hwaddr=`echo $i | cut -d= -f2 | tr '[a-z]' '[A-Z]'`
39 echo $i | grep -qi ipconf= && ipconf=`echo $i | cut -d= -f2`
40 echo $i | grep -qi netfsmount= && export netfsmount=`echo $i | cut -d= -f2`
41 echo $i | grep -qi netfsopt= && export netfsopt=`echo $i | cut -d= -f2`
42 echo $i | grep -qi prefix= && export imgname=`echo $i | cut -d= -f2`
43 echo $i | grep -qi netfspath= && export dirimg=`echo $i | cut -d= -f2`
44 echo $i | grep -qi pre= && pre=`echo $i | cut -d= -f2`
45 echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
46 echo $i | grep -qi proto= && proto=`echo $i | cut -d= -f2`
47 echo $i | grep -qi iproute= && iproute=`echo $i | cut -d= -f2`
48done
49
50if [ "$ipdev" != "" ] || [ "$ipconf" != "" ]; then
51 # Network configuration stored during archive
52 # or on cmdline so network wanted => starting it
53 LogIt "Starting Network..."
54
55 # Activate loobback
56 ifconfig lo 127.0.0.1
57
58 echo "$ipconf" | grep -q "dhcp"
59 if [ $? -eq 0 ]; then
60 ipdev=`echo $ipconf | cut -d: -f1`
61 LogIt "Making DHCP request on $ipdev"
62 udhcpc -i $ipdev
63 else
64 if [ "$ipconf" != "" ]; then
65 ipdev=`echo $ipconf | cut -d: -f1`
66 ipaddress=`echo $ipconf | cut -d: -f2`
67 ipnetmask=`echo $ipconf | cut -d: -f3`
68 ipbroadcast=`echo $ipconf | cut -d: -f4`
69 ipgateway=`echo $ipconf | cut -d: -f5`
70 fi
71
72 # If same system, map to the right MAC address
73 if [ "$hwaddr" != "" ]; then
74 hwaddr_found=`ifconfig $ipdev | grep HWaddr | awk '{print $NF}' | tr '[a-z]' '[A-Z]'`
75 if [ "$hwaddr" != "$hwaddr_found" ]; then
76 ipdev_new=`ifconfig -a | grep -i $hwaddr | awk '{print $1}'`
77 if [ "$ipdev_new" != "" ]; then
78 LogIt "Interface with MAC address $hwaddr changed from $ipdev to $ipdev_new"
79 LogIt "Using $ipdev_new for network configuration from now on"
80 ipdev=$ipdev_new
81 else
82 LogIt "NOTE: Interface $ipdev kept despite it doesn't match the $hwaddr MAC address"
83 fi
84 fi
85 fi
86
87 LogIt "Configuring $ipdev statically ($ipaddress/$ipnetmask)"
88 ifconfig $ipdev $ipaddress netmask $ipnetmask broadcast $ipbroadcast
89 route add default gw $ipgateway
90
91 fi
92
93 # Leave time to the stack to wake up (reported by some users)
94 sleep 5
95
96 # Handle a potential static route
97 if [ _"$iproute" != _"" ]; then
98 iproute=`echo $iproute | sed -i 's/:/ /g'`
99 LogIt "Adding static route with route add $iproute"
100 route add $iproute
101 fi
102
103 # ping server helps waking interface up
104 LogIt "Pinging Remote server..."
105 netfs_server_ipaddr=`echo $netfsmount | cut -d: -f1 | cut -d@ -f2`
106 ping -c $ipcount $netfs_server_ipaddr
107
108 # Which is our protocol for file sharing
109 if [ "$proto" = "" ]; then
110 LogIt "No protocol specified, defaulting to NFS"
111 proto="nfs"
112 fi
113
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" = "smbfs" ]; then
120 LogIt "Mounting SMBFS share ($netfsmount) on /tmp/isodir..."
121 mount -t cifs $netfsmount /tmp/isodir -o ro $netfsopt
122 elif [ "$proto" != "" ]; then
123 if [ -x /sbin/rpcbind ]; then
124 echo "Starting rpcbind daemon..."
125 /sbin/rpcbind -w &
126 fi
127 LogIt "Mounting Network share ($netfsmount) on /tmp/isodir..."
128 touch /etc/mtab
129 mount -t $proto -o nolock,ro $netfsopt $netfsmount /tmp/isodir
130 else
131 LogIt "Unknown protocol $proto"
132 fi
133
134 LogIt "Mounting Remote image ${imgname}-1.iso in $dirimg on /mnt/cdrom in loopback"
135 mount -o ro,loop -t iso9660 /tmp/isodir/$dirimg/${imgname}-1.iso /mnt/cdrom
136
137 # Save the scripts on the Network share locally
138 if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
139 cp $pre /tmp
140 LogIt "Copying $pre under /tmp"
141 fi
142 if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
143 cp $post /tmp
144 LogIt "Copying $post under /tmp"
145 fi
146fi
Note: See TracBrowser for help on using the repository browser.