# Packager = Tuxcore <dev@tuxcore.org> 
pkgname=ndisc6
pkgver=1.0.8
pkgrel=1
pkgdesc='Collection of IPv6 networking utilities'
arch=('x86_64')
url='https://www.remlab.net/ndisc6/'
license=('GPL')
depends=('glibc' 'perl')
makedepends=('glibc' 'gcc' 'systemd')
options=('!emptydirs')
install=$pkgname.install
source=("https://www.remlab.net/files/ndisc6/$pkgname-$pkgver.tar.bz2"
	      'rdnssd@.service'
        'resolvconf-hook')
#Contacted by mail, Rémi was not able to provide its public key.
#He suggested to only rely on https to trust the source.
sha256sums=('1f2fb2dc1172770aa5a09d39738a44d8b753cc5e2e25e306ca78682f9fea0b4f'
            '7b3055a55b6367691cc42e6ba30879f6a2690629ad66211448649a6e7a81758c'
            'c485bb8e5ee480dca2897f950ba9854f8b9deaf782480072536fa4f2d0152d24')

prepare() {
  cd $pkgname-$pkgver
  # apply patch from the source array (should be a pacman feature)
  local src
  for src in "${source[@]}"; do
    src="${src%%::*}"
    src="${src##*/}"
    [[ $src = *.patch ]] || continue
    echo "Applying patch $src..."
    patch -Np1 < "../$src"
  done
  # patch invalid path
  sed -ri 's,^PATH=.*,PATH=/usr/local/sbin:/usr/local/bin:/usr/bin,' rdnss/merge-hook.in
}

build() {
  cd $pkgname-$pkgver
  ./configure \
    --prefix=/usr \
    --sbindir=/usr/bin \
    --localstatedir=/var \
    --sysconfdir=/etc
  make
}

package() {
  pushd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install
  popd

  # service
  install -Dm644 "$srcdir/rdnssd@.service" "$pkgdir/usr/lib/systemd/system/rdnssd@.service"

  # tmpfiles
  install -Dm644 /dev/null "$pkgdir/usr/lib/tmpfiles.d/$pkgname.conf"
  echo 'd /run/rdnssd 0755 nobody root' > "$pkgdir/usr/lib/tmpfiles.d/$pkgname.conf"

  # resolvconf merge hook
  install -Dm755 "$srcdir/resolvconf-hook" "$pkgdir/etc/rdnssd/resolvconf-hook"
}

# vim:set ts=2 sw=2 et:
