#!/bin/bash

. $(dirname $0)/../../prologue.sh

if [ -z "${host}" ]; then
  echo "unable to locate NLPL project directory; exit."
  exit 1;
fi

start=$(date "+%y-%m-%d-%H:%M");
log="${root}/operation/log/${host}/data.translation.saga.${start}";

{
  echo -n "starting rsync(1) at "; date "+%y-%m-%d (%H:%M:%S)"; echo;
  rsync -rlptgHvvz --delete --chmod=g-w,o-w -e ssh ${root}/data/translation/ oe@saga.sigma2.no:/cluster/shared/nlpl/data/translation/;
  echo; echo -n "completed rsync(1) at "; date "+%y-%m-%d (%H:%M:%S)";
} > ${log} 2>&1

if [ $(grep -v " is uptodate" ${log} | wc -l) -gt 12 -o $(date "+%u") -eq 1 ]; then
  grep -v " is uptodate" ${log} | ${mail} -s "cron(8): data/translation update to saga" infrastructure@nlpl.eu yves.scherrer@helsinki.fi
fi