#!/bin/sh
# .COPYRIGHT: Copyright (c) 2009-2011 European Southern Observatory,
#                                         all rights reserved
# 
# .AUTHOR         Klaus Banse
# 
# 090428	creation
# 111206	last modif
#
# get Midas demo data
# which are needed for the full set of verifications 
# as well as the Midas tutorials
# and create dir. demo/data in $MIDASHOME, e.g. in /midas
# 
# $./getdemodata x
# will only download the tarfile with the data and not install 
# 
here=$(pwd)
# 
# get the demo data from ESO's ftp server
# into current dir.
# 
# sometimes the local ftp client and the ftp server at ESO's
# ftp.eso.org don't really work together 
# then, use another ftp client, e.g. ncftp or lftp (without -n)
#                               =>   ncftp  ftp.eso.org << END
# 
ftp -n  ftp.eso.org << END
user ftp ftp
cd midaspub
cd demo_data
get demo_data.tar.gz
quit
END

if [ "$1" = "x" ]; then
   echo "only downloaded demo_data.tar.gz"
   exit
fi

# now, move to $MIDASHOME
if [ -z "$MIDASHOME" ]; then		#check for zero length
   echo MIDASHOME not defined...
   echo enter location for the demo data, usually the home dir. of Midas
   echo defaulted to "~/midas"
   read answ
   if [ -z "$answ" ]; then
      direc="$HOME/midas"
   else
      direc="$answ"
   fi
else
   direc="$MIDASHOME"
fi
cd $direc

if [ -d demo/data ]; then
   echo "subdirs ./demo/data already exist - overwrite existing data?"
   echo "continue [YES/no]?"
   read answ
   if [ -z "$answ" ]; then
      answ=YES
   else
      if [ "$answ" = "no" -o "$answ" = "NO" ]; then
         echo "nothing to be done"
         echo "ensure that env. var. MID_TEST = $direc/demo/data ..."
         exit 
      fi
   fi
   echo "deleting all files in ./demo/data/ "
   rm  ./demo/data/*
else
   echo "create subdirs ./demo/data"
   mkdir -p demo/data
fi

cd ./demo/data
pwd

# untar the file 

echo "tar -zxvf $here/demo_data.tar.gz"
tar -zxvf $here/demo_data.tar.gz
echo " "
echo "all demo data stored in $(pwd)" 
# 
echo "ensure that env. var. MID_TEST = $direc/demo/data ..."

# come back
cd $here

