#! /bin/sh -e
# Move applied patches out to pasture, and overwrite really old versions

# Delete status for this patch
del_status()
{
    rm status/${1}-*
}

KVERSION=`latest-kernel-version`

for patch in patches/*/*.patch.gz; do
    BASENAME=`basename "$patch"`
    ROOTNAME=`dirname $patch`/`basename $patch .gz`

    # If INCLUDED in current kernel, move it.
    if grep -q ':INCLUDED:' "status/${BASENAME}-${KVERSION}"; then
	echo Moving $patch out to pasture.
	scripts/old-patch.sh $patch
	del_status $BASENAME
    fi
done