# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 90388 2012-03-04 02:44:28Z ryandesign@macports.org $

PortSystem          1.0

name                pserv
version             3.4
categories          www
platforms           darwin
maintainers         nomaintainer
license             GPL-2+

description         Pico Server is a small web server.

long_description    ${description}

homepage            http://pserv.sourceforge.net/
master_sites        sourceforge:project/pserv/pserv/${version}
extract.suffix      .tar.Z

checksums           rmd160  15ee471e2c0bc0aeb897dbe2eab5271928de8fbd \
                    sha256  6a37e3056504db4e5623ce59fda95a759f7692f67dcb174ceb32d340b3441977

patchfiles          patch-main.h \
                    patch-pserv.conf

post-patch {
    reinplace "s|@PREFIX@|${prefix}|g" \
                    ${worksrcpath}/defaults/pserv.conf \
                    ${worksrcpath}/sources/main.h
}

configure.args      --bindir=${prefix}/sbin

destroot.keepdirs   ${destroot}${prefix}/var/log/pserv

set conf_files      {etc/pserv/mime_types.dat etc/pserv/pserv.conf var/www/index.html}

if {${os.platform} == "darwin" && ${os.major} > 8} {
    set pserv_user _www
} else {
    set pserv_user www
}

startupitem.create      yes
startupitem.executable  sudo -u ${pserv_user} ${prefix}/sbin/pserv

post-destroot {
    foreach conf_file ${conf_files} {
        move ${destroot}${prefix}/${conf_file} ${destroot}${prefix}/${conf_file}.sample
    }
    
    xinstall -o ${pserv_user} -g ${pserv_user} -d ${destroot}${prefix}/var/log/pserv
}

post-activate {
    foreach conf_file ${conf_files} {
        if {![file exists ${prefix}/${conf_file}]} {
            copy ${prefix}/${conf_file}.sample ${prefix}/${conf_file}
        }
    }
}
