#!/bin/bash -e

# Script to copy new processed and aligned from the build server to the this
# server (euronode server) This polls to determine if an alignment has been done
# since the last time files were downloaded.  Remote file access is by rsync.

set -e  # errors terminate
trap "echo Error: $(hostname) copy failed >&2; exit 1" ERR
exec </dev/null

# location of the genbank root and files on the remote build server

gbBuildServer=hgwdev.sdsc.edu
rsyncCommand="udr rsync"
rsyncPort="ssh"
rsyncOpts="-ra"

gbBuildRoot=/hive/data/outside/genbank
gbRoot=/data/genbank
cd $gbRoot

# update the etc, bin, and lib directories
gbRRServer=hgnfs1.soe.ucsc.edu
gbRRRoot=/genbank
rsync $rsyncOpts $gbRRServer:$gbRRRoot/etc $gbRRServer:$gbRRRoot/bin $gbRRServer:$gbRRRoot/lib .

. $gbRoot/lib/gbCommon.sh
databases=$(gbGetDatabases etc/hgwbeta.dbs etc/rr.dbs)

# local location of /gbdb
gbdb=/data/gbdb


# Checking for an existing lock file, Silently exits if lock file exists
# and is less than one day old,  error if older.
gbCheckLock $gbRoot/var/copy/run/copy.lock

gbCopyStep -rsyncCommand="$rsyncCommand" -rsyncPort=$rsyncPort -gbdb=$gbdb $gbBuildServer $gbBuildRoot $databases

# we don't put put a completed message, as gbCopyStep does the checking.
