#!/bin/csh 
unset noclobber
setenv VERSION MAR99
echo 'Welcome to the GILDAS Installer for version '"$VERSION".
echo "Supported systems are : hpux aix osf1 solaris linux-pmac linux-intel"
echo "Enter operating system : "
set mach=($<)
switch ( $mach )
case	hpux:
	setenv	GAG_SYS "hpux" 
	setenv  GILDAS_MOTIF "YES"
	setenv  OS "hpux10_2"
 	setenv  MACH "pa7000"
		breaksw
case	aix:
	setenv	GAG_SYS "aix" 
	setenv  GILDAS_MOTIF "YES"
	setenv  OS "aix"
	setenv  MACH "rs6000"
		breaksw
case	osf1:
	setenv	GAG_SYS "osf1" 
	setenv  GILDAS_MOTIF "YES"
	setenv  MACH "alpha"
	setenv  OS "osf1"
		breaksw

case	solaris:
	setenv	GAG_SYS "solaris" 
	setenv  GILDAS_MOTIF "NO"
	setenv  MACH "sun"
	setenv  OS "solaris2_5"
		breaksw

case	linux-pmac:
	setenv	GAG_SYS "linux-pmac"
	setenv  GILDAS_MOTIF "YES"
        setenv  MACH "pmac"
	setenv  OS "linux"
		breaksw

case	linux-intel:
	setenv	GAG_SYS "linux-intel"
	setenv  GILDAS_MOTIF "YES"
        setenv  MACH "intel"
	setenv  OS "linux"
	        breaksw
default:
		echo "Unsupported system $mach" 
		exit -1
		breaksw
endsw

#on ksh, REPLY is the default in case the user simply strikes <return>
setenv REPLY $cwd
setenv OLDPWD $cwd
echo -n "Enter directory where gzipped archives are stored: "
set export=($<)

if ( -d $export ) then
    cd $export;    setenv EXPORT $cwd; 
    cd $OLDPWD; 
    echo "Found directory $EXPORT"
    else
    echo "E-GILDAS, $export does not exist"
    exit -1 
endif

setenv REPLY $cwd
echo -n "Enter base directory of GILDAS software: "
set dire=($<)
if ( -d $dire ) then
    cd $dire; setenv DIRE $cwd; cd $OLDPWD;
    echo "Found directory $DIRE"
else
    echo "F-GILDAS, $dire does not exist, exiting."
    exit -1 
endif
# test presence of GAG_SYS. can be explicitely Overriden by USER, who may want
# to install in a more complicated structure (system+version by example)

echo "I am about to rebuild the software in the default location:"
echo "$DIRE/$GAG_SYS (eventually creating directory $GAG_SYS)"
setenv reply Y
echo -n "Is that naming OK [Y or N]? "
set reply=($<)
if ( "$reply" == "Y" || "$reply" == "y" ) then
if ( -d $DIRE/$GAG_SYS ) then
    echo "Found directory $DIRE/$GAG_SYS"
#elif ( -a $DIRE/$GAG_SYS ) then
#    echo "F-GILDAS, $DIRE/$GAG_SYS is not a directory"
#    exit -1
else
    echo "Creating directory $DIRE/$GAG_SYS"
    mkdir $DIRE/$GAG_SYS
endif
else
setenv GAG_SYS $VERSION
echo "Please enter another directory name"
set GAG_SYS=($<)
if ( -d $DIRE/$GAG_SYS ) then
    echo "Found directory $DIRE/$GAG_SYS"
#elif ( -a $DIRE/$GAG_SYS ) then
#    echo "F-GILDAS, $DIRE/$GAG_SYS is not a directory"
#    exit -1
else
    echo "Creating directory $DIRE/$GAG_SYS"
    mkdir $DIRE/$GAG_SYS
endif
endif
# now we know the structure.
setenv GAG_ROOT $DIRE
# this may not exist. ah well. it is not my fault 
# if the structure is soooo complicated. For installs of binaries, everything
# goes (or MUST go, I hould say) into GAG_DEST.
setenv GAG_REF $DIRE/$GAG_SYS
setenv GAG_DEST $DIRE/$GAG_SYS
#
echo "Enter paper size on printer (A4 or US_LETTER) : "
set paper=($<)
switch ( $paper )
case    A4:
case    a4:
        setenv GAG_PAPER_SIZE "A4" 
        breaksw
case    US_LETTER:
case    us_letter:
        setenv GAG_PAPER_SIZE "US_LETTER" 
	beaksw
default:
        echo "Unsupported paper size $paper, using A4."
        setenv GAG_PAPER_SIZE "A4" 
endsw
echo " "
#
cd $GAG_DEST
setenv mach More
echo " ---------------------------------------------------------------"
echo "You are ready to install the software. You can install:"
echo " Basic: binaries in $GAG_DEST/bin, "
echo "        procedures in $GAG_DEST/pro "
echo "        and Help files in $GAG_DEST/help"
echo " Tasks: Additional tasks (binaries in $GAG_DEST/task)"
echo " Demo:  Some demo files in $GAG_DEST/demo"
echo " Doc:   The Postscript documentation in $GAG_DEST/doc"
echo " Lib:   The libraries/include files of the GILDAS package"
echo " ---------------------------------------------------------------"
while (1)
echo "Enter choice (basic, tasks, demo, doc, lib, all or quit) "
echo "(all means 'everything except libraries and include files')"
set mach=($<)
switch ( $mach )
case    all:
case    ALL:
	gunzip -c $EXPORT/GILDAS-bin-$OS-$MACH-$VERSION.tar.gz | tar xvf -
	gunzip -c $EXPORT/GILDAS-task-$OS-$MACH-$VERSION.tar.gz | tar xvf - 
	gunzip -c $EXPORT/GILDAS-pro-$VERSION.tar.gz | tar xvf -
	gunzip -c $EXPORT/GILDAS-help-$VERSION.tar.gz | tar xvf - 
	gunzip -c $EXPORT/GILDAS-demo-$VERSION.tar.gz | tar xvf - 
	gunzip -c $EXPORT/GILDAS-doc-$VERSION.tar.gz | tar xvf - 
		breaksw
case basic:
case BASIC:
	gunzip -c $EXPORT/GILDAS-bin-$OS-$MACH-$VERSION.tar.gz | tar xvf -
	echo "Updating the dictionary file $GAG_DEST/bin/.gag.dico.gbl"
	gunzip -c $EXPORT/GILDAS-pro-$VERSION.tar.gz | tar xvf -
	gunzip -c $EXPORT/GILDAS-help-$VERSION.tar.gz | tar xvf -
	breaksw
case tasks:
case TASKS:
case task:
case TASK:
	gunzip -c $EXPORT/GILDAS-task-$OS-$MACH-$VERSION.tar.gz | tar xvf - 
	breaksw
case Demo:
case demo:
case DEMO:
	gunzip -c $EXPORT/GILDAS-demo-$VERSION.tar.gz | tar xvf - 
	breaksw
case Doc:
case doc:
case DOC:
	gunzip -c $EXPORT/GILDAS-doc-$VERSION.tar.gz | tar xvf - 
	breaksw
case Lib:
case lib:
case LIB:
	gunzip -c $EXPORT/GILDAS-include-$OS-$MACH-$VERSION.tar.gz | tar xvf -
	gunzip -c $EXPORT/GILDAS-lib-$OS-$MACH-$VERSION.tar.gz | tar xvf - 
	breaksw
case UpdateDico:
case updatedico:
	echo "Updating the dictionary file $GAG_DEST/bin/.gag.dico.gbl"
	sed -e s%\$GILDAS_VERSION/%$VERSION/%g\;s%\$GAG_REF/%$GAG_REF/%g\;s%\$GAG_DEST/%$GAG_DEST/%g\;s%\$GAG_PAPER_SIZE%$GAG_PAPER_SIZE%g\;s%\$GILDAS_MOTIF%$GILDAS_MOTIF%g \
	$GAG_DEST/bin/gag.dico.gbl > $GAG_DEST/bin/.gag.dico.gbl
	breaksw
case quit:
case QUIT:
default:
    echo "Updating the dictionary file $GAG_DEST/bin/.gag.dico.gbl"
# temporary patch (I hope) for version mar99: 
#    sed -e s%November-1998%\$GILDAS_VERSION%g 
# end patch
    sed -e s%November-1998%$VERSION%g\;s%\$GILDAS_VERSION%$VERSION%g\;s%\$GAG_REF/%$GAG_REF/%g\;s%\$GAG_DEST/%$GAG_DEST/%g\;s%\$GAG_PAPER_SIZE%$GAG_PAPER_SIZE%g\;s%\$GILDAS_MOTIF%$GILDAS_MOTIF%g \
    $GAG_DEST/bin/gag.dico.gbl > $GAG_DEST/bin/.gag.dico.gbl
    echo "----------------------------------------------------------------------"
echo "----------------------------------------------------------------------"
echo "Please note that users MUST have"
echo "$GAG_REF/bin" 
echo "in their path to be able to use the GILDAS software."
echo " "
echo "You may want to check the contents of the dictionary file:"
echo "  $GAG_REF/bin/.gag.dico.gbl"
echo "and create a local dictionary file $GAG_REF/bin/.gag.dico.lcl to \
further tailor the local implementation."
echo "You MUST also check and tailor the file:"
echo "  $GAG_REF/bin/GreGPLOT"
echo "To be able to send correctly hardcopies to your local printers..."
echo "Quitting..."
    exit -1
    breaksw
endsw
end
#








