#!/bin/sh
# DocumentId:	$Id: dpsch-gendepends,v 1.1 2002/03/11 22:05:24 ola Exp $
# Author:	$Author: ola $
#		Ola Lundqvist <opal@debian.org>
# Summary:
#	Create substvars for dpsyco automaticly.

if [ ! -z "$1" ] ; then
    echo "USAGE: dpsch-gendepends"
fi

if [ ! -d debian ] ; then
    echo "No debian dir, exiting."
    exit 0
fi

if [ ! -e debian/control ] ; then
    echo "No debian control file, exiting."
    exit 0
fi

genstr() {
    TMPL=""
    TMPD=""
    if [ ! -z "$1" ] ; then
	TMPL="${1}."
	TMPD="$1"
    fi
    SEP=""
    STR=""
    if [ -e "debian/${TMPL}skel" -o -e "debian/${TMPL}userskel" ] ; then
	STR="${STR}${SEP}dpsyco-skel (>= 1.0.8)"
	SEP=", "
    fi
    if [ -e "debian/${TMPL}groups" -o -e "debian/${TMPL}users" ] ; then
	STR="${STR}${SEP}dpsyco-base (>= 1.0.8)"
	SEP=", "
	if [ ! -z "$(find debian/$TMPL/usr/share/dpsyco/users -name '*.pub' 2> /dev/null)" ] ; then
	    STR="${STR}${SEP}dpsyco-ssh (>= 1.0.8)"
	    SEP=", "
	fi
    fi
    if [ -e "debian/${TMPL}patch" -o -e "debian/${TMPL}userpatch" ] ; then
        STR="${STR}${SEP}dpsyco-patch (>= 1.0.8)"
        SEP=", "
    fi
    if [ -e "debian/${TMPL}cfengine" ] ; then
        STR="${STR}${SEP}dpsyco-cfengine (>= 1.0.8)"
        SEP=", "
    fi
    if ls debian/$TMPD/etc/cron-apt/action.d/* > /dev/null 2>&1 ; then
        STR="${STR}${SEP}cron-apt (>= 0.0.2)"
        SEP=", "
    fi
    if [ ! -z "$STR" ] ; then
        touch "debian/${TMPL}substvars"
	if echo "$STR" | grep dpsyco > /dev/null 2>&1 ; then
	    echo "dpsyco:Depends=dpsyco-lib (>= 1.0.8), dpsyco-lib (<= 1.1.0), $STR" >> "debian/${TMPL}substvars"
	else
	    echo "dpsyco:Depends=$STR" >> "debian/${TMPL}substvars"	    
	fi
    fi
}

dpsch-listbinpkgs | {
    while read TMPL ; do
	genstr $TMPL
    done
}

genstr

