#! /bin/bash
# This file is autogenerated
# update-cluster-add script, coded by Junichi Uekawa
# 27 Jul 2001. 
# Copyright 2001,2003 Junichi Uekawa
# Licensed under GPL version 2 or later.
# $Id: update-cluster-add.in,v 1.8 2003/10/26 04:21:31 dancer Exp $

TEXTDOMAIN=update-cluster
TEXTDOMAINDIR=/usr/share/locale

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

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.
       
       --bootmaster
              specify the bootmaster IP.


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;
	    ;;
	--bootmaster)
	    CLUSTERBOOTMASTER="<bootmaster>$2</bootmaster>"
	    shift; shift;
	    ;;
	--clusterxml)
	    CLUSTERXML="$2"
	    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.
       
       --bootmaster
              specify the bootmaster IP.


EOF
	    exit 1 
	    ;; 
    esac;  
done


REPLACEDSTRING="$CLUSTERIP$CLUSTERHOST$CLUSTERMAC$CLUSTERNOTES$CLUSTERNFSROOT${CLUSTERBOOTMASTER}"

# 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



exit 0
