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

pkgname=wpa_supplicant
pkgver=2.9
pkgrel=08
epoch=2
pkgdesc='A utility providing key negotiation for WPA wireless networks'
url='https://w1.fi/wpa_supplicant/'
arch=(x86_64)
depends=(openssl libdbus readline libnl)
install=wpa_supplicant.install
source=(
  https://w1.fi/releases/${pkgname}-${pkgver}.tar.gz{,.asc}
  https://w1.fi/security/2020-2/0001-P2P-Fix-copying-of-secondary-device-types-for-P2P-gr.patch
  CVE-2019-16275.patch
  tls.patch             # More permissive TLS fallback
  roam-properties.patch # https://bugs.archlinux.org/task/65482
  config
)

prepare() {
  cd "$srcdir/$pkgname-$pkgver"
  local src
  for src in "${source[@]}"; do
    src="${src%%::*}"
    src="${src##*/}"
    [[ $src = *.patch ]] || continue
    echo "Applying patch $src..."
    patch -Np1 < "../$src"
  done

  cd "$srcdir/$pkgname-$pkgver/$pkgname"
  cp "$srcdir/config" ./.config
}

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

  make LIBDIR=/usr/lib BINDIR=/usr/bin
  make LIBDIR=/usr/lib BINDIR=/usr/bin eapol_test
}

package() {
  cd "$srcdir/$pkgname-$pkgver/$pkgname"
  make LIBDIR=/usr/lib BINDIR=/usr/bin DESTDIR="$pkgdir" install
  install -Dm755 eapol_test "$pkgdir/usr/bin/eapol_test"

  install -d -m755 "$pkgdir/etc/wpa_supplicant"
  install -Dm644 wpa_supplicant.conf \
    "$pkgdir/usr/share/doc/wpa_supplicant/wpa_supplicant.conf"


 install -Dm644 dbus/dbus-wpa_supplicant.conf \
"$pkgdir/usr/share/dbus-1/system.d/wpa_supplicant.conf"
  install -d -m755 "$pkgdir/usr/share/man/man"{5,8}
  install -m644 doc/docbook/*.5 "$pkgdir/usr/share/man/man5/"
  install -m644 doc/docbook/*.8 "$pkgdir/usr/share/man/man8/"
  rm -f "$pkgdir/usr/share/man/man8/wpa_"{priv,gui}.8
}

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

license=(GPL)

validpgpkeys=('EC4AA0A991A5F2464582D52D2B6EF432EFC895FA') # Jouni Malinen

sha256sums=(fcbdee7b4a64bea8177973299c8c824419c413ec2e3a95db63dd6a5dc3541f17 # wpa_supplicant-2.9.tar.gz
	40f998be534b0ca674f643d3fbbf9536d264b148f272688582e8685eb6927e9d # wpa_supplicant-2.9.tar.gz.asc
	c4d65cc13863e0237d0644198558e2c47b4ed91e2b2be4516ff590724187c4a5 # 0001-P2P-Fix-copying-of-secondary-device-types-for-P2P-gr.patch
	bf91a135e717265969f1ab0319297c9d2e6f695928a17e3b3fa5accc8ef7b297 # CVE-2019-16275.patch
	449c7dad67b246b5b93e796f57c2f90c5c32cfc5b16f7aa4f17802dc260d3414 # tls.patch
	1ad3b61397c4a1dbafbf89059bccdda07cfe7eaff9f23ee25bed7bdd82c2bd87 # roam-properties.patch
	6f71a04875465178992e78216603d3c4735ee717a31738a6e30702c7a81c6c4e) #  config
