#! /bin/bash

# Call this script with the name of an eGroupWare release tarball,
# and it will build a new tarball that has CVS/SVN cruft and nonfree
# files removed.  The new tarball will be placed in the current
# directory.
#
# Written by Peter Eisentraut <petere@debian.org>, 2004-08-11
# Public domain

set -e

if [ "$1" = --upstream-version ]; then
	shift 2
fi

case x"$1"x in
	*.gzx)	taropt=z;;
	*.bz2x)	taropt=j;;
	xx)	echo "$0: specify tarball name as argument" 1>&2; exit 1;;
	*)	echo "$0: $1 does not appear to be a tarball" 1>&2; exit 1;;
esac

version=$(expr $1 : '.*eGroupWare-\(.*\).tar') || version=$(expr $1 : '.*egroupware_\(.*\).orig.tar')
version=$(echo $version | sed 's/\.rc/~rc/')
version="${version}+dfsg"

origtarname=egroupware_$version.orig.tar.gz

tmpdir=$(mktemp -d)
trap "rm -rf $tmpdir" EXIT

tar -C $tmpdir -x -$taropt -f $1
pushd $tmpdir/ >/dev/null
mv egroupware egroupware-$version
pushd egroupware-$version/ >/dev/null
rm -rf debian/					# I'd rather maintain my own ...
rm calendar/doc/rfc2445.txt			# RFC's are not DFSG-free
rm phpgwapi/inc/fpdf/tutorial/calligra.*	# doubtful copyright status
rm -rf $(find -name CVS -o -name .cvsignore -o -name .svn)	# CVS/SVN cruft
popd >/dev/null
tar -c -z -f $origtarname egroupware-$version/
popd >/dev/null
mv -i $tmpdir/$origtarname .

echo "`basename $0`: wrote \"$origtarname\""
