#!/bin/bash -e
usage="hgdownload-copy download

Copy download files from the build server to the the download
server.  This runs on the build server and pushes to the specified download
server"

set -beEu -o pipefail
trap "echo Error: $(hostname) download copy failed >&2; exit 1" ERR
exec </dev/null

if [ $# != 1 ] ; then
    echo "wrong # args: $usage" >&2
    exit 1
fi
downloadServer="$1"

# initialize
gbRoot=/hive/data/outside/genbank
cd $gbRoot
. $gbRoot/lib/gbCommon.sh

# location of the genbank root and files on the remote build server
rsyncPort="ssh"
gbDownloadBuildDir=${gbRoot}/data/ftp
verbose=""
#verbose="-verbose"

goldenPathDir=/mirrordata/apache/htdocs/goldenPath

# 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/downloadcp/$(hostname)/run/downloadcp.lock

gbCopyDownload $verbose -rsyncPort=$rsyncPort $gbDownloadBuildDir $downloadServer $goldenPathDir

