# $Id: Portfile 86303 2011-10-24 12:26:54Z ryandesign@macports.org $
PortSystem		1.0

name			anacron
version	 		2.3
revision		3
categories		sysutils
maintainers		nomaintainer
description		Schedules periodic jobs on systems that are not permanently up
long_description	Anacron is a periodic command scheduler. It executes \
					commands at intervals specified in days. Unlike \
					cron, it does not assume that the system is running \
					continuously.
platforms		darwin
homepage		http://sourceforge.net/projects/anacron
master_sites	sourceforge:project/anacron/anacron/${version}
checksums		md5 865cc1dfe1ed75c470d3e6de13763f03

patchfiles		patch-Makefile patch-README patch-anacron.8 patch-anacrontab.5 patch-gregor.c
post-patch {
	file copy ${filespath}/obstack.c ${filespath}/obstack.h \
		${workpath}/${worksrcdir}/
}

use_configure		no

build.args			PREFIX=${prefix}

destroot.args		PREFIX=${destroot}${prefix}
destroot.keepdirs	${destroot}${prefix}/etc/cron.daily \
					${destroot}${prefix}/etc/cron.weekly \
					${destroot}${prefix}/etc/cron.monthly \
					${destroot}${prefix}/var/spool/anacron
post-destroot {
	xinstall -m 755 ${filespath}/run-parts ${destroot}${prefix}/bin/
	reinplace "s|__PREFIX|${prefix}|g" \
		${destroot}${prefix}/share/man/man8/anacron.8
	reinplace "s|__PREFIX|${prefix}|g" \
		${destroot}${prefix}/share/man/man5/anacrontab.5
	xinstall -m 0644 ${filespath}/anacrontab.sample \
		${destroot}${prefix}/etc/anacrontab-dist
	reinplace "s|__PREFIX|${prefix}|g" \
		${destroot}${prefix}/etc/anacrontab-dist
	xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}
	xinstall -m 0644 -W ${worksrcpath} ChangeLog COPYING README TODO \
		${destroot}${prefix}/share/doc/${name}
	reinplace "s|__PREFIX|${prefix}|g" \
		${destroot}${prefix}/share/doc/${name}/README

	# Create startup rc script (if non-Darwin)
	if {${os.platform} != "darwin"} {
		xinstall -d -m 0755 ${destroot}${prefix}/etc/rc.d
		xinstall -m 755 -c ${filespath}/anacron.sh \
			${destroot}${prefix}/etc/rc.d/
		reinplace "s|__PREFIX|${prefix}|g" \
			${destroot}${prefix}/etc/rc.d/anacron.sh
	}
}

post-activate {
	# If no anacrontab already installed, copy sample file
	if {![file exists ${prefix}/etc/anacrontab]} {
		xinstall -m 0644 ${prefix}/etc/anacrontab-dist ${prefix}/etc/anacrontab
	}
}

platform darwin {
	startupitem.create			yes
	startupitem.name			Anacron
	startupitem.start			"\[ -n \"`grep anacron /etc/crontab`\" \] \\"
	startupitem.start-append	"\t|| echo \"10  *  *  *  *  root  ${prefix}/sbin/anacron -s\" >>/etc/crontab"
	startupitem.start-append	"${prefix}/sbin/anacron -s"
	startupitem.stop			"/usr/bin/killall -SIGUSR1 anacron"
}

