#!/bin/bash
# WF 2023-03-17

#ansi colors
#http://www.csc.uvic.ca/~sae/seng265/fall04/tips/s265s047-tips/bash-using-colors.html
blue='\033[0;34m'
red='\033[0;31m'
green='\033[0;32m' # '\e[1;32m' is too bright for white bg.
endColor='\033[0m'

#
# a colored message
#   params:
#     1: l_color - the color of the message
#     2: l_msg - the message to display
#
color_msg() {
  local l_color="$1"
  local l_msg="$2"
  echo -e "${l_color}$l_msg${endColor}"
}

# error
#
#   show an error message and exit
#
#   params:
#     1: l_msg - the message to display
error() {
  local l_msg="$1"
  # use ansi red for error
  color_msg $red "Error: $l_msg" 1>&2
  exit 1
}

#
# show the usage
#
usage() {
  echo "usage: $0 [-h|--help][--ceurws]"
  echo "  -h|--help: show this usage"
  echo "  --ceurws: force getting samples for CEURWS and exit"
}

#
# get the data from CEUR-WS
#
getCEURWS() {
  color_msg $blue "getting sample data for CEUR-WS"
  cws="ceur-ws"
  if [ ! -d $cws ]
  then
    mkdir -p $cws
  fi
  cd $cws
  volno=3262
  vol="Vol-$volno"
  zip=$vol.zip
  if [ ! -d $vol ]
  then
    if [ ! -f $zip ]
    then
      wget http://sunsite.informatik.rwth-aachen.de/ftp/pub/publications/CEUR-WS/$zip
    fi
    unzip $zip
  else
    color_msg $green "$vol already downloaded"
  fi
}

while [  "$1" != ""  ]
do
  option=$1
  shift
  case $option in
    -h|--help)
      usage
      exit 0;;
 	--ceurws)
      getCEURWS
      ;;
  esac
done
