[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-`
|
---|
| 14 | ipaddress=`grep netfs-client-ipaddr /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
| 15 | ipnetmask=`grep netfs-client-netmask /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
| 16 | ipbroadcast=`grep netfs-client-broadcast /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
| 17 | ipgateway=`grep netfs-client-defgw /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
| 18 | proto=`grep netfs-proto /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
[740] | 19 | ipconf=""
|
---|
[2255] | 20 | pre=""
|
---|
| 21 | post=""
|
---|
[2380] | 22 | export netfsmount=`grep netfs-server-mount /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
[1983] | 23 | export imgname=`grep iso-prefix /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
[740] | 24 | if [ "$imgname" = "" ]; then
|
---|
[801] | 25 | export imgname="mondorescue"
|
---|
[740] | 26 | fi
|
---|
[2380] | 27 | export dirimg=`grep netfs-server-path /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
[740] | 28 | if [ "$dirimg" = "" ]; then
|
---|
[801] | 29 | export dirimg="/"
|
---|
[740] | 30 | fi
|
---|
| 31 |
|
---|
| 32 | # info from cmdline are predominent
|
---|
| 33 | for i in `cat /proc/cmdline` ; do
|
---|
| 34 | echo $i | grep -qi ping= && ipcount=`echo $i | cut -d= -f2`
|
---|
| 35 | echo $i | grep -qi ipconf= && ipconf=`echo $i | cut -d= -f2`
|
---|
[2380] | 36 | echo $i | grep -qi netfsmount= && export netfsmount=`echo $i | cut -d= -f2`
|
---|
[801] | 37 | echo $i | grep -qi prefix= && export imgname=`echo $i | cut -d= -f2`
|
---|
[2380] | 38 | echo $i | grep -qi netfspath= && export dirimg=`echo $i | cut -d= -f2`
|
---|
[2255] | 39 | echo $i | grep -qi pre= && pre=`echo $i | cut -d= -f2`
|
---|
| 40 | echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
|
---|
[2380] | 41 | echo $i | grep -qi proto= && proto=`echo $i | cut -d= -f2`
|
---|
[740] | 42 | done
|
---|
| 43 |
|
---|
[1830] | 44 | if [ "$ipdev" != "" ] || [ "$ipconf" != "" ]; then
|
---|
| 45 | # Network configuration stored during archive
|
---|
| 46 | # or on cmdline so network wanted => starting it
|
---|
[740] | 47 | LogIt "Starting Network..."
|
---|
| 48 |
|
---|
[1830] | 49 | # Activate loobback
|
---|
| 50 | ifconfig lo 127.0.0.1
|
---|
[740] | 51 |
|
---|
[1830] | 52 | echo "$ipconf" | grep -q "dhcp"
|
---|
| 53 | if [ $? -eq 0 ]; then
|
---|
[740] | 54 | ipdev=`echo $ipconf | cut -d: -f1`
|
---|
[1830] | 55 | LogIt "Making DHCP request on $ipdev"
|
---|
| 56 | udhcpc -i $ipdev
|
---|
| 57 | else
|
---|
| 58 | if [ "$ipconf" != "" ]; then
|
---|
| 59 | ipdev=`echo $ipconf | cut -d: -f1`
|
---|
| 60 | ipaddress=`echo $ipconf | cut -d: -f2`
|
---|
| 61 | ipnetmask=`echo $ipconf | cut -d: -f3`
|
---|
| 62 | ipbroadcast=`echo $ipconf | cut -d: -f4`
|
---|
| 63 | ipgateway=`echo $ipconf | cut -d: -f5`
|
---|
| 64 | fi
|
---|
| 65 | LogIt "Configuring $ipdev statically ($ipaddress/$ipnetmask)"
|
---|
| 66 | ifconfig $ipdev $ipaddress netmask $ipnetmask broadcast $ipbroadcast
|
---|
| 67 | route add default gw $ipgateway
|
---|
[740] | 68 | fi
|
---|
| 69 |
|
---|
[1830] | 70 | # ping server helps waking interface up
|
---|
[2380] | 71 | LogIt "Pinging Remote server..."
|
---|
| 72 | netfs_server_ipaddr=`echo $netfsmount | cut -d: -f1 | cut -d@ -f2`
|
---|
| 73 | ping -c $ipcount $netfs_server_ipaddr
|
---|
[740] | 74 |
|
---|
[2380] | 75 | # Which is our protocol for file sharing
|
---|
| 76 | if [ "$proto" = "" ]; then
|
---|
| 77 | LogIt "No protocol specified, defaulting to NFS"
|
---|
| 78 | $proto = "nfs"
|
---|
| 79 | fi
|
---|
| 80 |
|
---|
| 81 | if [ "$proto" = "sshfs" ]; then
|
---|
| 82 | LogIt "Mounting SSHFS share ($netfsmount) on /tmp/isodir..."
|
---|
[2438] | 83 | # We need a correct console for ssh
|
---|
| 84 | ln -sf /dev/console /dev/tty
|
---|
| 85 | sshfs -o ro,StrictHostKeyChecking=no $netfsmount /tmp/isodir
|
---|
[2380] | 86 | elif [ "$proto" != "" ]; then
|
---|
| 87 | LogIt "Mounting Network share ($netfsmount) on /tmp/isodir..."
|
---|
| 88 | touch /etc/mtab
|
---|
| 89 | mount -t $proto -o nolock,ro $netfsmount /tmp/isodir
|
---|
| 90 | else
|
---|
| 91 | LogIt "Unknown protocol $proto"
|
---|
| 92 | fi
|
---|
[1830] | 93 |
|
---|
[2380] | 94 | LogIt "Mounting Remote image ${imgname}-1.iso in $dirimg on /mnt/cdrom in loopback"
|
---|
[1927] | 95 | mount -o ro,loop -t iso9660 /tmp/isodir/$dirimg/${imgname}-1.iso /mnt/cdrom
|
---|
[2253] | 96 |
|
---|
[2380] | 97 | # Save the scripts on the Network share locally
|
---|
[2255] | 98 | if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
|
---|
| 99 | cp $pre /tmp
|
---|
| 100 | LogIt "Copying $pre under /tmp"
|
---|
[2253] | 101 | fi
|
---|
[2255] | 102 | if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
|
---|
| 103 | cp $post /tmp
|
---|
| 104 | LogIt "Copying $post under /tmp"
|
---|
| 105 | fi
|
---|
[1830] | 106 | fi
|
---|