[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
|
---|
| 10 | ipcount=3
|
---|
| 11 |
|
---|
| 12 | # Get info from config file
|
---|
[2380] | 13 | ipdev=`grep netfs-dev /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
[2887] | 14 | hwaddr=`grep netfs-client-hwaddr /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
[2380] | 15 | ipaddress=`grep netfs-client-ipaddr /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
| 16 | ipnetmask=`grep netfs-client-netmask /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
| 17 | ipbroadcast=`grep netfs-client-broadcast /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
| 18 | ipgateway=`grep netfs-client-defgw /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
| 19 | proto=`grep netfs-proto /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
[3178] | 20 | iproute=`grep netfs-route /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
[740] | 21 | ipconf=""
|
---|
[2255] | 22 | pre=""
|
---|
| 23 | post=""
|
---|
[2380] | 24 | export netfsmount=`grep netfs-server-mount /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
[1983] | 25 | export imgname=`grep iso-prefix /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
[740] | 26 | if [ "$imgname" = "" ]; then
|
---|
[801] | 27 | export imgname="mondorescue"
|
---|
[740] | 28 | fi
|
---|
[2380] | 29 | export dirimg=`grep netfs-server-path /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
[740] | 30 | if [ "$dirimg" = "" ]; then
|
---|
[801] | 31 | export dirimg="/"
|
---|
[740] | 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`
|
---|
[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] | 47 | done
|
---|
| 48 |
|
---|
[1830] | 49 | if [ "$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
|
---|
[3319] | 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..."
|
---|
[3319] | 119 | mount -t cifs $netfsmount /tmp/isodir -o ro $netfsopt
|
---|
[2380] | 120 | elif [ "$proto" != "" ]; then
|
---|
[2951] | 121 | if [ -x /sbin/rpcbind ]; then
|
---|
[3319] | 122 | echo "Starting rpcbind daemon..."
|
---|
| 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] | 144 | fi
|
---|