next up previous contents
Next: updatefile.sh Up: Scripts di usability Previous: dhcpdgen.sh   Indice

confignode.sh

#!/bin/bash

if [ $# != 1 ] ; then
   echo "Usage: $0 [name]" 
   exit 1
fi

. cluster.conf

GATEWAY=$SERVER

LINE=$( cat $DHCP | grep $1 | awk {'print $2'})
if [ -z $LINE ] ||  [ $LINE != $1  ]  ; then
  echo "Don't find record in $DHCP for $1!"
  exit 1
fi
NOME=$LINE
MAC=$( cat $DHCP | grep $NOME | awk {'print $6'} | tr -d ";" )
IP=$( cat $DHCP | grep $NOME | awk {'print $8'} | tr -d ";" )

echo "Node:"
echo "  Name: $NOME"
echo "  MAC : $MAC"
echo "  IP  : $IP"
echo 
echo -n "Continue? (Return) | (CRTL+C for abort)"
read
checkfile(){
  if [ ! -e $1 ] ; then
    echo "Don't find $1!"
    exit 1
  fi
}

if [ ! -d $TFTPDIR/$NOME ] ; then
  echo "Don't find root directory for $NOME in $TFTPDIR/$NOME!"
  exit 1
fi

echo "Configure PXE..."
FILE=01-$( echo $MAC | tr ":" "-" | tr "[A-Z]" "[a-z]" )
if [ ! -e $TFTPDIR/$KERNEL ] ; then
  echo "Don't kernel in $TFTPDIR/$KERNEL!"
  exit 1
fi
if [ ! -d $TFTPDIR/pxelinux.cfg/ ] ; then
  echo "Don't find PXE config directory!"
  exit 1
fi 

for i in $( ls $TFTPDIR/pxelinux.cfg/ ) ; do
  if [  $TFTPDIR/pxelinux.cfg/$FILE != $TFTPDIR/pxelinux.cfg/$i ] ; then
    if [ ! -z $( cat $TFTPDIR/pxelinux.cfg/$i | grep $NOME \
                    | awk {'{print $1}'} ) ] &> /dev/null ; then
      echo "Find another PXE file for $NOME $i... delete!"
      rm -f $TFTPDIR/pxelinux.cfg/$i
    fi
  fi
done

echo "LABEL  linux
KERNEL $KERNEL
APPEND root=/dev/nfs ip=dhcp  
                  nfsroot=$SERVER:/tftpboot/$NOME 
                  init=/sbin/init
" >  $TFTPDIR/pxelinux.cfg/$FILE

ROOT="$TFTPDIR/$NOME"

echo "Configure fstab..."
checkfile $ROOT/etc/fstab

echo "
$SERVER:/tftpboot/$NOME  /nfs       defaults      1 0
$SERVER:/usr             /usr       nfs  defaults 1 0
$SERVER:/usr/local       /usr/local nfs  defaults 1 0
$SERVER:/root            /root      nfs  defaults 1 0
$SERVER:/home            /home      nfs  defaults 1 0
/dev/hda1                /data      ext3 defaults 1 1
none                     /proc      proc defaults 0 0
" > $ROOT/etc/fstab

echo "Configure eth0..."

echo "DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=$IP
NETMASK=255.255.255.0
GATEWAY=$GATEWAY
" > $ROOT/etc/sysconfig/network-scripts/ifcfg-eth0

echo "Configure Hostname..."
checkfile $ROOT/etc/sysconfig/network

echo "NETWORKING=yes
HOSTNAME=$NOME
" > $ROOT/etc/sysconfig/network

echo "Make /etc/hosts for $NOME..."
echo "127.0.0.1 localhost.localdomain localhost l$NOME
$SERVER $MASTER
" >  $ROOT/etc/hosts
cat $DHCP | grep host | awk {'print $8" "$2" g"$2'}\
                    | tr -d ";" >>  $ROOT/etc/hosts
echo

echo "Configure services..."
rm -fr $ROOT/etc/rc3.d/* $ROOT/etc/rc0.d/* $ROOT/etc/rc6.d/*

for i in $SERVICE_START ; do
  nome=$( echo $i | cut -b 4- )
  if [ ! -e $ROOT/etc/init.d/$nome ] ; then
    echo
    echo "Service $i not available for start!"
  else
    ( cd $ROOT/etc/rc3.d ; ln -s ../init.d/$nome $i )
  fi
done

( cd $ROOT/etc/rc3.d ; ln -s ../rc.local S99local )

for i in $SERVICE_STOP ; do
  nome=$( echo $i | cut -b 4- )
   if [ ! -e $ROOT/etc/init.d/$nome ] ; then
     echo
     echo "Service $i not available for shutdown!"
    else
      ( cd $ROOT/etc/rc0.d ; ln -s ../init.d/$nome $i )
      ( cd $ROOT/etc/rc6.d ; ln -s ../init.d/$nome $i )
    fi
done
( cd $ROOT/etc/rc0.d ; ln -s ../init.d/halt S01halt )
( cd $ROOT/etc/rc6.d ; ln -s ../init.d/halt S01reboot )

echo "Done."
exit 0



Mario Cavicchi 2004-07-22