source: branches/3.2/mindi/rootfs/usr/sbin/start-netfs @ 3433

Last change on this file since 3433 was 3433, checked in by bruno, 4 years ago
  • Fix the move of NIC when booting with PXE and that the card was renumbered (useing only uppercases MAC addresses for comparison)
  • Property svn:executable set to *
File size: 5.1 KB
RevLine 
[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
10ipcount=3
11
12# Get info from config file
[3271]13ipdev=`grep netfs-dev /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
[3433]14# MAC address in uppercases
15hwaddr=`grep netfs-client-hwaddr /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2- | perl -nle 'print uc;'`
[3271]16ipaddress=`grep netfs-client-ipaddr /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
17ipnetmask=`grep netfs-client-netmask /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
18ipbroadcast=`grep netfs-client-broadcast /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
19ipgateway=`grep netfs-client-defgw /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
20proto=`grep netfs-proto /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
21iproute=`grep netfs-route /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
[740]22ipconf=""
[2255]23pre=""
24post=""
[3271]25export netfsmount=`grep netfs-server-mount /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
26export imgname=`grep iso-prefix /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
[740]27if [ "$imgname" = "" ]; then
[801]28    export imgname="mondorescue"
[740]29fi
[3278]30export dirimg=`grep iso-dir /tmp/mondorestore.cfg 2> /dev/null | cut -d' ' -f2-`
[740]31if [ "$dirimg" = "" ]; then
[801]32    export dirimg="/"
[740]33fi
34
35# info from cmdline are predominent
36for i in `cat /proc/cmdline` ; do
37    echo $i | grep -qi ping= && ipcount=`echo $i | cut -d= -f2`
[3433]38    echo $i | grep -qi hwaddr= && hwaddr=`echo $i | cut -d= -f2  | perl -nle 'print uc;'`
[740]39    echo $i | grep -qi ipconf= && ipconf=`echo $i | cut -d= -f2`
[2380]40    echo $i | grep -qi netfsmount= && export netfsmount=`echo $i | cut -d= -f2`
[2498]41    echo $i | grep -qi netfsopt= && export netfsopt=`echo $i | cut -d= -f2`
[801]42    echo $i | grep -qi prefix= && export imgname=`echo $i | cut -d= -f2`
[2380]43    echo $i | grep -qi netfspath= && export dirimg=`echo $i | cut -d= -f2`
[2255]44    echo $i | grep -qi pre= && pre=`echo $i | cut -d= -f2`
45    echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
[2380]46    echo $i | grep -qi proto= && proto=`echo $i | cut -d= -f2`
[3168]47    echo $i | grep -qi iproute= && iproute=`echo $i | cut -d= -f2`
[740]48done
49
[1830]50if [ "$ipdev" != "" ] || [ "$ipconf" != "" ]; then
51    # Network configuration stored during archive
52    # or on cmdline so network wanted => starting it
[740]53    LogIt "Starting Network..."
54
[1830]55    # Activate loobback
56    ifconfig lo 127.0.0.1
[740]57
[1830]58    echo "$ipconf" | grep -q "dhcp"
59    if [ $? -eq 0 ]; then
[740]60        ipdev=`echo $ipconf | cut -d: -f1`
[1830]61        LogIt "Making DHCP request on $ipdev"
62        udhcpc -i $ipdev
63    else
64        if [ "$ipconf" != "" ]; then
65            ipdev=`echo $ipconf | cut -d: -f1`
66            ipaddress=`echo $ipconf | cut -d: -f2`
67            ipnetmask=`echo $ipconf | cut -d: -f3`
68            ipbroadcast=`echo $ipconf | cut -d: -f4`
69            ipgateway=`echo $ipconf | cut -d: -f5`
70        fi
[2887]71
72        # If same system, map to the right MAC address
[3271]73        if [ "$hwaddr" != "" ]; then
[3433]74            hwaddr_found=`ifconfig $ipdev | grep HWaddr | awk '{print $NF}' | perl -nle 'print uc;'`
[3271]75            if [ "$hwaddr" != "$hwaddr_found" ]; then
[3433]76                ipdev_new=`ifconfig -a | grep -i $hwaddr | awk '{print $1}'`
[3271]77                if [ "$ipdev_new" != "" ]; then
[3433]78                    LogIt "Interface with MAC address $hwaddr changed from $ipdev to $ipdev_new"
79                    LogIt "Using $ipdev_new for network configuration from now on"
[3271]80                    ipdev=$ipdev_new
81                else
82                    LogIt "NOTE: Interface $ipdev kept despite it doesn't match the $hwaddr MAC address"
83                fi
[2887]84            fi
85        fi
86
[1830]87        LogIt "Configuring $ipdev statically ($ipaddress/$ipnetmask)"
88        ifconfig $ipdev $ipaddress netmask $ipnetmask broadcast $ipbroadcast
89        route add default gw $ipgateway
[2887]90
[740]91    fi
92
[3168]93    # Leave time to the stack to wake up (reported by some users)
[2887]94    sleep 5
95
[3168]96    # Handle a potential static route
97    if [ _"$iproute" != _"" ]; then
98        iproute=`echo $iproute | perl -pi -e 's|:| |g'`
99        LogIt "Adding static route with route add $iproute"
100        route add $iproute
101    fi
102
[1830]103    # ping server helps waking interface up
[2380]104    LogIt "Pinging Remote server..."
105    netfs_server_ipaddr=`echo $netfsmount | cut -d: -f1 | cut -d@ -f2`
106    ping -c $ipcount $netfs_server_ipaddr 
[740]107
[2380]108    # Which is our protocol for file sharing
109    if [ "$proto" = "" ]; then
110        LogIt "No protocol specified, defaulting to NFS"
[2709]111        proto="nfs"
[2380]112    fi
113
114    if [ "$proto" = "sshfs" ]; then
115        LogIt "Mounting SSHFS share ($netfsmount) on /tmp/isodir..."
[2438]116        # We need a correct console for ssh
117        ln -sf /dev/console /dev/tty
[2498]118        sshfs -o ro,StrictHostKeyChecking=no $netfsopt $netfsmount /tmp/isodir
[3111]119    elif [ "$proto" = "smbfs" ]; then
120        LogIt "Mounting SMBFS share ($netfsmount) on /tmp/isodir..."
[3279]121        mount -t cifs $netfsmount /tmp/isodir -o ro $netfsopt 
[2380]122    elif [ "$proto" != "" ]; then
[2951]123        if [ -x /sbin/rpcbind ]; then
[3271]124            echo "Starting rpcbind daemon..."
[3261]125            /sbin/rpcbind -w &
[2951]126        fi
[2380]127        LogIt "Mounting Network share ($netfsmount) on /tmp/isodir..."
128        touch /etc/mtab
[2498]129        mount -t $proto -o nolock,ro $netfsopt $netfsmount /tmp/isodir
[2380]130    else
131        LogIt "Unknown protocol $proto"
132    fi
[1830]133   
[2380]134    LogIt "Mounting Remote image ${imgname}-1.iso in $dirimg on /mnt/cdrom in loopback"
[1927]135    mount -o ro,loop -t iso9660 /tmp/isodir/$dirimg/${imgname}-1.iso /mnt/cdrom
[2253]136
[2380]137    # Save the scripts on the Network share locally
[2255]138    if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
139        cp $pre /tmp
140        LogIt "Copying $pre under /tmp"
[2253]141    fi
[2255]142    if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
143        cp $post /tmp
144        LogIt "Copying $post under /tmp"
145    fi
[1830]146fi
Note: See TracBrowser for help on using the repository browser.