
INSTALLDIR=`pwd`/myinstalldir

rm -rf .verificatum_* verificatum-* $INSTALLDIR


# Make list of versions that should be considered.
for MIDDLE in `seq 0 2`;
do
   for MINOR in `seq 2 20`; 
   do
      VERSIONS="1.$MIDDLE.$MINOR $VERSIONS"
   done
done

printf "Finding latest version..."
# Find the latest version of distribution.
for VERSION in $VERSIONS;
do
   wget --quiet http://www.verificatum.com/download/verificatum-full-$VERSION.tar.gz
   if test -e verificatum-full-$VERSION.tar.gz;
   then
      break
   fi
done
printf "done."

# Unpack, build and install.
tar xvf verificatum-full-$VERSION.tar.gz
cd verificatum-full-$VERSION
./configure --prefix=$INSTALLDIR
make
make install

# Copy bash script that sets environment variables.
cp .verificatum_env ~/
source .verificatum_env

# Create script that sets environment variables using csh syntax
# (translate bash script).
echo 'if ! $?CLASSPATH then 
   setenv CLASSPATH
endif
if ! $?LD_LIBRARY_PATH then 
   setenv LD_LIBRARY_PATH
endif
if ! $?LIBRARY_PATH then 
   setenv LIBRARY_PATH
endif' > ~/.verificatum_env_csh

cat .verificatum_env | sed s/"export"/"setenv"/ | sed s/"="/" "/ >> ~/.verificatum_env_csh

# Initialize random source.
vog -rndinit RandomDevice /dev/urandom

