source: MondoRescue/branches/2.2.9/mindi/rootfs/sbin/start-nfs@ 2255

Last change on this file since 2255 was 2255, checked in by Bruno Cornec, 15 years ago
  • Fix #336 by extending the previous feature to a double call (pre and post) on the boot loader line to be able to call cripts either before mondorestore and/or after its execution
  • Property svn:executable set to *
File size: 3.0 KB
Line 
1#!/bin/sh
2#
3# $Id$
4#
5# This script sets up the network + NFS environment if needed.
6#
7
8
9# number of ping
10ipcount=3
11
12# Get info from config file
13ipdev=`grep nfs-dev /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
14ipaddress=`grep nfs-client-ipaddr /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
15ipnetmask=`grep nfs-client-netmask /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
16ipbroadcast=`grep nfs-client-broadcast /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
17ipgateway=`grep nfs-client-defgw /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
18ipconf=""
19pre=""
20post=""
21export nfsmount=`grep nfs-server-mount /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
22export imgname=`grep iso-prefix /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
23if [ "$imgname" = "" ]; then
24 export imgname="mondorescue"
25fi
26export dirimg=`grep nfs-server-path /tmp/mondo-restore.cfg 2> /dev/null | cut -d' ' -f2-`
27if [ "$dirimg" = "" ]; then
28 export dirimg="/"
29fi
30
31# info from cmdline are predominent
32for i in `cat /proc/cmdline` ; do
33 echo $i | grep -qi ping= && ipcount=`echo $i | cut -d= -f2`
34 echo $i | grep -qi ipconf= && ipconf=`echo $i | cut -d= -f2`
35 echo $i | grep -qi nfsmount= && export nfsmount=`echo $i | cut -d= -f2`
36 echo $i | grep -qi prefix= && export imgname=`echo $i | cut -d= -f2`
37 echo $i | grep -qi nfspath= && export dirimg=`echo $i | cut -d= -f2`
38 echo $i | grep -qi pre= && pre=`echo $i | cut -d= -f2`
39 echo $i | grep -qi post= && post=`echo $i | cut -d= -f2`
40done
41
42if [ "$ipdev" != "" ] || [ "$ipconf" != "" ]; then
43 # Network configuration stored during archive
44 # or on cmdline so network wanted => starting it
45 LogIt "Starting Network..."
46
47 # Activate loobback
48 ifconfig lo 127.0.0.1
49
50 echo "$ipconf" | grep -q "dhcp"
51 if [ $? -eq 0 ]; then
52 ipdev=`echo $ipconf | cut -d: -f1`
53 LogIt "Making DHCP request on $ipdev"
54 udhcpc -i $ipdev
55 else
56 if [ "$ipconf" != "" ]; then
57 ipdev=`echo $ipconf | cut -d: -f1`
58 ipaddress=`echo $ipconf | cut -d: -f2`
59 ipnetmask=`echo $ipconf | cut -d: -f3`
60 ipbroadcast=`echo $ipconf | cut -d: -f4`
61 ipgateway=`echo $ipconf | cut -d: -f5`
62 fi
63 LogIt "Configuring $ipdev statically ($ipaddress/$ipnetmask)"
64 ifconfig $ipdev $ipaddress netmask $ipnetmask broadcast $ipbroadcast
65 route add default gw $ipgateway
66 fi
67
68 # ping server helps waking interface up
69 LogIt "Pinging NFS server..."
70 nfs_server_ipaddr=`echo $nfsmount | cut -d: -f1`
71 ping -c $ipcount $nfs_server_ipaddr
72
73 # Finally mounts the NFS share
74 LogIt "Mounting NFS share ($nfsmount) on /tmp/isodir..."
75 touch /etc/mtab
76 mount -t nfs -o nolock,ro $nfsmount /tmp/isodir
77
78 LogIt "Mounting NFS image ${imgname}-1.iso in $dirimg on /mnt/cdrom in loopback"
79 mount -o ro,loop -t iso9660 /tmp/isodir/$dirimg/${imgname}-1.iso /mnt/cdrom
80
81 # Save the scripts on the NFS share locally
82 if [ "`echo $pre | grep -E '^/tmp/isodir'`" ]; then
83 cp $pre /tmp
84 LogIt "Copying $pre under /tmp"
85 fi
86 if [ "`echo $post | grep -E '^/tmp/isodir'`" ]; then
87 cp $post /tmp
88 LogIt "Copying $post under /tmp"
89 fi
90fi
Note: See TracBrowser for help on using the repository browser.