#!/bin/sh
# Remove certain files containing GPL language from the given archive
if [ $# -lt 1 ]
then
        echo "Usage: $0 phpxxx.tar.bz2, from php working directory"
        exit 1
fi
gunzip -t $1
if [ $? -ne 0 ]
then
        echo "$1 is not a gzipped file"
        exit 1
fi
ARCHIVE=$1
ARCHIVE_DIR=$(basename $ARCHIVE .tar.bz2)
TMP_DIR=$(mktemp -d /tmp/phpXXXX)
cp $ARCHIVE $TMP_DIR
pushd  $TMP_DIR
tar xfj $ARCHIVE
if [ $? -ne 0 ]
then
        echo "Could not untar $ARCHIVE"
	popd
	rm -rf "$TMP_DIR"
        exit 1
fi
pushd $ARCHIVE_DIR 
rm -rf Zend/zend_language_parser.c
rm -rf Zend/zend_language_parser.h
rm -rf Zend/zend_ini_parser.c
rm -rf Zend/zend_ini_parser.h
rm -rf sapi/phpdbg/phpdbg_parser.c
rm -rf sapi/phpdbg/phpdbg_parser.h
rm -rf pear/install-pear-nozlib.phar
rm -rf ext/phar/tests
popd
mv $ARCHIVE ${ARCHIVE}-old
COPYFILE_DISABLE=1 tar cj -f $ARCHIVE $ARCHIVE_DIR
if [ $? -ne 0 ]
then
        echo "Could not tar $ARCHIVE"
        popd 
        rm -rf "$TMP_DIR"
        exit 1
fi
pwd
ls -l
popd
mv $ARCHIVE ${ARCHIVE}-original
cp ${TMP_DIR}/$ARCHIVE .
#rm -rf "$TMP_DIR"

