#!/bin/sh
# DocumentId:	$Id: dpsch-installcronapt,v 1.1 2002/03/11 22:05:24 ola Exp $
# Author:	$Author: ola $
#		Ola Lundqvist <opal@debian.org>
# Arguments:	
# Summary:
#	Install a system cron-apt file to a package.

. /etc/dpsyco/defaults.conf

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

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

dpsch-listbinpkgs | {
    while read PKG ; do
	if [ -e debian/$PKG.cron-apt ] ; then
	    mkdir -p debian/$PKG/etc/cron-apt
	    touch debian/$PKG/etc/cron-apt/action.d/$PKG
	    cat debian/$PKG.cron-apt >> debian/$PKG/etc/cron-apt/action.d/$PKG
	    touch debian/$PKG/DEBIAN/connfiles
	    if ! grep "/etc/cron-apt/action.d/$PKG" debian/$PKG/DEBIAN/conffiles > /dev/null 2>&1 ; then
		echo  "/etc/cron-apt/action.d/$PKG" >> debian/$PKG/DEBIAN/conffiles
	    fi
	fi
    done
}

dpsch-showfirstbinpkg | {
    while read PKG ; do
	if [ -e debian/cron-apt ] ; then
	    mkdir -p debian/$PKG/etc/cron-apt
	    touch debian/$PKG/etc/cron-apt/action.d/$PKG
	    cat debian/cron-apt >> debian/$PKG/etc/cron-apt/action.d/$PKG
	    if ! grep "/etc/cron-apt/action.d/$PKG" debian/$PKG/DEBIAN/conffiles > /dev/null 2>&1 ; then
		echo  "/etc/cron-apt/action.d/$PKG" >> debian/$PKG/DEBIAN/conffiles
	    fi
	fi
    done
}
