#!/bin/sh

PROGNAME=`basename "$0"`

if [ "$1" = '--help' ] || [ ! "$1" ] || [ ! -e "$1" ] ; then
    cat 1>&2 <<EOF
Usage: $PROGNAME <package location>

Search for package declarations in the given package, overwriting the Control
file for the package with an updated version.
EOF
    exit 1
fi

PACKAGE="$1"

# Obtain the existing Control file and extract the non-provides fields.

grep -v '^provides: ' "$PACKAGE/Control" > _non_provides.tmp

# Search for package declarations and build provides fields.

grep PC_FILENAME -r "$PACKAGE" | cut -d'=' -f 2 | sort -u | sed 's/^ /provides: /' > _provides.tmp

# Concatenate the files and overwrite the Control file.

cat _provides.tmp _non_provides.tmp > "$PACKAGE/Control"

# Remove the temporary files.

rm _provides.tmp _non_provides.tmp
