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=""
|
---|
14 | hwaddr=""
|
---|
15 | ipaddress=""
|
---|
16 | ipnetmask=""
|
---|
17 | ipbroadcast=""
|
---|
18 | ipgateway=""
|
---|
19 | proto=""
|
---|
20 | ipconf=""
|
---|
21 | pre=""
|
---|
22 | post=""
|
---|
23 | netfsmount=""
|
---|
24 | imgname=""
|
---|
25 | dirimg=""
|
---|
26 |
|
---|
27 | # Get info from config file
|
---|
28 | if [ -f $MINDI_CACHE/mondorestore.cfg ]; then
|
---|
29 | ipdev=`grep netfs-dev $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
30 | hwaddr=`grep netfs-client-hwaddr $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
31 | ipaddress=`grep netfs-client-ipaddr $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
32 | ipnetmask=`grep netfs-client-netmask $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
33 | ipbroadcast=`grep netfs-client-broadcast $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
34 | ipgateway=`grep netfs-client-defgw $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
35 | proto=`grep netfs-proto $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
36 | export netfsmount=`grep netfs-server-mount $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
37 | export imgname=`grep iso-prefix $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
38 | export dirimg=`grep netfs-server-path $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
39 | fi
|
---|
40 |
|
---|
41 | if [ "$imgname" = "" ]; then
|
---|
42 | export imgname="mondorescue"
|
---|
43 | fi
|
---|
44 | if [ "$dirimg" = "" ]; then
|
---|
45 | export dirimg="/"
|
---|
46 | fi
|
---|
47 |
|
---|
48 | # info from cmdline are predominent
|
---|
49 | for i in `cat $CMDLINE` ; do
|
---|
50 | echo $i | grep -qi ping= && ipcount=`echo $i | cut -d= -f2`
|
---|
51 | echo $i | grep -qi hwaddr= && hwaddr=`echo $i | cut -d= -f2`
|
---|
52 | echo $i | grep -qi ipconf= && ipconf=`echo $i | cut -d= -f2`
|
---|
53 | echo $i | grep -qi netfsmount= && export netfsmount=`echo $i | cut -d= -f2`
|
---|
54 | echo $i | grep -qi netfsopt= && export netfsopt=`echo $i | cut -d= -f2`
|
---|
55 | echo $i | grep -qi prefix= && export imgname=`echo $i | cut -d= -f2`
|
---|
56 | echo $i | grep -qi netfspath= && export dirimg=`echo $i | cut -d= -f2`
|
---|
57 | echo $i | grep -qi pre= && pre=`echo $i | cut -d= -f2`
|
---|
58 | echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
|
---|
59 | echo $i | grep -qi proto= && proto=`echo $i | cut -d= -f2`
|
---|
60 | done
|
---|
61 |
|
---|
62 | if [ "$ipdev" != "" ] || [ "$ipconf" != "" ]; then
|
---|
63 | # Network configuration stored during archive
|
---|
64 | # or on cmdline so network wanted => starting it
|
---|
65 | LogIt "Starting Network..."
|
---|
66 |
|
---|
67 | # Activate loobback
|
---|
68 | ifconfig lo 127.0.0.1
|
---|
69 |
|
---|
70 | echo "$ipconf" | grep -q "dhcp"
|
---|
71 | if [ $? -eq 0 ]; then
|
---|
72 | ipdev=`echo $ipconf | cut -d: -f1`
|
---|
73 | dhc="/sbin/dhclient"
|
---|
74 | if [ ! -x $dhc ]; then
|
---|
75 | dhc="/sbin/dhcpcd"
|
---|
76 | if [ ! -x $dhc ]; then
|
---|
77 | dhc="/sbin/udhcpc"
|
---|
78 | if [ ! -x $dhc ]; then
|
---|
79 | dhc=""
|
---|
80 | else
|
---|
81 | dhc="$dhc -i"
|
---|
82 | fi
|
---|
83 | fi
|
---|
84 | fi
|
---|
85 | if [ -x $dhc ]; then
|
---|
86 | LogIt "Making DHCP request on $ipdev with $dhc"
|
---|
87 | $dhc $ipdev
|
---|
88 | else
|
---|
89 | LogIt "Unable to make a DHCP request on $ipdev - no client found"
|
---|
90 | fi
|
---|
91 | else
|
---|
92 | if [ "$ipconf" != "" ]; then
|
---|
93 | ipdev=`echo $ipconf | cut -d: -f1`
|
---|
94 | ipaddress=`echo $ipconf | cut -d: -f2`
|
---|
95 | ipnetmask=`echo $ipconf | cut -d: -f3`
|
---|
96 | ipbroadcast=`echo $ipconf | cut -d: -f4`
|
---|
97 | ipgateway=`echo $ipconf | cut -d: -f5`
|
---|
98 | fi
|
---|
99 |
|
---|
100 | # If same system, map to the right MAC address
|
---|
101 | hwaddr_found=`ifconfig $ipdev | /bin/grep HWaddr | awk '{print $NF}'`
|
---|
102 | if [ "$hwaddr" != "$hwaddr_found" ]; then
|
---|
103 | ipdev_new=`ifconfig -a | /bin/grep $hwaddr | awk '{print $1}'`
|
---|
104 | if [ "$ipdev_new" != "" ]; then
|
---|
105 | LogIt "Interface $ipdev changed to $ipdev_new (MAC: $hwaddr)"
|
---|
106 | ipdev=$ipdev_new
|
---|
107 | else
|
---|
108 | LogIt "NOTE: Interface $ipdev kept despite it doesn't match the $hwaddr MAC address"
|
---|
109 | fi
|
---|
110 | fi
|
---|
111 |
|
---|
112 | LogIt "Configuring $ipdev statically ($ipaddress/$ipnetmask)"
|
---|
113 | ifconfig $ipdev $ipaddress netmask $ipnetmask broadcast $ipbroadcast
|
---|
114 | route add default gw $ipgateway
|
---|
115 |
|
---|
116 | fi
|
---|
117 |
|
---|
118 | # Leave time to the satck to wake up (reported by some users)
|
---|
119 | sleep 5
|
---|
120 |
|
---|
121 | # ping server helps waking interface up
|
---|
122 | netfs_server_ipaddr=`echo $netfsmount | cut -d: -f1 | cut -d@ -f2`
|
---|
123 | if [ $netfs_server_ipaddr != "" ]; then
|
---|
124 | LogIt "Pinging Remote server $netfs_server_ipaddr ($ipcount times)..."
|
---|
125 | ping -c $ipcount $netfs_server_ipaddr
|
---|
126 | fi
|
---|
127 |
|
---|
128 | # Which is our protocol for file sharing
|
---|
129 | if [ "$proto" = "" ]; then
|
---|
130 | LogIt "No protocol specified, defaulting to NFS"
|
---|
131 | proto="nfs"
|
---|
132 | fi
|
---|
133 |
|
---|
134 | if [ "$netfsmount" != "" ]; then
|
---|
135 | if [ "$proto" = "sshfs" ]; then
|
---|
136 | LogIt "Mounting SSHFS share ($netfsmount) on /tmp/isodir..."
|
---|
137 | # We need a correct console for ssh
|
---|
138 | ln -sf /dev/console /dev/tty
|
---|
139 | sshfs -o ro,StrictHostKeyChecking=no $netfsopt $netfsmount /tmp/isodir
|
---|
140 | elif [ "$proto" = "smbfs" ]; then
|
---|
141 | LogIt "Mounting SMBFS share ($netfsmount) on /tmp/isodir..."
|
---|
142 | mount -t cifs $netfsopt $netfsmount /tmp/isodir -o ro
|
---|
143 | elif [ "$proto" != "" ]; then
|
---|
144 | if [ -x /sbin/rpcbind ]; then
|
---|
145 | "Startng rpcbind daemon..."
|
---|
146 | /sbin/rpcbind &
|
---|
147 | fi
|
---|
148 | LogIt "Mounting Network share ($netfsmount) on /tmp/isodir..."
|
---|
149 | touch /etc/mtab
|
---|
150 | mount -t $proto -o nolock,ro $netfsopt $netfsmount /tmp/isodir
|
---|
151 | else
|
---|
152 | LogIt "Unknown protocol $proto"
|
---|
153 | fi
|
---|
154 |
|
---|
155 | # In all these cases we should have an image
|
---|
156 | LogIt "Mounting Remote image ${imgname}-1.iso in $dirimg on /mnt/cdrom in loopback"
|
---|
157 | mount -o ro,loop -t iso9660 /tmp/isodir/$dirimg/${imgname}-1.iso /mnt/cdrom
|
---|
158 | else
|
---|
159 | LogIt "No image to mount"
|
---|
160 | fi
|
---|
161 |
|
---|
162 | # Save the scripts on the Network share locally
|
---|
163 | if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
|
---|
164 | cp $pre /tmp
|
---|
165 | LogIt "Copying $pre under /tmp"
|
---|
166 | fi
|
---|
167 | if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
|
---|
168 | cp $post /tmp
|
---|
169 | LogIt "Copying $post under /tmp"
|
---|
170 | fi
|
---|
171 | fi
|
---|