#!/bin/sh
#
# Executed by uscan, repackages the upstream source removing
# all non-DFSG content.

set -e

PACKAGE=$(dpkg-parsechangelog | sed -rn '/^Source:/ {s/^Source: //; p}')
VERSION=$(echo $2)
FILE=$3
DIR="$PACKAGE-$VERSION"
DFSG_FILE=$(echo "$FILE" | sed 's/\.orig\.tar\.gz$/+dfsg\.orig\.tar\.gz/')

# Unpack
tar xzf $FILE \
 --exclude "*/packages/acs-templating/www/resources/xinha-nightly/iconsets/Tango" \
 --exclude "*/packages/acs-templating/www/resources/xinha-nightly/images/tango" \
 --exclude "*/packages/acs-templating/www/resources/tinymce/jscripts/tiny_mce/plugins/media/img/flv_player.swf" \
 --exclude "*/packages/acs-templating/www/resources/tinymce/examples/media/sample.swf" \
 --exclude "*/packages/acs-content-repository/java/PerlTools.jar" 

# Repack as DFSG
tar cz -f $FILE $DIR
mv $FILE $DFSG_FILE

# Clean
rm -rf $DIR
