# Maintainer: botplus <oneofvalts@sdf.org>
# Contributor: bill-auger <bill-auger@programmer.net>


pkgname=gophernicus
pkgver=3.1.1
pkgrel=2
pkgdesc="Modern, full-featured (and hopefully) secure gopher daemon"
arch=('armv7h' 'i686' 'x86_64')
url="https://github.com/gophernicus/gophernicus"
license=('BSD2')

backup=(etc/xinetd.d/gophernicus
        srv/gopher/gophermap)
install=${pkgname}.install

depends=('libwrap' 'xinetd')
optdepends=("xinetd-openrc: openrc init-script")
source=(${pkgname}-${pkgver}.tar.gz::https://github.com/gophernicus/gophernicus/releases/download/${pkgver}/${pkgname}-${pkgver}.tar.gz
        xinetd-respect-custom-server-root.patch
        remove-DESTDIR-from-initscripts.patch
        fix-make-log-typo.patch
        preserve-existing-gophermap.patch)

b2sums=('74610071fab7ee6defc7e128c92f8775d00c42e6b3e806993d9468676e904388bd54cb101f25dad0e281e67090cfdcaf21728eab7821fa1cbd9ea09201d93acb'
        'da46d9010d3b7485aa092c3557c707473ac465451f7e09d32e52409bdefba0633900f198cb8aadc8a05e55274b70ef72cfc2bda4fe22b254c738aa078b0f8280'
        '575bf3480b79c5381f2d08c029e96ebb7eee224e19effe294b95feb1f11f8536a53c12b4850df1263b609a776de350acb0cc17783547b841a631aa7643b3f468'
        '56fedcb3d687b935a4d6d254f511b7fc9c2171190ec4eb00724fab82c93c424c2c373a8881818daba55bee9a381213b45c9a79fde13419a5f817a7bfd065f60c'
        'd6bc23c85168e235430eaf3c70edb62c2ee729c891aab15492b637d43fa752310a7f67cc9c194b3d174d46a6ce8a692bb685178874b8ea01086b12a4746f6fb4')


prepare()
{
  cd "${srcdir}"/${pkgname}-${pkgver}

  # allow server root under /srv/ with xinetd
  patch -Np1 < "${srcdir}"/xinetd-respect-custom-server-root.patch

  # remove DESTDIR path from installed init scripts
  patch -Np1 < "${srcdir}"/remove-DESTDIR-from-initscripts.patch

  # fix typo in make log (does not affect the binary package)
  patch -Np1 < "${srcdir}"/fix-make-log-typo.patch

  # fix think-o in ./configure (does not affect the binary package)
  patch -Np1 < "${srcdir}"/preserve-existing-gophermap.patch
}

build()
{
  cd "${srcdir}"/${pkgname}-${pkgver}

  ./configure --prefix=/usr            \
              --sbindir=/usr/bin       \
              --listener=xinetd        \
              --gopherroot=/srv/gopher
  make
}

package()
{
  cd "${srcdir}"/${pkgname}-${pkgver}

  make DESTDIR="${pkgdir}" install
}
