#!/bin/sh
# DocumentId:	$Id: install 2221 2006-07-05 22:35:21Z ola $
# Author:	$Author: ola $
#		Ola Lundqvist <opal@debian.org>
# Arguments:
#		$1	Destination	
#		$2	Part
# Summary:
#	Installs the tools.
#

if [ -z "$1" ] ; then
    echo "No part specified, exiting."
    exit -1
fi

if [ -z "$2" ] ; then
    echo "No part specified, exiting."
    exit -1
fi

DDATE=$(LANG=C date)
DEST="$1"
PART="$2"

cd $PART

if [ -d man ] ; then
    mkdir -p $DEST/usr/share/man/man1
    find man -name "*.pod" | {
	while read POD ; do
	    NAME=$(echo $POD | sed -e "s|.pod$||;")
	    PT=""
	    if [ ! -z "$PART" ] ; then
		PT="-$PART"
	    fi
	    echo "Generating $NAME.1"
	    pod2man --section=1 \
		--release="Dpsyco " \
		--date="$DDATE" \
		$POD > $NAME.1
	    DNAME=$(echo "$NAME" | sed -e "s|man/||;")
	    echo "Copy $NAME.1 to $DEST/usr/share/man/man1/$DNAME.1.gz"
	    gzip -c -9 $NAME.1 > $DEST/usr/share/man/man1/$DNAME.1.gz
	done
    }
fi

if [ -d conf ] ; then
    cp conf/*.conf $DEST/etc/dpsyco
fi

if [ -d src ] ; then
    find src -name "*.func" | {
	while read FILE ; do
	    mkdir -p $DEST/usr/share/dpsyco
	    cp $FILE $DEST/usr/share/dpsyco
	done
    }
    find src -name "*.test" | {
	while read FILE ; do
	    mkdir -p $DEST/usr/share/dpsyco
	    cp $FILE $DEST/usr/share/dpsyco
	done
    }
    find src -name "dpsyco-*" | {
	while read FILE ; do
	    mkdir -p $DEST/usr/bin
	    cp $FILE $DEST/usr/bin
	done
    }
    find src -name "dpsch-*" | {
	while read FILE ; do    
	    mkdir -p $DEST/usr/bin
	    cp $FILE $DEST/usr/bin
	done
    }
    find src -name "update-dpsyco*" | {
	while read FILE ; do    
	    mkdir -p $DEST/usr/sbin
	    cp $FILE $DEST/usr/sbin
	done
    }
fi
