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

PortSystem          1.0
PortGroup           active_variants 1.1
PortGroup           boost 1.0

name                shibboleth
version             3.4.1
revision            1
categories          security www shibboleth
license             Apache
maintainers         {snc @nerdling} {scantor @scantor}
description         Shibboleth Native Service Provider
long_description    The Shibboleth System is a standards based, open source \
                    software package for web single sign-on across or within \
                    organizational boundaries. It allows sites to make \
                    informed authorization decisions for individual access of \
                    protected online resources in a privacy-preserving manner.

homepage            https://www.shibboleth.net/

boost.depends_type  build

platforms           darwin
depends_build       port:pkgconfig
depends_lib         port:opensaml \
                    port:xmltooling \
                    port:xercesc3 \
                    port:xml-security-c \
                    port:log4shib \
                    port:apache2

master_sites        http://shibboleth.net/downloads/service-provider/${version}/
distname            ${name}-sp-${version}
use_bzip2           yes
worksrcdir          ${name}-sp-${version}
checksums           rmd160  5af8c3c5901042982fd1677b120c7075f623357f \
                    sha256  bffe3e62e46d86cc75db1093b77fa1456b30da7c930a13708afa0139c8a8acc1 \
                    size    830667

require_active_variants curl ssl

use_autoreconf      yes
autoreconf.args     -fvi
configure.args      --enable-apache-24

variant odbc description {enable odbc support} {
        depends_lib-append port:unixODBC
        configure.args-append --enable-odbc
}

destroot.keepdirs ${destroot}${prefix}/var/log/${name} ${destroot}${prefix}/var/run/${name} ${destroot}${prefix}/var/cache/${name}

destroot.args   NOKEYGEN=1

post-destroot {
    file delete {*}[glob ${destroot}${prefix}/etc/${name}/*.logger]
    file delete {*}[glob ${destroot}${prefix}/etc/${name}/*.html]
    file delete {*}[glob ${destroot}${prefix}/etc/${name}/*.xml]
    file delete {*}[glob ${destroot}${prefix}/etc/${name}/shibd-*]
}

post-activate {
    # Make sure initial conf files are present and set up correctly
    set confDir ${prefix}/etc/${name}
    foreach f [glob -tails -directory ${confDir} *.dist] {
        regexp {(.+)\.dist} $f ign destname
        if {![file exists ${confDir}/${destname}]} {
            file copy ${confDir}/${f} ${confDir}/${destname}
        }
    }
    if {![file exists ${confDir}/sp-key.pem]} {
        system -W ${prefix}/etc/${name} "./keygen.sh -b -n sp-signing"
        system -W ${prefix}/etc/${name} "./keygen.sh -b -n sp-encrypt"
    }
}

startupitem.create      yes
startupitem.name        shibd
startupitem.executable  ${prefix}/sbin/shibd -F -f -p ${prefix}/var/run/${name}/shibd.pid

livecheck.type          regex
livecheck.url           http://shibboleth.net/downloads/service-provider/latest/
livecheck.regex         ${name}-sp-(\\d+\\.\\d+(\\.\\d+)?)