#!/bin/sh
# vim:set sw=4 ts=4:
# $Id: get_alice_config,v 1.13 2005/04/11 14:14:34 fabian Exp $
#
#############################################################################
#
# ALICE
# Automatic Linux Installation and Configuration Environment
#
# Copyright (c) 2000-2002 SuSE Linux Solutions AG, Eschborn, Germany
#               2002-2004 SuSE Linux AG, Eschborn, Germany
#               2005           SUSE GmbH, Nuernberg, Germany
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#############################################################################
#
# Author: 
#
# ALICE
# Automatic Linux Installation and Configuration Environment
#
#############################################################################
#
# Copyright (c) 2000 SuSE Linux Solutions AG, Eschborn, Germany
# All rights reserved.
#
# This file is part of ALICE, which was sponsored by
# T-Online International AG
#
# Author: Fabian Herschel
#
#############################################################################
#
# NOTES:
#        The CVSROOT comes either from the environment or from
#        the comand line ( --cvs_root= )
#        ALICE_HOME also comes either from the environment or
#        from the command line 
#        RELEASE is either "Prod" or defined in the command line
#
#############################################################################
#
ALICE_REPOSITORY=""
if [ -z "$ALICE_RELEASE" ]
then
    ALICE_RELEASE=Prod
fi
while [ $# -gt 0 ]
do
      case $1 in
         --cvs_root=* )
                        CVSROOT=${1#--cvs_root=}
                        ;;
         --cvsroot=* )
                        CVSROOT=${1#--cvsroot=}
                        ;;
         --cvs_root | --cvsroot )
                        CVSROOT=$2; shift
                        ;;
         --release=* )  
                        ALICE_RELEASE=${1#--release=}
                        ;;
         --release )    ALICE_RELEASE=$2; shift
                        ;;
         --alice_home=* )
                        ALICE_HOME=${1#--alice_home=}
                        ;;
         --alicehome=* )
                        ALICE_HOME=${1#--alicehome=}
                        ;;
         --alice_home | --alicehome )
                        ALICE_HOME=$2; shift
                        ;;
         --repository=* )
                        ALICE_REPOSITORY=${1#--repository}
                        ;;
         --repository )
                        ALICE_REPOSITORY=$2; shift
                        ;;

         * )
                 echo "unknown parameter $1" >&2
                 echo "usage: $0 --cvs_root=... --release=... --alice_home=..." >&2
                 exit 2
                 ;;
      esac
      shift
done
if [ -z "$ALICE_HOME" ]
then
   echo "ERROR: ALICE_HOME is not set"
   echo "Try to set ALICE_HOME by --alice_home="
   exit 2
fi
#CVSROOT=/space/CVS
#CVSROOT=${server}:${CVS_DIR}  
CVS_RSH=ssh
CVS_SERVER=cvs

export CVSROOT CVS_RSH CVS_SERVER ALICE_HOME ALICE_RELEASE

cd $ALICE_HOME
isitalice=$(basename $(pwd))
if [ -z "$ALICE_REPOSITORY" ]
then
   ALICE_REPOSITORY=$isitalice
fi

#if [ $isitalice = "ALICE" -o $isitalice = "alice" ]
if echo $isitalice | egrep -q "(alice|ALICE)(\$|_[a-zA-Z0-9]+\$)"
then
   rm -rf cfg info templates classes
   cd ..
   cvs export -r $ALICE_RELEASE ${ALICE_REPOSITORY}/{info,classes,templates} 
else
        echo "Error: ALICE_HOME is wrong" >&2
        echo "Error: ALICE_HOME must match /.../alice, /.../ALICE or /.../alice_[a-zA-Z0-9]+" >&2
        exit 2
fi                
