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
|
---|
10 | ipcount=3
|
---|
11 |
|
---|
12 | # Get info from config file
|
---|
13 | ipdev=`grep netfs-dev /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
14 | hwaddr=`grep netfs-client-hwaddr /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
15 | ipaddress=`grep netfs-client-ipaddr /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
16 | ipnetmask=`grep netfs-client-netmask /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
17 | ipbroadcast=`grep netfs-client-broadcast /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
18 | ipgateway=`grep netfs-client-defgw /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
19 | proto=`grep netfs-proto /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
20 | iproute=`grep netfs-route /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
21 | ipconf=""
|
---|
22 | pre=""
|
---|
23 | post=""
|
---|
24 | export netfsmount=`grep netfs-server-mount /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
25 | export imgname=`grep iso-prefix /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
26 | if [ "$imgname" = "" ]; then
|
---|
27 | export imgname="mondorescue"
|
---|
28 | fi
|
---|
29 | export dirimg=`grep iso-dir /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
30 | if [ "$dirimg" = "" ]; then
|
---|
31 | export dirimg="/"
|
---|
32 | fi
|
---|
33 |
|
---|
34 | # info from cmdline are predominent
|
---|
35 | for i in `cat /proc/cmdline` ; do
|
---|
36 | echo $i | grep -qi ping= && ipcount=`echo $i | cut -d= -f2`
|
---|
37 | echo $i | grep -qi hwaddr= && hwaddr=`echo $i | cut -d= -f2`
|
---|
38 | echo $i | grep -qi ipconf= && ipconf=`echo $i | cut -d= -f2`
|
---|
39 | echo $i | grep -qi netfsmount= && export netfsmount=`echo $i | cut -d= -f2`
|
---|
40 | echo $i | grep -qi netfsopt= && export netfsopt=`echo $i | cut -d= -f2`
|
---|
41 | echo $i | grep -qi prefix= && export imgname=`echo $i | cut -d= -f2`
|
---|
42 | echo $i | grep -qi netfspath= && export dirimg=`echo $i | cut -d= -f2`
|
---|
43 | echo $i | grep -qi pre= && pre=`echo $i | cut -d= -f2`
|
---|
44 | echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
|
---|
45 | echo $i | grep -qi proto= && proto=`echo $i | cut -d= -f2`
|
---|
46 | echo $i | grep -qi iproute= && iproute=`echo $i | cut -d= -f2`
|
---|
47 | done
|
---|
48 |
|
---|
49 | if [ "$ipdev" != "" ] || [ "$ipconf" != "" ]; then
|
---|
50 | # Network configuration stored during archive
|
---|
51 | # or on cmdline so network wanted => starting it
|
---|
52 | LogIt "Starting Network..."
|
---|
53 |
|
---|
54 | # Activate loobback
|
---|
55 | ifconfig lo 127.0.0.1
|
---|
56 |
|
---|
57 | echo "$ipconf" | grep -q "dhcp"
|
---|
58 | if [ $? -eq 0 ]; then
|
---|
59 | ipdev=`echo $ipconf | cut -d: -f1`
|
---|
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
|
---|
70 |
|
---|
71 | # If same system, map to the right MAC address
|
---|
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
|
---|
82 | fi
|
---|
83 | fi
|
---|
84 |
|
---|
85 | LogIt "Configuring $ipdev statically ($ipaddress/$ipnetmask)"
|
---|
86 | ifconfig $ipdev $ipaddress netmask $ipnetmask broadcast $ipbroadcast
|
---|
87 | route add default gw $ipgateway
|
---|
88 |
|
---|
89 | fi
|
---|
90 |
|
---|
91 | # Leave time to the stack to wake up (reported by some users)
|
---|
92 | sleep 5
|
---|
93 |
|
---|
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 |
|
---|
101 | # ping server helps waking interface up
|
---|
102 | LogIt "Pinging Remote server..."
|
---|
103 | netfs_server_ipaddr=`echo $netfsmount | cut -d: -f1 | cut -d@ -f2`
|
---|
104 | ping -c $ipcount $netfs_server_ipaddr
|
---|
105 |
|
---|
106 | # Which is our protocol for file sharing
|
---|
107 | if [ "$proto" = "" ]; then
|
---|
108 | LogIt "No protocol specified, defaulting to NFS"
|
---|
109 | proto="nfs"
|
---|
110 | fi
|
---|
111 |
|
---|
112 | if [ "$proto" = "sshfs" ]; then
|
---|
113 | LogIt "Mounting SSHFS share ($netfsmount) on /tmp/isodir..."
|
---|
114 | # We need a correct console for ssh
|
---|
115 | ln -sf /dev/console /dev/tty
|
---|
116 | sshfs -o ro,StrictHostKeyChecking=no $netfsopt $netfsmount /tmp/isodir
|
---|
117 | elif [ "$proto" = "smbfs" ]; then
|
---|
118 | LogIt "Mounting SMBFS share ($netfsmount) on /tmp/isodir..."
|
---|
119 | mount -t cifs $netfsmount /tmp/isodir -o ro $netfsopt
|
---|
120 | elif [ "$proto" != "" ]; then
|
---|
121 | if [ -x /sbin/rpcbind ]; then
|
---|
122 | echo "Starting rpcbind daemon..."
|
---|
123 | /sbin/rpcbind -w &
|
---|
124 | fi
|
---|
125 | LogIt "Mounting Network share ($netfsmount) on /tmp/isodir..."
|
---|
126 | touch /etc/mtab
|
---|
127 | mount -t $proto -o nolock,ro $netfsopt $netfsmount /tmp/isodir
|
---|
128 | else
|
---|
129 | LogIt "Unknown protocol $proto"
|
---|
130 | fi
|
---|
131 |
|
---|
132 | LogIt "Mounting Remote image ${imgname}-1.iso in $dirimg on /mnt/cdrom in loopback"
|
---|
133 | mount -o ro,loop -t iso9660 /tmp/isodir/$dirimg/${imgname}-1.iso /mnt/cdrom
|
---|
134 |
|
---|
135 | # Save the scripts on the Network share locally
|
---|
136 | if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
|
---|
137 | cp $pre /tmp
|
---|
138 | LogIt "Copying $pre under /tmp"
|
---|
139 | fi
|
---|
140 | if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
|
---|
141 | cp $post /tmp
|
---|
142 | LogIt "Copying $post under /tmp"
|
---|
143 | fi
|
---|
144 | fi
|
---|