#!/bin/sh

PRODUCTNAME=`echo ${1} | grep -i news\ extra`
if [ ! -z "${PRODUCTNAME}" ]; then
    PRODUCT="newsextra"
    DIRPATH="blackmagic news extra"
fi

if [ -z "${PRODUCTNAME}" ]; then
    PRODUCTNAME=`echo ${1} | grep -i blackmagic`
    if [ ! -z "${PRODUCTNAME}" ]; then
	PRODUCT="blackmagic"
	DIRPATH="Serendipity Blackmagic"
    fi
fi

if [ -z "${PRODUCTNAME}" ]; then
    PRODUCTNAME=`echo ${1} | grep -i megarip`
    if [ ! -z "${PRODUCTNAME}" ]; then
	PRODUCT="megarip"
	DIRPATH="Serendipity Megarip"
    fi
fi

if [ -z "${PRODUCTNAME}" ]; then
    PRODUCTNAME=`echo ${1} | grep -i veripress`
    DIRPATH="Veripress"
    if [ ! -z "${PRODUCTNAME}" ]; then
	PRODUCT="veripress"
	DIRPATH="Veripress"
    fi
fi

if [ -z "${PRODUCTNAME}" ]; then
    PRODUCTNAME=`echo ${1} | grep -i primojet`
    if [ ! -z "${PRODUCTNAME}" ]; then
	PRODUCT="primojet"
	DIRPATH="FFGS PRIMOJET"
    fi
fi

PRODUCTDIR="${2}/${DIRPATH}"

# copy testprints
SOURCEDIR="${1}/../../testprn"
DESTDIR="${PRODUCTDIR}/lib/testprints"
if [ ! -d "$DESTDIR" ]; then
    echo "Could not find product installation directory $DESTDIR"
    exit 0
fi

if [ -d "$SOURCEDIR" ]; then
    if [ -d "$DESTDIR" ]; then
	cd "$SOURCEDIR"
	cp -pf * "$DESTDIR"
    fi
fi


# copy any canon related plugins
SOURCEDIR="${1}/../../extras/canon"
DESTDIR="${PRODUCTDIR}/lib/canon"
if [ -d "$SOURCEDIR" ]; then
    if [ -d "$DESTDIR" ]; then
	cd "$SOURCEDIR"
	cp -RpfX * "$DESTDIR"
    fi
fi

# copy any epson related plugins
SOURCEDIR="${1}/../../macosx/epson"
DESTDIR="${PRODUCTDIR}/lib/epson"
if [ -d "$SOURCEDIR" ]; then
    if [ -d "$DESTDIR" ]; then
	cd "$SOURCEDIR"
	cp -RpfX * "$DESTDIR"
    fi
fi


#cleanup any ._ files
if [ -d "${PRODUCTDIR}" ]; then
    cd "${PRODUCTDIR}"
    if [ $? != 0 ]; then
	echo "Cannot change directory to ${PRODUCTDIR}"
	exit 0
    fi
    find . -name '._*' |
    (
	while  { read i; }
	do
	    rm -f "$i"
	done
    )
    find . -name '.AppleDouble' |
    (
	while  { read i; }
	do
	    rm -rf "$i"
	done
    )
fi


