File cripple_source.sh of Package openbabel

#!/bin/bash

REMOVE_DIRS=(
windows-vc2005
)

set -o errexit

CMDNAME=${0##*/}
SOURCEDIR=${0%$CMDNAME}

BASENAME=${1%.tar.bz2}

trap "rm -rf  \"$BASENAME-crippled.tar\" \"$BASENAME-crippled.tar.bz2\"" ERR

for (( N=0 ; N<${#REMOVE_DIRS[@]} ; N++ )) ; do
    #REMOVE_DIRS[N]="$BASENAME/${REMOVE_DIRS[N]}"
    # use a wildcard because VirtualBox-1.6.0-OSE != VirtualBox-1.6.0_OSE
    REMOVE_DIRS[N]="*/${REMOVE_DIRS[N]}"
done

cd "$SOURCEDIR" >/dev/null

if ! test -f "$BASENAME.tar.bz2" ; then
    exit 0
fi

if test -f "$BASENAME-crippled.tar.bz2" ; then
    if test "$BASENAME.tar.bz2" -ot "$BASENAME-crippled.tar.bz2" ; then
	if test $CMDNAME -ot "$BASENAME-crippled.tar.bz2" ; then
	    exit 0
	fi
    fi
fi

cp -a "$BASENAME.tar.bz2" "$BASENAME-crippled.tar.bz2"
bunzip2 "$BASENAME-crippled.tar.bz2"
tar --wildcards --delete -f "$BASENAME-crippled.tar" "${REMOVE_DIRS[@]}"
bzip2 "$BASENAME-crippled.tar"