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

name                sguil-client
github.setup        bammv sguil 1.0.0 v
categories          security net
license             GPL-3
maintainers         nomaintainer
description         GUI Console for Sguil Network Security Monitor
long_description    {*}${description}
supported_archs     noarch
platforms           any
homepage            https://bammv.github.io/sguil/
github.tarball_from archive
checksums           rmd160 105b99c18ca4fce24e71cf49240a6e085acb4961 \
                    sha256 4f6bd74966750238a727087f639bafd723cf95807cc421cde1ade5a50e19ee16
depends_lib         port:tclx \
                    port:itk \
                    port:iwidgets \
                    port:tcllib \
                    port:tcl-tls \
                    path:lib/libssl.dylib:openssl

patchfiles          configpath.patch
post-patch {
    reinplace "s|set SGUILLIB ./lib|set SGUILLIB ${prefix}/lib/sguil|" \
        ${worksrcpath}/client/sguil.conf
    reinplace "s|set WIRESHARK_PATH /usr/sbin/wireshark|set WIRESHARK_PATH ${prefix}/bin/wireshark|" \
        ${worksrcpath}/client/sguil.conf
    reinplace "s|set SERVERHOST demo.sguil.net|set SERVERHOST localhost|" \
        ${worksrcpath}/client/sguil.conf
    reinplace "s|set MAILSERVER mail.example.com|set MAILSERVER localhost|" \
        ${worksrcpath}/client/sguil.conf
    reinplace "s|@PREFIX@|${prefix}|" ${worksrcpath}/client/sguil.tk
}

use_configure       no
build {}

set sguiletc  ${prefix}/etc/sguil
destroot {
    set sguilbin  ${prefix}/bin
    set sguillib  ${prefix}/lib/sguil
    set sguildoc  ${prefix}/share/doc/sguil

    xinstall -d ${destroot}${sguilbin}
    xinstall ${worksrcpath}/client/sguil.tk ${destroot}${sguilbin}
    xinstall -d ${destroot}${sguillib}
    copy {*}[glob ${worksrcpath}/client/lib/*] ${destroot}${sguillib}
    xinstall -d ${destroot}${sguildoc}
    copy {*}[glob ${worksrcpath}/doc/*] ${destroot}${sguildoc}
    xinstall -d ${destroot}${sguiletc}
    xinstall -m 444 ${worksrcpath}/client/sguil.conf ${destroot}${sguiletc}/sguil.conf.sample
}

post-activate {
    if {![file exists ${sguiletc}/sguil.conf]} {
        copy ${sguiletc}/sguil.conf.sample ${sguiletc}/sguil.conf
    }
}