#!/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$/+dfsg2\.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-content-repository/java/PerlTools.jar" \
 --exclude "*/packages/chat/www/chat.jar" \
 --exclude "*/packages/lorsm/www/delivery-scorm/stuff.jar" \
 --exclude "*/packages/lorsm/www/delivery/stuff.jar" \
 --exclude "*/packages/acs-templating/www/resources/tinymce/jscripts/tiny_mce/plugins/media/img/flv_player.swf"
  
# Repack
tar cz -f $FILE $DIR
mv $FILE $DFSG_FILE
  
# Clean
rm -rf $DIR
