set -e
set -u

VER="3.0.714"
FILE="../darkstat-3.0.714.tar.bz2"
PKG="darkstat"

SUFFIX="+dfsg"

echo
echo "Repackaging $FILE"
echo

DIR=`mktemp -d ./tmpRepackXXXXXX`
DIR=$(readlink -f "$DIR")
trap "/bin/rm -rf \"$DIR\"" QUIT INT EXIT


UP_BASE="$DIR/unpack"
mkdir "$UP_BASE"
tar -xvjf "$FILE" -C /"$UP_BASE"

set -f
MYORIGPWD=$(pwd)
cd "$UP_BASE"
rm "$PKG-$VER/contrib/darkproxy.php"
tar -cvzf "$PKG-$VER$SUFFIX.orig.tar.gz" "$PKG-$VER/"
mv "$PKG-$VER$SUFFIX.orig.tar.gz" "$MYORIGPWD/../"
cd "$MYORIGPWD"

echo 
echo "done"
echo 

rm "$FILE"
rm -rf "$DIR"
