#!/bin/sh

if [ -e /usr/local/etc/cvsup/update.sh ]; then
	if [ "$(id -u)" != "0" ]; then
		echo "You need to run /usr/local/etc/cvsup/update.sh as root"
		echo "Re-execing through su"
		exec su root -c "exec $0 $1"
	else
		echo "This is a cvsup mirror - running /usr/local/etc/cvsup/update.sh"
		(/usr/local/etc/cvsup/update.sh && \
			echo ">>> cvsup done - please press Ctrl-C") &
		sleep 3
		tail -100000 -f /var/log/cvsup.log
		exit 0
	fi
fi
umask 2
export CVSROOT=$(dirname $(which $0))
if [ "x$1" != "x" ]
then
  HOST=$1
else
  HOST=cvsup.freebsd.org
fi

if [ "x$2" != "x" ]
then
  COLLECTION=$2
  # Interesting alternatives:
  # openbsd-cvs-all (from cvsup.de.freebsd.org)
  # cvs-all
  # src-sys
  # ports-all
else
  COLLECTION='cvs-all cvs-crypto'
fi

cd $CVSROOT
date
echo "Updating CVS tree: ${CVSROOT}"
time /usr/local/bin/cvsup -g -L2 /dev/fd/0 <<EOF
# Comments here

*default host=$HOST

${COLLECTION} release=cvs base=${CVSROOT} prefix=${CVSROOT} delete old use-rel-suffix
EOF

date
