#! /bin/bash
# update-cluster-add script, coded by Junichi Uekawa
# 27 Jul 2001. 
# Copyright 2001 Junichi Uekawa
# Licensed under GPL version 2 or later.
# $Id: update-cluster-add,v 1.4 2001/08/08 02:48:39 dancer Exp $

CLUSTERXML=/etc/update-cluster/cluster.xml
CLUSTERIP=
CLUSTERHOST=
CLUSTERMAC=
CLUSTERNOTES=
CLUSTERNFSROOT=

if test -z "$1"; then
    cat <<EOF
update-cluster-add [--options] [item] ...
  Updates the cluster database, please see the manpage for detailed 
  description of what it does.

       --ip   Specifies the IP address of the added node.

       --mac  Specifies the MAC address of the added node.

       --hostname
              Specifies the hostname of the added node.

       --notes
              Adds a note for the added node, use --notes  master
              to specify that this node is the master node.

EOF
    exit 1 
fi


while test -n "$1"; do
 case "$1" in
   --ip) 
     CLUSTERIP="<ip>$2</ip>"
     shift; shift;
     ;;
   --hostname)
     CLUSTERHOST="<hostname>$2</hostname>"
     shift; shift;
     ;;
   --mac)
     CLUSTERMAC="<mac>$2</mac>"
     shift; shift;
     ;;
   --notes)
     CLUSTERNOTES="<notes>$2</notes>"
     shift; shift;
     ;;
   --nfsroot)
     CLUSTERNFSROOT="<nfsroot>$2</nfsroot>"
     shift; shift;
     ;;
   *)
    cat <<EOF
update-cluster-add [--options] [item] ...
  Updates the cluster database, please see the manpage for detailed
  description of what it does.

       --ip   Specifies the IP address of the added node.

       --mac  Specifies the MAC address of the added node.

       --hostname
              Specifies the hostname of the added node.

       --notes
              Adds a note for the added node, use --notes  master
              to specify that this node is the master node.

EOF
     exit 1 
     ;; 
 esac;  
done


REPLACEDSTRING="$CLUSTERIP$CLUSTERHOST$CLUSTERMAC$CLUSTERNOTES$CLUSTERNFSROOT"

# create a new XML file if it doesn't exist.
test -f $CLUSTERXML || cat > $CLUSTERXML << EOF 
<?xml version="1.0"?>
<!DOCTYPE cluster SYSTEM "/usr/share/update-cluster/cluster.dtd">
<cluster>
</cluster>
EOF

cat $CLUSTERXML | \
sed "s!</cluster>!  <host>$REPLACEDSTRING</host></cluster>!" | \
update-cluster-remove > $CLUSTERXML.tmp &&  \
mv $CLUSTERXML.tmp $CLUSTERXML



