#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer	: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobcore/$pkgname"
# Website		: https://pozol.eu
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgbase=dhcp
pkgname=('dhcp' 'dhclient')

# separate patch levels with a period to maintain proper versioning.
_realver=4.4.3-P1
pkgver=${_realver/-/.}
pkgrel=01
arch=('x86_64')
url='https://www.isc.org/dhcp/'
makedepends=('bash' 'iproute2' 'openldap')
# options=('!lto')  ##  remove # if you want the internationalization options to be included 

source=("https://downloads.isc.org/isc/${pkgbase}/${_realver}/${pkgbase}-${_realver}.tar.gz"{,.asc}
        '0001-99-replace-hostname-with-uname-n.patch'
        'dhcp-sysusers.conf'
        'dhcp-tmpfiles.conf')

prepare() {
  cd "${srcdir}/${pkgbase}-${_realver}"

  patch -Np1 < ../0001-99-replace-hostname-with-uname-n.patch
}

build() {
  cd "${srcdir}/${pkgbase}-${_realver}"
#  SEE "note"
#       --disable-dhcpv6 \
#  see note on the dhcp/dhclient directory about this
  ./configure \
      --prefix=/usr \
      --sbindir=/usr/bin \
      --sysconfdir=/etc \
      --disable-dhcpv4o6 \
      --enable-binary-leases \
      --enable-paranoia \
      --with-ldap \
      --with-ldapcrypto \
      --with-srv-lease-file=/var/lib/dhcp/dhcpd.leases \
      --with-cli-lease-file=/var/lib/dhclient/dhclient.leases
  make -j1
}

package_dhcp(){
  pkgdesc="A DHCP server, client, and relay agent w/o systemd & ipv6"
  depends=('glibc' 'libldap')
  backup=('etc/dhcpd.conf' )
# 'etc/dhcpd6.conf')

  cd "${srcdir}/${pkgbase}-${_realver}"

  make DESTDIR="${pkgdir}" install

  install -D -m644 "${srcdir}/dhcp-sysusers.conf" "${pkgdir}/usr/lib/sysusers.d/dhcp.conf"
  install -D -m644 "${srcdir}/dhcp-tmpfiles.conf" "${pkgdir}/usr/lib/tmpfiles.d/dhcp.conf"

  # move and install config files in place
  mv "${pkgdir}/etc/dhcpd.conf.example" "${pkgdir}/etc/dhcpd.conf"

  # Remove dhclient
  make -C client DESTDIR="${pkgdir}" uninstall

  # install license
  install -m644 -D LICENSE "${pkgdir}/usr/share/licenses/dhcp/LICENSE"
}

package_dhclient(){
  pkgdesc="A standalone DHCP client from the dhcp package w/o systemd & ipv6"
  depends=('glibc' 'bash' 'iproute2' 'run-parts')
  provides=('dhcp-client')

  cd "${srcdir}/${pkgbase}-${_realver}"

  make -C client DESTDIR="${pkgdir}" install

  install -m755 -d "${pkgdir}/usr/share/dhclient"
  mv "${pkgdir}/etc/dhclient.conf.example" "${pkgdir}/usr/share/dhclient/"

  install -d "${pkgdir}/var/lib/dhclient"

  # install dhclient linux script
  install -m755 client/scripts/linux "${pkgdir}/usr/bin/dhclient-script"

  # install license
  install -m644 -D LICENSE "${pkgdir}/usr/share/licenses/dhclient/LICENSE"

}

#---- license gpg-key sha256sums ----

license=('custom:isc-dhcp')

validpgpkeys=('7E1C91AC8030A5A59D1EFAB9750F3C87723E4012') # Internet Systems Consortium, Inc. (Signing key, 2021-2022) <codesign@isc.org>

sha256sums=(0ac416bb55997ca8632174fd10737fd61cdb8dba2752160a335775bc21dc73c7 # dhcp-4.4.3-P1.tar.gz
	4295715b00f2368877bb59017c70fbbb738d5d654442b3bfec34e0d7f53306be # dhcp-4.4.3-P1.tar.gz.asc
	f3dd5fe585eae18a982bfdbe163f3e3749057cb595ee59a154348094109351c2 # 0001-99-replace-hostname-with-uname-n.patch
	b16083e6bb572ffacaa7cd97e7fde5fcfa1b6dbeb166f162e2ec6e8ec4b928d6 # dhcp-sysusers.conf
	abcd30e9e8428e34d22ab4d3074ef4bd84c2b11f5868597111b47d6f56d204da) # dhcp-tmpfiles.conf
