#!/bin/sh

# This script adds a new virtual server from the command line
# It's designed for ISPs who might need to create a lot of servers


usage()
{
  echo
  echo "Deletes a virtual server"
  echo "Usage: $0 '<servername>'"
  echo
  exit
}



if [ $# -ne 1  ]
then
  usage
fi

# Take the arguments
NAME=$1


# check ZEUSHOME is set
if [ -z "$ZEUSHOME" ]
then
  echo "Please set \$ZEUSHOME to point to the directory under which Zeus applications are installed"
  exit 1
fi

if [ ! -d $ZEUSHOME/webadmin ]
then
    echo "This script should only be run on machines with the webadmin package on"
    exit 1
fi

if [ -f $ZEUSHOME/webadmin/conf/runningsites/$NAME ]
then
   echo "Server is currently running, please stop it first."
   echo "Server was NOT deleted"
   exit 1
fi


CONFFILE=$ZEUSHOME/webadmin/conf/sites/$NAME

if [ ! -f $CONFFILE ]
then
   echo "Server $NAME does not exist"
   exit 1
fi


rm -f $CONFFILE

if [ $? -ne 0 ]
then
  echo "Error deleting file $CONFFILE"
  exit 1
fi

echo "Server $NAME deleted successfully"
