#!/bin/bash

if [ -d /proj/nlpl ]; then
  host="taito";
  root="/proj/nlpl";
elif [ -d /cluster/shared/nlpl ]; then
  host="saga";
  root="/cluster/shared/nlpl";
fi

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.vectors.uio.${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/vectors/ oe@ps.hpc.uio.no:/usit/ps/nlpl/data/vectors/;
  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 11 -o $(date "+%u") -eq 1 ]; then
  grep -v " is uptodate" ${log} | mailx -r oe@ifi.uio.no -s "cron(8): data/vectors update to uio" infrastructure@nlpl.eu;
fi