#!/bin/sh
# DocumentId:	$Id: twinspot-patch,v 1.1 2001/07/17 13:20:45 olalu Exp $
# Author:	$Author: olalu $
#		Ola Lundqvist <ola.lundqvist@euronetics.se>
# Date:		$Date: 2001/07/17 13:20:45 $
# 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
