#!/bin/bash
set -e

upload=''
islive=''
clearup=''
component='not_set'
config='/storage/app/EWS_prod/regions/EastAfrica/resources/coordinator/configs/config_EastAfrica_fc_live.json' # default
rundate=$(date '+%Y%m%d') # default today


SHORT=p:c:s:h
LONG=component:,config:,rundate:,noupload::,islive::,clearup::,help
OPTS=$(getopt -a --options $SHORT --longoptions $LONG -- "$@")
echo $OPTS
eval set -- "$OPTS"

while :
do
  case "$1" in
    -p | --component )
      component="$2"
      shift 2
      ;;
    -c | --config )
      config="$2"
      shift 2
      ;;
    -s | --rundate )
      rundate="$2"
      shift 2
      ;;
    --noupload )
      upload="--noupload"
      shift 2;
      ;;
    --islive )
      islive="--islive"
      shift 2;
      ;;
    --clearup )
      clearup="--clearup"
      shift 2;
      ;;
    -h | --help)
      "This is a launch script, example usage: runDockerEWS.sh -p Deposition -c -c /<path>/config_EastAfrica_fc_live.json -s 20220808"
      exit 2
      ;;
    --)
      shift;
      break
      ;;
    *)
      echo "Unexpected option: $1"
      ;;
  esac
done



function run_coordinator() {
    printf "component: %s\nconfig: %s\nrundate: %s\n" "$component" "$config" "$rundate"
    printf "optional args:\n%s\n" "$upload $islive $clearup"
    docker container ls;
    docker exec \
    ews_runner \
    /storage/app/EWS_prod/code/coordinator/scripts/run_Processor.sh \
    -p "$component" \
    -c "$config" \
    -s "$rundate" \
    $upload \
    $islive \
    $clearup
}

run_coordinator