#! /usr/bin/ksh
echo "Supported systems are: "
echo "          HPUX hpux    "
read mach?"Enter operating system : "
case $mach in
	hpux | HPUX)
		GAG_SYS="HPUX" 
		GILDAS_MOTIF="YES" ;;
		OS=hpux10_2
		MACH=pa7000
	*)
		echo "Unsupported system $mach" 
		exit -1;;
esac
echo $GAG_SYS
#
read dire?"Enter top directory of GILDAS software : "
echo "Checking export directory from $dire"
cd $dire; DIRE=$PWD; cd $OLDPWD; echo $DIRE;
if [[ -d $DIRE/export ]] then
    echo "Found directory $DIRE/export"
else
    echo "E-GILDAS, $DIRE/export does not exist"
    exit -1 
fi
if [[ -d $DIRE/$GAG_SYS ]] then
    echo "Found directory $DIRE/$GAG_SYS"
elif [[ -a $DIRE/$GAG_SYS ]] then
    echo "E-GILDAS, $DIRE/$GAG_SYS is not a directory"
    exit -1
else
    echo "Creating directory $DIRE/$GAG_SYS"
    mkdir $DIRE/$GAG_SYS
fi
if [[ -d $DIRE/sou ]] then
    echo "Found directory $DIRE/sou"
elif [[ -a $DIRE/sou ]] then
    echo "E-GILDAS, $DIRE/sou is not a directory"
    exit -1
else
    echo "Creating directory $DIRE/sou"
    mkdir $DIRE/sou
fi
GAG_ROOT=$DIRE/$GAG_SYS
GAG_TOP=$DIRE
GAG_DEST=$DIRE/$GAG_SYS
GAG_REF=$DIRE/sou
#
cp $DIRE/export/Makefile .
#
read paper?"Enter paper size on printer (A4 or US_LETTER) : "
case $paper in
        A4)
                GAG_PAPER_SIZE="A4" ;;
        US_LETTER)
                GAG_PAPER_SIZE="US_LETTER" ;;
        *)
                echo "Unsupported paper size $paper"
                exit -1;;
esac
echo " "
PATH=$GAG_ROOT/bin:$PATH
#
#
#
# Automatic edition of .gag.dico.gbl to define path
#
echo $GAG_REF
echo $GAG_DEST
echo $GAG_PAPER_SIZE
echo $GILDAS_MOTIF
sed -e "s?\$GAG_REF/?$GAG_REF/?g" -e "s?\$GAG_DEST/?$GAG_DEST/?g"  \
    -e "s?\$GAG_PAPER_SIZE?$GAG_PAPER_SIZE?g" \
    -e "s?\$GILDAS_MOTIF?$GILDAS_MOTIF?g" \
	$GAG_REF/bin/gag.dico.gbl > \
	toto 
#
cd $GAG_SYS
pwd
$mach=More
until [[ $mach = quit ]] do
read mach?"Enter choice (Basic, Tasks, Demo, Doc, Lib, or quit) "
case $mach in
    Basic)
	gunzip -c $GAG_TOP/GILDAS-bin-$OS-$MACH-static.gz | tar xvf -
	gunzip -c $GAG_TOP/GILDAS-pro-$OS-$MACH-static.gz | tar xvf -
	gunzip -c $GAG_TOP/GILDAS-help-$OS-$MACH-static.gz | tar xvf - ;;
    Tasks)
	gunzip -c $GAG_TOP/GILDAS-task-$OS-$MACH-static.gz | tar xvf - ;;
    Demo)
	gunzip -c $GAG_TOP/GILDAS-demo-$OS-$MACH-static.gz | tar xvf - ;;
    Doc)
	gunzip -c $GAG_TOP/GILDAS-doc-$OS-$MACH-static.gz | tar xvf - ;;
    Lib)
	gunzip -c $GAG_TOP/GILDAS-inc-$OS-$MACH-static.gz | tar xvf -
	gunzip -c $GAG_TOP/GILDAS-lib-$OS-$MACH-static.gz | tar xvf - ;;
    quit)
	echo "Quitting ... "
	exit -1 ;;
    *)
	$mach=More ;;
esac
done
#
cd $GAG_TOP
