#!/bin/sh
more <<"EOF"

-------------------------------------------------------------
Dies ist das Installations-Script 
fuer GEONExT unter Linux.

Copyright 2002 Lehrstuhl fr Mathematik und ihre Didaktik
der Universitt Bayreuth.
-------------------------------------------------------------

EOF

geonextname="geonext"

###########################################################################
#  java suchen
###########################################################################
echo "Suche Java JRE ..."
echo
echo
javalocation=`which java`
echo "Der Standardaufruf von java startet folgende Version:"
`java -version`

agreed=
while [ x$agreed = x ]; do
    echo
	 echo "Sie bentigen mindestens Version 1.4.0 "
    echo "Wo ist ihr ausfhrbarer Java-Interpreter? [$javalocation] "
    read reply leftover
    if [ -z $reply ] ; then
	 		reply=$javalocation
	 fi
	 
    if [ -x $reply ] ; then
            agreed=1
				javalocation=$reply
      		echo "$javalocation gefunden..."
				echo
				echo
    else				
      echo "Bitte geben Sie einen gltigen Pfad an";
    fi				
done

echo "Sie haben folgende Java-Version gewhlt:"
`$javalocation -version`

###########################################################################
#  GEONExT-Verzeichnis bestimmen
###########################################################################

geonextlocation="/usr/local/geonext"
agreed=
while [ x$agreed = x ]; do
    echo
    echo "Wo wollen Sie GEONExT? installieren? [$geonextlocation] "
    read reply leftover
    if [ -z $reply ] ; then
		reply=$geonextlocation
	 fi
	 geonextlocation=$reply
	 
    if [ ! -d $geonextlocation ] ; then
   	echo "$geonextlocation existiert nicht, versuche es zu erstellen..."
		echo
		echo
		mkdir -p $geonextlocation
		if [ ! -d $geonextlocation ] ; then
   		echo "Sie haben keine Berechtigung $geonextlocation zu erstellen..."
   		echo "Sie bentigen Superuser-Rechte..."
			echo 
			echo "Installations-Script wird beendet."
			exit
		else
	      agreed=1
		fi
    else				
      echo "Das Verzeichnis $geonextlocation wurde gefunden...";
		echo
		echo
		if [ ! -w $geonextlocation ] ; then
   		echo "Sie haben keine komplette Schreibberechtigung fr das Verzeichnis $geonextlocation..."
   		echo "Sie bentigen Superuser-Rechte..."
			echo 
			echo "Installations-Script wird beendet."
			exit
		fi
		touch $geonextlocation/$geonextname
		if [ ! -f $geonextlocation/$geonextname ] ; then
   		echo "Sie haben keine Schreibberechtigung fr das Verzeichnis $geonextlocation..."
   		echo "Sie bentigen Superuser-Rechte..."
			echo 
			echo "Installations-Script wird beendet."
			exit
		else
	      agreed=1
		fi
    fi				
done


###########################################################################
#  geonext-Script erzeugen
###########################################################################

echo
echo
echo "Erzeuge das Shell-Script geonext...";
echo "#!/bin/sh" >$geonextlocation/$geonextname
echo "$javalocation -cp $geonextlocation/geonext.jar geonext/Geonext &" >$geonextlocation/$geonextname
###########################################################################
#  Dateien kopieren
###########################################################################
chmod a+x $geonextlocation/$geonextname
cp  geonext.jar $geonextlocation
cp  geonext-batik.jar $geonextlocation
cp  x.ico $geonextlocation
cp  geonext.html $geonextlocation
cp  didmat.crt $geonextlocation
cp  index.html $geonextlocation
cp  ubt.gif $geonextlocation
cp  gxt.gif $geonextlocation
cp  license.txt $geonextlocation
cp  cacerts $geonextlocation
cp  geoint.png $geonextlocation
cp  help.jar $geonextlocation
cp  help_fr.jar $geonextlocation
cp  help_de.jar $geonextlocation
cp  help_it.jar $geonextlocation
cp  help_uk.jar $geonextlocation
###########################################################################
#  geonext-Script erzeugen
###########################################################################

agreed=
while [ x$agreed = x ]; do
    echo
    echo "Wollen Sie einen symbolischen Verweis in /usr/local/bin erzeugen? [yes or no] "
    read reply leftover
    case $reply in
        y* | Y*)
            agreed=1;;
        n* | n*)
	 echo "Installations erfolgreich beendet."
	 echo "Sie knnen GEONExT mit dem Befehl geonext starten."
    exit 1;;
    esac
done

localbin="/usr/local/bin"
###########################################################################
#  Symbolischer Link
###########################################################################
ln -fs $geonextlocation/$geonextname $localbin/$geonextname
if [ ! -L $localbin/$geonextname ] ; then
 		echo "Sie haben keine Schreibberechtigung fr das Verzeichnis $localbin..."
  		echo "Sie bentigen Superuser-Rechte..."
		echo 
		echo "Installations-Script wird beendet."
		exit
fi
###########################################################################
#  Ende
###########################################################################
echo
echo "Installations erfolgreich beendet."
echo "Sie knnen GEONExT mit dem Befehl geonext starten."
