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

# Final release was on 2022-11-07
deprecated.upstream_support no

name                postgresql10-server
version             10.19
categories          databases
platforms           {darwin any}
maintainers         {jwa @jyrkiwahlstedt}
license             Permissive

set rname           postgresql10
description         run ${rname} as server
long_description    {*}${description}
distfiles       

homepage            https://www.postgresql.org/
master_sites        postgresql

depends_run         port:${rname}

supported_archs     noarch

use_configure       no
build    {}

set libdir          ${prefix}/lib/${rname}
set dbdir           ${prefix}/var/db/${rname}/defaultdb
set logdir          ${prefix}/var/log/${rname}
set dbuser          postgres
set dbgrp           postgres
set dbhome          ${prefix}/var/db/${rname}

add_users ${dbuser} shell=/bin/sh group=${dbgrp} \
    home=${prefix}/var/db/${rname} \
    realname=PostgreSQL-10\ Server

startupitem.create  yes
startupitem.init    \
    "PGCTL=${libdir}/bin/pg_ctl"
startupitem.start    \
    "su ${dbuser} -c \"\${PGCTL} -D \${POSTGRESQL10DATA:=${dbdir}} start -l ${logdir}/postgres.log\""
startupitem.stop    \
"su ${dbuser} -c \"\${PGCTL} -D \${POSTGRESQL10DATA:=${dbdir}} stop -s -m fast\""

destroot {
    xinstall -m 755 -d ${destroot}${logdir}
    system "touch ${destroot}${logdir}/postgres.log"
    system "chown ${dbuser}:${dbgrp} ${destroot}${logdir}/postgres.log"
}

notes "\nTo create a database instance, after install do\n\
        sudo mkdir -p ${dbdir}\n\
        sudo chown ${dbuser}:${dbgrp} ${dbdir}\n\
        sudo su ${dbuser} -c \'cd ${dbhome} && ${libdir}/bin/initdb -D ${dbdir}\' "

livecheck.type      none