-TAG=upstream_version_`echo $VERSION | tr . _`
-echo "(re)tagging with release tag '$TAG'"
-#cvs -q rtag -d $TAG $PKG
-#cvs -q tag -F $TAG
-
-
-# build the tarball
-echo "building tarballs"
+if [ -z ${opt_dpkg_buildpackage} ]; then
+ export CVSROOT=`cat CVS/Root`
+fi
+
+if [ ! -z ${opt_tag} ]; then
+ DEB_TAG=debian_version_`echo ${DEBVERSION} | tr . _`
+ UPSTREAM_TAG=upstream_version_`echo ${VERSION} | tr . _`
+ echo "(Re-)tagging with Debian tag '${DEB_TAG}'"
+ cvs -q rtag -d ${DEB_TAG} ${PKG} > /dev/null
+ cvs -q tag -F ${DEB_TAG} > /dev/null
+
+ # Retag with upstream tag if release not 0 or 1
+ if [ "`echo ${DEBVERSION} | egrep '\-0$\-1$]'`" != "" ]; then
+ echo "(Re-)tagging with Upstream tag '${UPSTREAM_TAG}'"
+ cvs -q rtag -d $UPSTREAM_TAG $PKG > /dev/null
+ cvs -q tag -F $UPSTREAM_TAG > /dev/null
+ fi
+fi
+# Prepare for archive