#!/bin/bash -x

set -e

tmp=$(mktemp -d)

trap cleanup EXIT
cleanup() {
    set +e
    [ -z "$tmp" -o ! -d "$tmp" ] || rm -rf "$tmp"
}

unset CDPATH
pwd=$(pwd)

dirname=wanderlust
pkgname=wl

cd "$tmp"
cvs -d :pserver:anonymous@cvs.m17n.org:/cvs/root checkout $dirname
cd $dirname
cat>version.el<<EOF
(load-file "elmo/elmo-version.el")
(princ (concat elmo-version "\n"))
EOF
VERSION=$(emacs --quick --script version.el 2>/dev/null)
rm -f version.el
REVISION=$(date +%Y%m%d)
find . -type d -name CVS -print0 | xargs -0r rm -rf
cd ..
mv $dirname ${pkgname}-${VERSION}
tar Jcf "$pwd"/${pkgname}-${VERSION}.cvs${REVISION}.tar.xz ${pkgname}-${VERSION}
cd ${pwd} >/dev/null

exit
