-#!/bin/sh
-
-# Creates debian and system-independent archive files
-# Programmer: Kevin Rosenberg based on script used by onShore Development
+#!/bin/bash
+# Creates debian and upstream packages
+# Programmer: Kevin Rosenberg
set -e
-VERSION=`cat VERSION`
DEBPKG=cl-uffi
PKG=uffi
TOPDIR=`basename $PWD`
+VERSION=`cat VERSION`
+DEBVERSION=`sed -n -e "s/${DEBPKG} (\(.*\)).*/\1/p" < debian/changelog |head -1`
+
DISTDIR=${PKG}-${VERSION}
DEBDIR=${DEBPKG}-${VERSION}
-TAG=upstream_version_`echo $VERSION | tr . _`
-echo "(re)tagging with release tag '$TAG'"
-cvs -q rtag -d $TAG $PKG
-cvs -q tag -F $TAG
+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
-# build the tarball
-echo "building tarballs"
+# Prepare for archive
cd ..
rm -f ${PKG}_${VERSION}.tar.gz ${DEBPKG}_${VERSION}.orig.tar.gz
rm -rf ${DISTDIR} ${DEBDIR} ${DISTDIR}.zip
cp -a ${TOPDIR} ${DISTDIR}
-# Remove junk from distribution dir
-find ${DISTDIR} -type f -name .cvsignore -exec rm {} \;
-find ${DISTDIR} -type d -name CVS | xargs rm -r
-find ${DISTDIR}/doc -type f -name \*.tex -or -name \*.aux -or \
- -name \*.log -or -name \*.out -or -name \*.dvi -or \
- -name \*~ -or -name .\#\* -or -name \#*\# |xargs rm -f
+echo "Cleaning distribution directory ${DISTDIR}"
+find ${DISTDIR} -type f -name .cvsignore -exec rm -f {} \;
+rm -rf `find ${DISTDIR} -type d -name CVS`
+rm -f `find ${DISTDIR} -type f -name '*~' -or -name '#*' -or -name '#*#'`
+rm -f `find ${DISTDIR}/doc -type f -name \*.tex -or -name \*.aux -or \
+ -name \*.log -or -name \*.out -or -name \*.dvi -or -name copy`
-# Create original distribution archives
+echo "Creating upstream archives"
rm -rf ${DISTDIR}/debian
GZIP=-9 tar czf ${DISTDIR}.tar.gz ${DISTDIR}
cp -a ${DISTDIR} ${DEBDIR}
-rm -f ${DEBDIR}/debian/.cvsignore
GZIP=-9 tar czf ${DEBPKG}_${VERSION}.orig.tar.gz ${DEBDIR}
-find ${DISTDIR} -type f -and -name \*.cl -or -name \*.list -or \
+unix2dos `find ${DISTDIR} -type f -name \*.cl -or -name \*.list -or \
-name \*.system -or -name Makefile -or -name ChangeLog -or \
- -name COPYRIGHT -or -name TODO -or -name README -or -name INSTALL \
- -or -name NEWS -or -name \*.sgml -or -name COPYING\* -or -name catalog \
- | xargs unix2dos
+ -name COPYRIGHT -or -name TODO -or -name README -or -name INSTALL -or \
+ -name NEWS -or -name \*.sgml -or -name COPYING\* -or -name catalog`
zip -rq ${DISTDIR}.zip ${DISTDIR}
cp -a ${TOPDIR}/debian ${DEBDIR}
+rm -f ${DEBDIR}/debian/.cvsignore
+rm -rf ${DEBDIR}/debian/CVS
-cd ${DEBDIR}
-dpkg-buildpackage -rfakeroot -kkevin@b9.com -a
-
-cd ..
-rm -rf ${DEBDIR}
rm -rf ${DISTDIR}
-lintian ${DEBPKG}_${VERSION}-*.changes
+export CVS_BUILDPACKAGE=1
+if [ "${CVS_BUILDPACKAGE}" != "" ]; then
+ rm -rf ${DEBDIR}
+ mv ${DEBPKG}_${VERSION}.orig.tar.gz /usr/local/src/Packages/${DEBPKG}
+else
+ cd ${DEBDIR}
+ echo "Building Debian files"
+ dpkg-buildpackage -rfakeroot -kkevin@rosenberg.net -a
+ echo "Checking Debian Files"
+ lintian ${DEBPKG}_${VERSION}-*.changes
+
+ echo "Moving Debian Files to /usr/local/src/Packages/${DEBPKG}"
+ mkdir -p /usr/local/src/Packages/${DEBPKG}
+ mv ${DEBPKG}_${VERSION}* /usr/local/src/Packages/${DEBPKG}
+ cd ..
+ rm -rf ${DEBDIR}
+fi
-mkdir -p /usr/local/share/Packages/${DEBPKG}
-mv ${DEBPKG}_${VERSION}* /usr/local/share/Packages/${DEBPKG}
cd ${TOPDIR}
+
exit 0