#!/bin/sh
#
# Name: ca-set-default
#
# Description:
#   Set the default CA for the grid-cert-request command
#
# 2003-09-01 Anders Waananen <waananen@nbi.dk>
#

if test "x$X509_CERT_DIR" = "x" ; then
  X509_CERT_DIR=/etc/grid-security/certificates
fi

if test "x$GRID_SECURITY_DIR" = "x" ; then
  GRID_SECURITY_DIR=/etc/grid-security
fi

if test "x$1" = "x" ; then
  echo "Usage: `basename $0` <hash>"
  exit 0
else
  CA_HASH="$1"
fi

if test "x$#" = "x1" ; then
  if cd $X509_CERT_DIR; then
    if test -f globus-host-ssl.conf.${CA_HASH} ; then
    if test -f globus-user-ssl.conf.${CA_HASH} ; then
    if test -f grid-security.conf.${CA_HASH} ; then
      ln -sf $X509_CERT_DIR/globus-host-ssl.conf.${CA_HASH} $GRID_SECURITY_DIR/globus-host-ssl.conf
      ln -sf $X509_CERT_DIR/globus-user-ssl.conf.${CA_HASH} $GRID_SECURITY_DIR/globus-user-ssl.conf
      ln -sf $X509_CERT_DIR/grid-security.conf.${CA_HASH}   $GRID_SECURITY_DIR/grid-security.conf
      exit 0
    fi
    fi
    fi
  else
    echo "Problem with security directory: $X509_CERT_DIR"
    exit 1
  fi
  echo "Problem with security files for the CA: $CA_HASH"
  exit 1
fi
