# Packager = Tuxcore <dev@tuxcore.org> 
pkgname=nbd
pkgver=3.26.1
pkgrel=1
pkgdesc='tools for network block devices, allowing you to use remote block devices over TCP/IP'
arch=('x86_64')
url='https://github.com/NetworkBlockDevice/nbd/'
license=('GPL')
depends=('glib2' 'gnutls' 'libnl')
makedepends=('docbook-utils' 'docbook-sgml' 'perl-sgmls' 'autoconf-archive')
backup=('etc/nbd-server/config')
source=("https://github.com/NetworkBlockDevice/${pkgname}/releases/download/${pkgname}-${pkgver}/${pkgname}-${pkgver}.tar.xz"
        'config'
        'nbd.service'
        'sysusers_nbd.conf')
sha256sums=('f0cf509fa5b20b1a07f7904eb637e9b47d3e30b6ed6f00075af5d8b701c78fef'
            'ee2e9fbbeb8a8b9b71d16b6f32eb41788f6def9d00cc4a47897ed3cb97cdde7c'
            '1b1add55d82d7623eabf7ff3dfec15c1fbe3c340fa74160df3d60e91eb1c71ba'
            '3fd98fe87d0b31b82126dc669f00355865f58fae81af3fccbc0d06504baef6cd')

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

  cat > systemd/sh.tmpl <<EOF
#!/bin/sh

prefix=@prefix@
exec_prefix=@exec_prefix@
sysconfdir=@sysconfdir@

cat <<EOF
EOF
  sed -i 's|../man/sh.tmpl|sh.tmpl|' systemd/Makefile.am

  # this requires make dependency 'autoconf-archive'
  # TODO: drop when issue solved...
  autoreconf -fi
}

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

  ./configure \
    --prefix=/usr \
    --sbindir=/usr/bin \
    --sysconfdir=/etc \
    --enable-syslog

  make
}

# checks still fail...
#check() {
#  cd "${srcdir}/${pkgname}-${pkgver}"
#
#  make check
#}

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

  make DESTDIR="${pkgdir}" install
  install -D -m0644 systemd/nbd@.service "${pkgdir}"/usr/lib/systemd/system/nbd@.service

  install -D -m0644 "${srcdir}"/config "${pkgdir}"/etc/nbd-server/config
  install -D -m0644 "${srcdir}"/nbd.service "${pkgdir}"/usr/lib/systemd/system/nbd.service
  install -D -m0644 "${srcdir}"/sysusers_nbd.conf "${pkgdir}"/usr/lib/sysusers.d/nbd.conf

  install -D -m0644 doc/README "${pkgdir}"/usr/share/doc/nbd/README
}
