# -*- 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
PortGroup           legacysupport 1.1

# Need O_CLOEXEC
legacysupport.newest_darwin_requires_legacy 10

github.setup        logrotate logrotate 3.21.0
revision            0
github.tarball_from releases
use_xz              yes
checksums           rmd160  9e1edb08441ae239a8471f81b8d589772e3d5243 \
                    sha256  8fa12015e3b8415c121fc9c0ca53aa872f7b0702f543afda7e32b6c4900f6516 \
                    size    168532

categories          sysutils
license             GPL-2
maintainers         {ctreleaven @ctreleaven} openmaintainer

description         Rotates, compresses, and mails system logs

long_description    The logrotate utility is designed to simplify the administration of logs \
                    on a system which generates a lot of log files. Logrotate provides \
                    automatic rotation, compression (gzip by default), removal and mailing \
                    of log files. Logrotate can be set to handle a log file daily, weekly, \
                    monthly or when the log file exceeds a certain size.

installs_libs       no

depends_lib         port:popt

depends_run         port:gettext \
                    port:gzip

set compress        ${prefix}/bin/gzip
set compress_ext    .gz
set uncompress      ${prefix}/bin/gunzip

post-extract {
    touch ${worksrcpath}/.depend
    copy ${filespath}/logrotate.conf.example \
        ${worksrcpath}/
    copy ${filespath}/org.macports.logrotate.plist.example \
        ${worksrcpath}/
}

post-patch {
    reinplace "s|@PREFIX@|${prefix}|g" \
        ${worksrcpath}/logrotate.conf.example
    reinplace "s|@PREFIX@|${prefix}|g" \
        ${worksrcpath}/org.macports.logrotate.plist.example
}

use_autoconf        yes

configure.args-append \
                    --disable-silent-rules\
                    --with-state-file-path=${prefix}/var/run/logrotate/logrotate.status \
                    --with-default-mail-command=/bin/mail \
                    --with-compress-command=${compress} \
                    --with-uncompress-command=${uncompress} \
                    --with-compress-extension=${compress_ext}

destroot.keepdirs   ${destroot}${prefix}/etc/logrotate.d \
                    ${destroot}${prefix}/var/run/logrotate
post-destroot {
    xinstall -d ${destroot}${prefix}/share/${name}
    xinstall -m 644 -W ${worksrcpath} ChangeLog.md COPYING logrotate.conf.example \
        ${destroot}${prefix}/share/${name}
}

startupitem.type    launchd
startupitem.create  no
startupitem.custom_file \
                    ${worksrcpath}/org.macports.logrotate.plist.example

pre-activate {
# launchd plist was formerly unregistered; delete if found
# this block can be deleted in a couple of years (2025)
    delete /Library/LaunchDaemons/org.macports.logrotate.plist
}

post-activate {
    if {![file exists ${prefix}/etc/logrotate.conf]} {
        copy ${prefix}/share/${name}/logrotate.conf.example ${prefix}/etc/logrotate.conf
    }
}

variant bzip2 description {Use bzip2 compression by default} {
    set compress    ${prefix}/bin/bzip2
    set compress_ext .bz2
    set uncompress   ${prefix}/bin/bunzip2
    depends_run-replace \
                    port:gzip port:bzip2
}

notes "
To use logrotate:

  * See 'man logrotate' for configuration options.

  * Enable daily log rotation with this command.

    \$ sudo port load logrotate
"