#! /bin/sh
# Copyright (c) 1999-2005 CollabNet, Inc.  All rights reserved.

installdir="//opt/CollabNet_Subversion"
confdir="//etc/opt/CollabNet_Subversion"
datadir="//var/opt/CollabNet_Subversion"
bindir="${installdir}/bin"
docsdir="${installdir}/docs"
mandir="${installdir}/share/man"
localedir="${installdir}/share/locale"
httpdconf="${confdir}/conf/httpd.conf"
serverconf="${confdir}/conf/server"
version="1.5.0-11"

usage()
{
    cat <<EOF
Usage: collabnetsvn-config [OPTION]

Known values for OPTION are:

  --installdir          print location where CollabNet Subversion installed
  --bindir              print location where binaries are installed
  --docsdir             print location where help documents are installed
  --mandir              print location where man pages are installed
  --confdir             print location where configuration files are installed
  --datadir             print location where runtime data will be stored
  --localedir           print location where internationalization files are installed
  --httpdconf           print location of Apache httpd.conf file
  --server              print which Subversion server is configured
  --repository          print location where repositories are present
  --viewvc              exit with success if viewvc is configured
  --help		display this help and exit
  --version		output version information
  --support FEATURE     exit with success if feature is supported
 Known features: dav [yes], ssl [yes], zlib [yes], ldap [yes], dontdothat [yes]
                 

EOF

    exit $1
}

msg_to_configure()
{
  echo "CollabNet Subversion server is not yet configured." >&2
  echo "Plase run 'Configure-CollabNet-Subversion' to configure." >&2
  exit 1
}

support()
{
    if test "X$1" = "Xyes"; then
        echo "yes" >&1
	exit 0
    else
        echo "no" >&1
	exit 1
    fi
}

if test $# -eq 0; then
    usage 1
fi

while test $# -gt 0; do
    case "$1" in
    -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
    *) optarg= ;;
    esac

    case "$1" in
    --installdir)
        echo "$installdir" >&1
        ;;
    --bindir)
        echo "$bindir" >&1
        ;;
    --docsdir)
        echo "$docsdir" >&1
        ;;
    --mandir)
        echo "$mandir" >&1
        ;;
    --confdir)
        echo "$confdir" >&1
        ;;
    --datadir)
        echo "$datadir" >&1
        ;;
    --localedir)
        echo "$localedir" >&1
        ;;
    --httpdconf)
        echo "$httpdconf" >&1
        ;;
    --server)
        if [ -f "$serverconf" ]; then
          server=`cat "$serverconf" | grep "server[ ]*=[ ]*" | cut -d "=" -f 2- | sed 's/^[ ]*//'`
        fi
        if [ -z "$server" ]; then
          msg_to_configure
        else
          echo "$server" >&1
        fi
        ;;
    --repository)
        if [ -f "$serverconf" ]; then
          repository=`cat "$serverconf" | grep "repository[ ]*=[ ]*" | cut -d "=" -f 2- | sed 's/^[ ]*//'`
        fi
        if [ -z "$repository" ]; then
          msg_to_configure
        else
          echo "$repository" >&1
        fi
        ;;
    --viewvc)
        if [ -f "$serverconf" ]; then
          viewvc=`cat "$serverconf" | grep "viewvc[ ]*=[ ]*" | cut -d "=" -f 2- | sed 's/^[ ]*//'`
        fi
        if [ -n "$viewvc" ] && [ "X$viewvc" = "Xyes" ]; then
          support yes
        else
          support no
        fi
        ;;
    --version)
	echo "$version" >&1
	exit 0
	;;
    --help)
	usage 0
	;;
    --support)
	shift
	case "$1" in
  	  ssl|SSL) support yes ;;
	  zlib|ZLIB) support yes ;;
	  dav|DAV) support yes ;;
          ldap|LDAP) support yes ;;
          dontdothat|DONTDOTHAT) support yes ;;
	*) support no ;;
	esac
	;;
    *)
	usage 1 1>&2
	;;
    esac
    shift
done

exit 0
