#!/bin/bash

# This script is used to delete from the current directory tree the
# font files that are provided by other packages in Debian.

# It is intented to be used against the font tarball from
# ftp://ftp.texmacs.org/pub/TeXmacs/fonts/TeXmacs-windows-fonts-1.0-noarch.tar.gz
# to remove from it the font files that are already in Debian.

# as the first argument, it takes the name of a Contents file.

#             -- René van Bevern <rvb@debian.org>

CONTENTS_FILE="$1"

find . -name '*.pfb' -o -name '*.tfm' | cut -c 3- | while read FONT; do
    BASENAME=$(basename $FONT)
    if (grep "$BASENAME" $CONTENTS_FILE); then
	rm $FONT
    fi
done

# now remove empty directories

find . -type d -depth | while read DIR; do
    rmdir --ignore-fail-on-non-empty "$DIR"
done
