#! /bin/sh
set -e

. $HOME/websync.conf

export RSYNC_PASSWORD

HOSTNAME=`hostname -f`

LOCK="${TO}/Archive-Update-in-Progress-${HOSTNAME}"

# Get in the right directory and set the umask to be group writable
#
cd $HOME
umask 002

# Check to see if another sync is in progress
if lockfile -! -l 43200 -r 0 "$LOCK"; then
  echo ${HOSTNAME} unable to start rsync, lock file exists
  exit 1
fi
trap "rm -f $LOCK > /dev/null 2>&1" exit

set +e
rsync -rltvz --delete \
	--exclude "Archive-Update-in-Progress-${HOSTNAME}" \
	--exclude "${HOSTNAME}" \
	$EXCLUDE \
	$RSYNC_USER@$RSYNC_HOST::web.debian.org $TO > rsync.log 2>&1
if [ -d ${TO}/mirror/timestamps ]; then
	date -u > "${TO}/mirror/timestamps/${HOSTNAME}" ;
fi
savelog rsync.log > /dev/null 2>&1

