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

github.setup        geneweb geneweb 7.1.0-beta2 v
revision            5
categories          genealogy
maintainers         {pguyot @pguyot} openmaintainer
license             GPL-2

description         Sophisticated Genealogy System
long_description    GeneWeb is sophisticated genealogy software with a \
                    web interface.  It provides efficient relationship and consanguinity \
                    computing, support for very large database (i.e., hundreds of thousands \
                    of entries), and more.

homepage            https://geneweb.tuxfamily.org/wiki/GeneWeb

github.tarball_from archive
checksums           rmd160  97f060aec92e757499eb8adb3979178c7feefa59 \
                    sha256  5599ed26d69e65ac59a55c73efd806c6cebf8e0aeb4bd1173123621084d4aae8 \
                    size    8920128

depends_build       port:ocaml-dune

depends_lib         port:ocaml \
                    port:camlp5 \
                    port:ocaml-calendars \
                    port:ocaml-camlp-streams \
                    port:ocaml-cppo \
                    port:ocaml-decompress \
                    port:ocaml-digestif \
                    port:ocaml-fmt \
                    port:ocaml-jingoo \
                    port:ocaml-logs \
                    port:ocaml-logs-syslog \
                    port:ocaml-markup \
                    port:ocaml-pp_loc \
                    port:ocaml-ppx_blob \
                    port:ocaml-ppx_deriving \
                    port:ocaml-ppx_import \
                    port:ocaml-stdlib-shims \
                    port:ocaml-unidecode \
                    port:ocaml-uri \
                    port:ocaml-uucp \
                    port:ocaml-uunf \
                    port:ocaml-uutf \
                    port:ocaml-yojson \
                    port:ocaml-zarith

use_parallel_build  no

set gwuser          ${name}
set gwgroup         ${name}
set logdir          ${prefix}/var/log
set langdir         ${prefix}/share/${name}/gw
set dbdir           ${prefix}/var/db/${name}

add_users ${gwuser} group=${gwgroup} \
                    home=${dbdir} \
                    realname=Geneweb

startupitem.create  yes
startupitem.user    ${gwuser}
startupitem.executable \
                    ${prefix}/share/${name}/gw/gwd \
                    -bd ${dbdir} \
                    -hd ${langdir} \
                    -lang en \
                    -log ${logdir}/${name}.log \
                    -daemon
startupitem.pidfile none

# Include upstream commits for calendars 2.0.0 and unidecode 0.5.0
patchfiles          patch-calendars-2.0.0.diff \
                    patch-unidecode-0.5.0.diff

configure.cmd       ocaml
configure.pre_args
configure.args      ./configure.ml

build.target        distrib

destroot.keepdirs   ${destroot}${dbdir}

set distrib         ${worksrcpath}/distribution

destroot {
    xinstall -m 0755 -o ${gwuser} -g ${gwgroup} -d ${destroot}${logdir}
    xinstall -m 0755 -o ${gwuser} -g ${gwgroup} -d ${destroot}${dbdir}

    system "touch ${destroot}${logdir}/${name}.log"
    system "chown ${gwuser}:${gwgroup} ${destroot}${logdir}/${name}.log"
    system "chown -R ${gwuser}:${gwgroup} ${destroot}${dbdir}"

    xinstall -m 0755 -o ${gwuser} -g ${gwgroup} -d ${destroot}${prefix}/share/${name}
    xinstall -m 0755 -o ${gwuser} -g ${gwgroup} -d ${destroot}${prefix}/share/doc/${name}

    foreach x {LICENSE.txt README.txt START.htm README.txt LISEZMOI.txt CHANGES.txt gw geneweb.command gwd.command gwsetup.command} {
        file copy -force ${distrib}/${x} ${destroot}${prefix}/share/${name}/${x}
    }

    system "chmod a+rx ${destroot}${prefix}/share/${name}/gwsetup.command"
    system "chmod a+rx ${destroot}${prefix}/share/${name}/gwd.command"

    # Make the directory structure generally writeable so the gwsetup and other stuff will work easily.
    system "chown -R ${gwuser}:${gwgroup} ${destroot}${prefix}/share/${name}"
    system "chmod -R a+r ${destroot}${prefix}/share/${name}/gw"

    # Move a few utilities where the user can get to them easily
    file copy -force ${destroot}${prefix}/share/${name}/gw/consang ${destroot}${prefix}/bin
    file copy -force ${destroot}${prefix}/share/${name}/gw/ged2gwb ${destroot}${prefix}/bin
    file copy -force ${destroot}${prefix}/share/${name}/gw/gwb2ged ${destroot}${prefix}/bin
    file copy -force ${filespath}/gwsetup.macports ${destroot}${prefix}/bin/gwsetup

    # Set correct path in gwsetup
    reinplace "s|%PREFIX%|${prefix}|" ${destroot}${prefix}/bin/gwsetup
    system "chmod a+rx ${destroot}${prefix}/bin/gwsetup"
}

post-activate {
    system "chown -R ${gwuser}:${gwgroup} ${prefix}/var/db/${name}"
    system "chmod -R a+rwX ${prefix}/var/db/${name}"
}

notes "
Geneweb will be listening on localhost, port 2317.

To get started, you will need to load an initial database.\
Run the program 'gwsetup' to get started. After that point,\
simply point your browser to http://localhost:2317 to review\
the data.

If you are upgrading, you may need to fix permissions:\
sudo chmod 0755 ${prefix}/var/db/geneweb/cnt/
"
