#! /bin/bash
# @(#)(CAcert) $Id: $
# rsync-tarballs - script to rsync tarballs from www.cacert.org to test servers

SRCHOST=webdb			# use alias configured in ~/.ssh/config
SRCDIR=/home/cacert/www/tarballs

DSTHOST=test.cacert.org		# cacert1
DSTDIR=/home/cacert/www/tarballs

DSTHOST2=test2.cacert.org	# cacert2
DSTDIR2=/root/chroot/spec/distro

DSTHOST3=cacert3		# special ssh port in .ssh/config
DSTDIR3=/root/chroot/spec/distro

TMPDIR=/tmp/tmp-$$/

test -r ~/bin/ssh-check && . ~/bin/ssh-check

# Because we cannot do a direct rsync from remote to remote,
# we will use sshfs to make one of the remote sides look local

mkdir ${TMPDIR}
echo "sshfs ${SRCHOST}:${SRCDIR} ${TMPDIR}"
sshfs ${SRCHOST}:${SRCDIR} ${TMPDIR}

echo "rsync from ${TMPDIR} to ${DSTHOST}:${DSTDIR}"
rsync -e ssh --verbose --archive --delete-after ${TMPDIR} ${DSTHOST}:${DSTDIR}

echo "rsync from ${TMPDIR}current.tar.bz2 to ${DSTHOST}:${DSTDIR2}/www.tar.bz2"
rsync -e ssh --verbose --copy-links ${TMPDIR}/current.tar.bz2 ${DSTHOST}:${DSTDIR2}/www.tar.bz2

echo "rsync from ${TMPDIR}current.tar.bz2 to ${DSTHOST2}:${DSTDIR2}/www.tar.bz2"
rsync -e ssh --verbose --copy-links ${TMPDIR}/current.tar.bz2 ${DSTHOST2}:${DSTDIR2}/www.tar.bz2

echo "rsync from ${TMPDIR}current.tar.bz2 to ${DSTHOST3}:${DSTDIR2}/www.tar.bz2"
rsync -e ssh --verbose --copy-links ${TMPDIR}/current.tar.bz2 ${DSTHOST3}:${DSTDIR2}/www.tar.bz2

fusermount -u ${TMPDIR}
rmdir ${TMPDIR}