# Copyright     : Obarun
#------------------------
# Maintainer    : Eric Vidal <eric@obarun.org>
# Maintainer    : Jean-Michel T.Dydak <jean-michel@obarun.org>
#----------------
# Pkgbuild Src  : https://git.obarun.org/pkg/obcore/dhcpcd
#--------------------------------------------------------------------------------
# DESCRIPTION ]

pkgname=dhcpcd
pkgver=9.4.1
pkgrel=3
pkgdesc="RFC2131 compliant DHCP client daemon"
url='https://roy.marples.name/projects/dhcpcd/'

track="$pkgname"
target="$pkgname-$pkgver"
source=(
    "https://roy.marples.name/downloads/${track}/${target}.tar.xz"
    dhcpcd.conf
    dhcpcd.sysusers
    dhcpcd.tmpfiles
    dhcpcd.install
)

#----------------------
# BUILD CONFIGURATION ]

options=(
    'emptydirs'
)   ## We Need the Empty /var/lib/dhcpcd Directory

#------------------------
# INSTALL CONFIGURATION ]

depends=(
    'glibc'
    'sh'
    'udev'
)

optdepends=(
    'openresolv: resolvconf support'
)

backup=(
    'etc/dhcpcd.conf'
)

groups=(
    'base'
)

provides=(
    'dhcp-client'
)

install=dhcpcd.install

#----------------
# BUILD CONTROL ]

_flags=(
    --prefix=/usr
    --sysconfdir=/etc
    --localestatdir=/var
    --sbindir=/usr/bin
    --libexecdir=/usr/lib/dhcpcd
    --dbdir=/var/lib/dhcpcd
    --runstatedir=/run
    --privsepuser=dhcpcd
)

#--------
# BUILD ]

build() {
    cd $pkgname-$pkgver

    ./configure "${_flags[@]}"
    make
}

#--------
# CHECK ]

check() {
    cd $pkgname-$pkgver
    make test
}

#----------
# PACKAGE ]

package() {
    cd $pkgname-$pkgver

    make DESTDIR="$pkgdir" install

    ## Install License
    install -Dm644 "$srcdir"/$pkgname-$pkgver/LICENSE \
        "$pkgdir"/usr/share/licenses/$pkgname/LICENSE

    # Set Options in /etc/dhcpcd.conf
    echo noipv4ll >> "${pkgdir}/etc/dhcpcd.conf" # Disable ip4vall

    ## Set Options in /etc/dhcpcd.conf
    install -m644  "$srcdir"/dhcpcd.conf     "$pkgdir"/etc/dhcpcd.conf
    install -Dm644 "$srcdir"/dhcpcd.sysusers "$pkgdir"/usr/lib/sysusers.d/dhcpcd.conf
    install -Dm644 "$srcdir"/dhcpcd.tmpfiles "$pkgdir"/usr/lib/tmpfiles.d/dhcpcd.conf
}

#--------------------
# ARCH LICENSE AUTH ]

arch=(x86_64)
license=(BSD)

sha256sums=('819357634efed1ea5cf44ec01b24d3d3f8852fec8b4249925dcc5667c54e376c'
            '5f72df416730de7453a45f2eabe318a4607c7760e8b50614b17f9a8bef3aab4f'
            '06788ad9f5f7ccb5d2a2da6f0322ff5771f8de82cfbe8b9ad954f2c38265e21b'
            '55d57b958f6b7e4d4a538ee88b0fcc1a522050c2d38efb5d680139f618234b35'
            'd40d51367fcf7e9596e42cd2bab59404633bedbab4d0a3183e7246b4677937b7')
