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

go.setup            github.com/mailhog/MailHog 1.0.1 v
revision            0

description         Web and API based SMTP testing

long_description    MailHog is an email testing tool for developers. You can \
                    configure your application to use MailHog for SMTP \
                    delivery, then view messages in the web UI, or retrieve \
                    them with the JSON API, and optionally release the \
                    messages to real SMTP servers for delivery.

categories          mail devel
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer
license             MIT
installs_libs       no

checksums           rmd160  3faa61726e2e5d1d7745051453abb068676c6c9a \
                    sha256  6227b566f3f7acbfee0011643c46721e20389eba4c8c2d795c0d2f4d2905f282 \
                    size    1249045

depends_build-append \
                    port:gox

build.cmd           make
build.pre_args-append \
                    VERSION=${version}
build.args          release

set mh_name         mailhog
set mh_user         ${mh_name}
set mh_doc_dir      ${prefix}/share/doc/${mh_name}
set mh_log_dir      ${prefix}/var/log/${mh_name}

add_users           ${mh_user} group=${mh_user} realname=${name}

startupitem.create  yes
startupitem.executable \
                    ${prefix}/bin/${name}
startupitem.user    ${mh_user}
startupitem.logevents \
                    yes
startupitem.logfile ${mh_log_dir}/${name}.log

patch {
    # Only build the binary, do not tag or attempt to download gox
    reinplace -E {s|^release:.*|release:|} ${worksrcpath}/Makefile

    # Only build for the current OS and architecture
    reinplace -E "s|gox|gox -osarch \"${goos}/${goarch}\"|g" \
        ${worksrcpath}/Makefile
}

destroot.keepdirs-append ${destroot}${mh_log_dir}

destroot {
    xinstall -m 0755 \
        {*}[glob ${worksrcpath}/build/*_${goos}_${goarch}] \
        ${destroot}${prefix}/bin/${name}

    xinstall -d ${destroot}${mh_doc_dir}
    file copy {*}[glob ${worksrcpath}/docs/*] ${destroot}${mh_doc_dir}/

    xinstall -d ${destroot}${mh_log_dir}
    file attributes ${destroot}${mh_log_dir} -owner ${mh_user}
}

notes "
    Once ${name} is running using the `port load` instructions below,
    it can be accessed at:

        http://localhost:8025

    Logs are located in:

        ${mh_log_dir}
"
