# -*- 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$

PortSystem          1.0

name                fetch-crl
version             3.0.8
categories          security
maintainers         nikhef.nl:dennisvd
description         Download tool for Certificate Revocation Lists
homepage            http://wiki.nikhef.nl/grid/FetchCRL3
platforms           darwin
master_sites        http://dist.eugridpma.info/distribution/util/fetch-crl3/
distfiles           ${name}-${version}.tar.gz \
                    org.eugridpma.fetch-crl.plist

checksums           sha256 9f65ea0f9bece8817f2b211536d2f805c022d2e661e6bf7a910322f16bb303fb \
                    rmd160 849559332c5d34c9a58150a1383cafe77d2cdc62

use_configure       no

destroot.destdir    PREFIX=${destroot}${prefix} ETC=${destroot}${prefix}/etc CACHE=${destroot}${prefix}/var/cache

post-build {
    # update the prefix used in the plist file
    file copy ${filespath}/org.eugridpma.fetch-crl.plist ${worksrcpath}
    reinplace "s!/opt/local!${prefix}!g" org.eugridpma.fetch-crl.plist

    # update the standard config file
    reinplace "s!/etc!${prefix}/etc!" fetch-crl.cnf
    system "echo 'statedir ${prefix}/var/cache/fetch-crl' >> ${worksrcpath}/fetch-crl.cnf"
}

post-destroot {
    # install the plist file
    file mkdir ${destroot}${prefix}/etc/LaunchDaemons
    xinstall ${worksrcpath}/org.eugridpma.fetch-crl.plist ${destroot}${prefix}/etc/LaunchDaemons/
    file mkdir ${prefix}/var/cache/fetch-crl
}

post-activate {
    # symlink the plist file and start with launchctl
    ln -s ${prefix}/etc/LaunchDaemons/org.eugridpma.fetch-crl.plist /Library/Launchdaemons/
    system "launchctl load /Library/LaunchDaemons/org.eugridpma.fetch-crl.plist"
}

pre-deactivate {
    system "launchctl remove org.eugridpma.fetch-crl || true"
    system "launchctl unload /Library/LaunchDaemons/org.eugridpma.fetch-crl.plist || true "
    file delete /Library/LaunchDaemons/org.eugridpma.fetch-crl.plist
}
