#!/bin/sh
# fkr, jberry, yeled
# checks out both HEAD and then the svn url specified in $RELEASE_URL_FILE
# made for sampson 2006-08-30
# TODO should clean up after itself.
# TODO shouldn't refer to the Tag as "dp1.0"
# TODO stop using darwinports -> macports?
#

set -e

SVN=/usr/bin/svn
DPROOT="/Volumes/src2/darwinports"
REPO_BASE=http://svn.macports.org/repository/macports
RELEASE_URL_FILE="base/config/RELEASE_URL"

# Check out HEAD
TMPDIR=dp
if [ -d ${DPROOT}/${TMPDIR}.tmp ]; then
	$SVN update ${DPROOT}/${TMPDIR}.tmp
else
	$SVN checkout ${REPO_BASE}/trunk ${DPROOT}/${TMPDIR}.tmp
fi
rsync -q --exclude=.svn -a --delete ${DPROOT}/${TMPDIR}.tmp/ ${DPROOT}/${TMPDIR}/
echo `date -u +%s` > ${DPROOT}/${TMPDIR}/TIMESTAMP

# Extract the release URL from HEAD
read RELEASE_URL < ${DPROOT}/${TMPDIR}/${RELEASE_URL_FILE}
[ -n ${RELEASE_URL} ] || { echo "no RELEASE_URL specified in svn HEAD" ; exit 1; }

# Checkout from the release tag specified in HEAD
TMPDIR=dp1.0
if [ -d ${DPROOT}/${TMPDIR}.tmp ]; then
	$SVN switch ${RELEASE_URL} ${DPROOT}/${TMPDIR}.tmp
else
	$SVN checkout ${RELEASE_URL} ${DPROOT}/${TMPDIR}.tmp
fi
rsync -q --exclude=.svn -a --delete ${DPROOT}/${TMPDIR}.tmp/ ${DPROOT}/${TMPDIR}/
echo `date -u +%s` > ${DPROOT}/${TMPDIR}/TIMESTAMP
