[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 | ipconf=""
|
---|
[2255] | 13 | pre=""
|
---|
| 14 | post=""
|
---|
[2591] | 15 | ipdev=""
|
---|
| 16 | ipaddress=""
|
---|
| 17 | ipnetmask=""
|
---|
| 18 | ipbroadcast=""
|
---|
| 19 | ipgateway=""
|
---|
| 20 | proto=""
|
---|
| 21 | netfsmount=""
|
---|
| 22 | imgname=""
|
---|
| 23 | dirimg=""
|
---|
| 24 |
|
---|
| 25 | # Get info from config file
|
---|
| 26 | if [ -f $MINDI_CACHE/mondorestore.cfg ]; then
|
---|
| 27 | ipdev=`grep netfs-dev $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
| 28 | ipaddress=`grep netfs-client-ipaddr $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
| 29 | ipnetmask=`grep netfs-client-netmask $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
| 30 | ipbroadcast=`grep netfs-client-broadcast $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
| 31 | ipgateway=`grep netfs-client-defgw $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
| 32 | proto=`grep netfs-proto $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
| 33 | export netfsmount=`grep netfs-server-mount $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
| 34 | export imgname=`grep iso-prefix $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
| 35 | export dirimg=`grep netfs-server-path $MINDI_CACHE/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
|
---|
| 36 | fi
|
---|
| 37 |
|
---|
[740] | 38 | if [ "$imgname" = "" ]; then
|
---|
[801] | 39 | export imgname="mondorescue"
|
---|
[740] | 40 | fi
|
---|
| 41 | if [ "$dirimg" = "" ]; then
|
---|
[801] | 42 | export dirimg="/"
|
---|
[740] | 43 | fi
|
---|
| 44 |
|
---|
| 45 | # info from cmdline are predominent
|
---|
[2382] | 46 | for i in `cat $CMDLINE` ; do
|
---|
[740] | 47 | echo $i | grep -qi ping= && ipcount=`echo $i | cut -d= -f2`
|
---|
| 48 | echo $i | grep -qi ipconf= && ipconf=`echo $i | cut -d= -f2`
|
---|
[2380] | 49 | echo $i | grep -qi netfsmount= && export netfsmount=`echo $i | cut -d= -f2`
|
---|
[2499] | 50 | echo $i | grep -qi netfsopt= && export netfsopt=`echo $i | cut -d= -f2`
|
---|
[801] | 51 | echo $i | grep -qi prefix= && export imgname=`echo $i | cut -d= -f2`
|
---|
[2380] | 52 | echo $i | grep -qi netfspath= && export dirimg=`echo $i | cut -d= -f2`
|
---|
[2255] | 53 | echo $i | grep -qi pre= && pre=`echo $i | cut -d= -f2`
|
---|
| 54 | echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
|
---|
[2380] | 55 | echo $i | grep -qi proto= && proto=`echo $i | cut -d= -f2`
|
---|
[740] | 56 | done
|
---|
| 57 |
|
---|
[1830] | 58 | if [ "$ipdev" != "" ] || [ "$ipconf" != "" ]; then
|
---|
| 59 | # Network configuration stored during archive
|
---|
| 60 | # or on cmdline so network wanted => starting it
|
---|
[740] | 61 | LogIt "Starting Network..."
|
---|
| 62 |
|
---|
[1830] | 63 | # Activate loobback
|
---|
| 64 | ifconfig lo 127.0.0.1
|
---|
[740] | 65 |
|
---|
[1830] | 66 | echo "$ipconf" | grep -q "dhcp"
|
---|
| 67 | if [ $? -eq 0 ]; then
|
---|
[740] | 68 | ipdev=`echo $ipconf | cut -d: -f1`
|
---|
[2591] | 69 | dhc="/sbin/dhclient"
|
---|
| 70 | if [ ! -x $dhc ]; then
|
---|
| 71 | dhc="/sbin/dhcpcd"
|
---|
| 72 | if [ ! -x $dhc ]; then
|
---|
| 73 | dhc="/sbin/udhcpc"
|
---|
| 74 | if [ ! -x $dhc ]; then
|
---|
| 75 | dhc=""
|
---|
| 76 | else
|
---|
| 77 | dhc="$dhc -i"
|
---|
| 78 | fi
|
---|
| 79 | fi
|
---|
| 80 | fi
|
---|
| 81 | if [ -x $dhc ]; then
|
---|
| 82 | LogIt "Making DHCP request on $ipdev with $dhc"
|
---|
| 83 | $dhc $ipdev
|
---|
| 84 | else
|
---|
| 85 | LogIt "Unable to make a DHCP request on $ipdev - no client found"
|
---|
| 86 | fi
|
---|
[1830] | 87 | else
|
---|
| 88 | if [ "$ipconf" != "" ]; then
|
---|
| 89 | ipdev=`echo $ipconf | cut -d: -f1`
|
---|
| 90 | ipaddress=`echo $ipconf | cut -d: -f2`
|
---|
| 91 | ipnetmask=`echo $ipconf | cut -d: -f3`
|
---|
| 92 | ipbroadcast=`echo $ipconf | cut -d: -f4`
|
---|
| 93 | ipgateway=`echo $ipconf | cut -d: -f5`
|
---|
| 94 | fi
|
---|
| 95 | LogIt "Configuring $ipdev statically ($ipaddress/$ipnetmask)"
|
---|
| 96 | ifconfig $ipdev $ipaddress netmask $ipnetmask broadcast $ipbroadcast
|
---|
| 97 | route add default gw $ipgateway
|
---|
[740] | 98 | fi
|
---|
| 99 |
|
---|
[1830] | 100 | # ping server helps waking interface up
|
---|
[2380] | 101 | netfs_server_ipaddr=`echo $netfsmount | cut -d: -f1 | cut -d@ -f2`
|
---|
[2591] | 102 | if [ $netfs_server_ipaddr != "" ]; then
|
---|
| 103 | LogIt "Pinging Remote server $netfs_server_ipaddr ($ipcount times)..."
|
---|
| 104 | ping -c $ipcount $netfs_server_ipaddr
|
---|
| 105 | fi
|
---|
[740] | 106 |
|
---|
[2380] | 107 | # Which is our protocol for file sharing
|
---|
| 108 | if [ "$proto" = "" ]; then
|
---|
| 109 | LogIt "No protocol specified, defaulting to NFS"
|
---|
[2709] | 110 | proto="nfs"
|
---|
[2380] | 111 | fi
|
---|
| 112 |
|
---|
[2591] | 113 | if [ "$netfsmount" != "" ]; then
|
---|
| 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" != "" ]; then
|
---|
| 120 | LogIt "Mounting Network share ($netfsmount) on /tmp/isodir..."
|
---|
| 121 | touch /etc/mtab
|
---|
| 122 | mount -t $proto -o nolock,ro $netfsopt $netfsmount /tmp/isodir
|
---|
| 123 | else
|
---|
| 124 | LogIt "Unknown protocol $proto"
|
---|
| 125 | fi
|
---|
| 126 |
|
---|
| 127 | # In all these cases we should have an image
|
---|
| 128 | LogIt "Mounting Remote image ${imgname}-1.iso in $dirimg on /mnt/cdrom in loopback"
|
---|
| 129 | mount -o ro,loop -t iso9660 /tmp/isodir/$dirimg/${imgname}-1.iso /mnt/cdrom
|
---|
[2380] | 130 | else
|
---|
[2591] | 131 | LogIt "No image to mount"
|
---|
[2380] | 132 | fi
|
---|
[1830] | 133 |
|
---|
[2380] | 134 | # Save the scripts on the Network share locally
|
---|
[2255] | 135 | if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
|
---|
| 136 | cp $pre /tmp
|
---|
| 137 | LogIt "Copying $pre under /tmp"
|
---|
[2253] | 138 | fi
|
---|
[2255] | 139 | if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
|
---|
| 140 | cp $post /tmp
|
---|
| 141 | LogIt "Copying $post under /tmp"
|
---|
| 142 | fi
|
---|
[1830] | 143 | fi
|
---|