# $Id: Portfile,v 1.4 2006/02/22 06:23:09 markd Exp $

PortSystem	1.0

name			sendpage
version			1.000001
categories		net
maintainers		markd@opendarwin.org
platforms		darwin

description		Sendpage sends alphanumeric pages via a modem, receives via SNPP

long_description	An SNPP client, SNPP server, a queuing engine, \
                        a modem control engine, a TAP communication system, \
                        and an email notification system.

homepage		http://www.sendpage.org/
					
master_sites	sourceforge
checksums		md5 4dc9115ad984408e0400241341341b99

depends_lib port:p5-net-snpp \
			port:p5-device-serialport \
			port:p5-mailtools \
			port:p5-dbi

use_configure		no
build {}

# Maintain empty directories
destroot.keepdirs	${destroot}${prefix}/var/sendpage \
					${destroot}${prefix}/var/sendpage/lock 

variant server  {
# Create a startupitem to start/stop the server
    startupitem.create    yes
    startupitem.start    "${prefix}/share/${name}/sendpage.init start"
    startupitem.stop    "${prefix}/share/${name}/sendpage.init stop"
}

pre-destroot {
        adduser sendpage
        addgroup sendpage
                
		reinplace "s|Win32|Device|g" ${worksrcpath}/Makefile.PL

		reinplace "s|/etc/sendpage.cf|${prefix}/etc/sendpage/sendpage.cf|g" ${worksrcpath}/sendpage
		reinplace "s|/var/lock|${prefix}/var/sendpage/lock|g" ${worksrcpath}/sendpage

		reinplace "s|/etc/sendpage.cf|${prefix}/etc/sendpage/sendpage.cf|g" ${worksrcpath}/sendpage.init
        reinplace "s|/var/spool|${prefix}/var|g" ${worksrcpath}/sendpage.init
        reinplace "s|/usr/local/bin|${prefix}/bin|g" ${worksrcpath}/sendpage.init

		reinplace "s|/var/spool|${prefix}/var|g" \
			${worksrcpath}/sendpage

		reinplace "s|/etc|${prefix}/etc/sendpage|g" ${worksrcpath}/snpp

		reinplace "s|#pidfileprefix = /tmp/var/spool/sendpage/sendpage| \
			pidfileprefix = ${prefix}/var/sendpage/sendpage|g" ${worksrcpath}/sendpage.cf

		reinplace "s|#lockprefix = /tmp/var/lock/LCK..| \
                        lockprefix = ${prefix}/var/sendpage/lock/LCK..|g" ${worksrcpath}/sendpage.cf

		reinplace "s|#queuedir = /tmp/var/spool/sendpage| \
                        queuedir = ${prefix}/var/sendpage|g" ${worksrcpath}/sendpage.cf
}

destroot {
		system "cd ${worksrcpath} && perl Makefile.PL"
		system "cd ${worksrcpath} && make"
		system "cd ${worksrcpath} && make install"
}

post-destroot {

# Copy sendpage configuration files
		xinstall -m 755 -d ${destroot}${prefix}/etc/sendpage
		xinstall -m 755 ${worksrcpath}/sendpage.cf ${destroot}${prefix}/etc/sendpage
		xinstall -m 755 ${worksrcpath}/email2page.conf ${destroot}${prefix}/etc/sendpage
		xinstall -m 755 ${worksrcpath}/snpp.conf ${destroot}${prefix}/etc/sendpage

# Copy sendpage documentation & examples
		xinstall -m 755 -d ${destroot}${prefix}/share/doc/sendpage
		xinstall -m 755 ${worksrcpath}/README ${destroot}${prefix}/share/doc/sendpage
		xinstall -m 755 ${worksrcpath}/FEATURES ${destroot}${prefix}/share/doc/sendpage
		xinstall -m 755 ${worksrcpath}/TODO ${destroot}${prefix}/share/doc/sendpage

		xinstall -m 755 -d ${destroot}${prefix}/share/sendpage/examples
		eval xinstall -m 755 [glob ${worksrcpath}/examples/*] ${destroot}${prefix}/share/sendpage/examples
		xinstall -m 755 ${worksrcpath}/${name}.init ${destroot}${prefix}/share/sendpage/examples

# Make the sendpage queue area
		xinstall -d ${destroot}${prefix}/var/sendpage/lock
		system "chmod og-rwx ${destroot}${prefix}/var/sendpage"
		system "chown sendpage ${destroot}${prefix}/var/sendpage" 
		system "chgrp tty ${destroot}${prefix}/var/sendpage"

		system "chown sendpage ${destroot}${prefix}/var/sendpage/lock"
		system "chgrp uucp ${destroot}${prefix}/var/sendpage/lock"

# Install sendpage start script                
		xinstall -o root -m 755 -c ${worksrcpath}/${name}.init ${destroot}${prefix}/share/${name}

}

post-install {
		ui_msg "\n
README & docs -->	${prefix}/share/doc/sendpage
Config files -->	${prefix}/etc/sendpage
Start script -->	${prefix}/share/sendpage/sendpage.init
Examples  -->		${prefix}/share/sendpage/examples\n"
}
