#!/bin/sh
# DocumentId:	$Id: twinspot-patch 975 2001-07-17 13:22:01Z olalu $
# Author:	$Author: olalu $
#		Ola Lundqvist <ola.lundqvist@euronetics.se>
# Date:		$Date: 2001-07-17 15:22:01 +0200 (tis, 17 jul 2001) $
# Arguments:	A list of patch files.
# Summary:
#	Patches a file structure.

if [ ! -z "PATCHDEST" ] ; then
    cd "$PATCHDEST"
fi

TF=/etc/twinspot/twinspot-patch

for PF in $*; do
    if [ ! -f $PF ] ; then
	echo "Can not find patch file $1."
    else
	echo "Autopatch using $FP."	
	FILES=$(grep "^+++ " $PF | sed -e "s|^+++ ||" | sed "s|[[:space:]].*||")
	if [ -e $TF ] ; then
	    rm -f $TF
	fi
	echo "#\!/bin/sh" > $TF
	for $FILE in $FILES ; do
	    find $FILE -prune -printf "chown %u.%g %p\nchmod %m %p\n" >> $TF
	done
	patch -s -t -T -p0 -i $PF
	if [ -e $TF ] ; then
	    chmod +x $TF
	    $TF
	    rm -f $TF
	fi
    fi
done
