# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8::et:sw=4:ts=4:sts=4

PortSystem          1.0

name                pass
version             1.7.4
revision            3
maintainers         {judaew @judaew} openmaintainer
categories          security
description         ${name} is the standard unix password manager
long_description    {*}${description}
supported_archs     noarch
platforms           any
homepage            https://www.passwordstore.org/
license             GPL-2+

depends_run         port:git \
                    port:tree \
                    port:qrencode \
                    port:util-linux \
                    path:bin/gpg:gnupg2

master_sites        https://git.zx2c4.com/password-store/snapshot/
# Avoid stealth update of 1.7.4
master_sites        macports_distfiles
distname            password-store-${version}
use_xz              yes

# See https://trac.macports.org/ticket/56767
variant external_gpg description {Variant for GPG Suite users and so on} {
    depends_run-replace path:bin/gpg:gnupg2 \
                        bin:gpg:gnupg2
}

checksums           rmd160  c1ac8d01ba88fad13cb5c7a6dcb2b7f3f58bb36c \
                    sha256  cfa9faf659f2ed6b38e7a7c3fb43e177d00edbacc6265e6e32215ff40e3793c0 \
                    size    65272

patchfiles          patch-getopt-path.diff
patchfiles-append   patch-fix-unnecessary-reencryptions.diff

post-patch {
    reinplace "s|@@PREFIX@@|${prefix}|g" ${worksrcpath}/src/platform/darwin.sh
}

use_configure       no
build {}

destroot.env-append PREFIX=${prefix} \
                    SYSCONFDIR=${prefix}/etc \
                    WITH_ALLCOMP=yes

# Add misc contrib files
post-destroot {
    set vim-plugin ${prefix}/share/vim/vimfiles
    xinstall -d ${destroot}${vim-plugin}/ftdetect
    xinstall -m 0644 ${worksrcpath}/contrib/vim/redact_pass.vim \
        ${destroot}${vim-plugin}/ftdetect

    set emacs-plugin ${prefix}/share/emacs/site-lisp
    xinstall -d ${destroot}${emacs-plugin}
    xinstall -m 0644 ${worksrcpath}/contrib/emacs/password-store.el \
        ${destroot}${emacs-plugin}

    xinstall -d ${destroot}${prefix}/share/${name}
    xinstall -m 0644 ${worksrcpath}/contrib/pass.applescript \
        ${destroot}${prefix}/share/${name}
}

notes "
    To use pass bash completion, add the following lines at the end of your
    .bash_profile:

    \[\[ -r \"${prefix}/share/bash-completion/completions/pass\" \]\] && \\
        source \"${prefix}/share/bash-completion/completions/pass\"
    
    No additional steps are required for zsh and fish completions installed
    from MacPorts. To use completion with system version of zsh, include the
    directory with shell completion via fpath to your .zprofile:

    fpath=(${prefix}/share/zsh/site-functions \$fpath)
"

livecheck.type    regex
livecheck.url     ${homepage}
livecheck.regex   {The latest version is ([\d.]+)\.}