#!/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 |---------------------------------------

# this package's utility has been incorporated to wireless-regdb and is no longer necessary
# it has been replaced by the later version of wireless-regdb and creates a conflict with it.
# to be removed 04-08-2022

pkgname=crda
pkgver=4.14
pkgrel=04
pkgdesc="Central Regulatory Domain Agent for wireless networks w/o systemd"
arch=(x86_64)
url="https://wireless.wiki.kernel.org/en/developers/Regulatory/CRDA"
depends=('wireless-regdb' 'libnl' 'libgcrypt' 'iw')
makedepends=('python-m2crypto')
install=crda.install
source=("https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/crda.git/snapshot/crda-$pkgver.tar.gz"
        set-wireless-regdom
        0001-Makefile-Don-t-run-ldconfig.patch
        0001-Makefile-Link-libreg.so-against-the-crypto-library.patch
        crda-4.14-python-3.patch)

prepare() {
  cd "${srcdir}"/${pkgname}-${pkgver}
  patch -p1 -i "${srcdir}"/0001-Makefile-Link-libreg.so-against-the-crypto-library.patch
  patch -p1 -i "${srcdir}"/0001-Makefile-Don-t-run-ldconfig.patch
  patch -p1 -i "${srcdir}"/crda-4.14-python-3.patch
}

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

package() {
  # Install crda, regdbdump and udev rules
  cd "${srcdir}"/${pkgname}-${pkgver}
  make DESTDIR="${pkgdir}" UDEV_RULE_DIR=/usr/lib/udev/rules.d/ SBINDIR=/usr/bin/ install
  # Adjust paths in udev rule file
  sed 's|/sbin/crda|/usr/bin/crda|' -i "${pkgdir}"/usr/lib/udev/rules.d/85-regulatory.rules
  # This rule automatically sets the regulatory domain when cfg80211 is loaded
  echo 'ACTION=="add", SUBSYSTEM=="module", DEVPATH=="/module/cfg80211", RUN+="/usr/bin/set-wireless-regdom"' >> "${pkgdir}"/usr/lib/udev/rules.d/85-regulatory.rules

  install -D -m644 "${srcdir}"/${pkgname}-${pkgver}/LICENSE "${pkgdir}"/usr/share/licenses/crda/LICENSE
  
  install -D -m755 "${srcdir}"/set-wireless-regdom "${pkgdir}"/usr/bin/set-wireless-regdom
}

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

license=('custom')

validpgpkeys=('E4053F8D0E7C4B9A0A20AB27DC553250F8FE7407') #Luis R. Rodriguez
#                                      DC553250F8FE7407: "Luis Chamberlain <mcgrof@kernel.org>
# Same key different name, Chamberlain is what kernel.org repo shows

sha256sums=(5a8f35bb8b27474f466b0e75d451ba917433d8aab1889678a64d9c4e72a8b8c2 # crda-4.14.tar.gz
	603ce97da5cce3f5337e99007ce04e2f295bb33a36b308794884011f7bcabaf3 # set-wireless-regdom
	ff52990cf9295e5cebcf07ebbf2a96e225d97088573edcc898b29ce33a0fb663 # 0001-Makefile-Don-t-run-ldconfig.patch
	96b2068b27202f8bc78009869520e396cb3f3ac7a826efef06d0fc41047f2520 # 0001-Makefile-Link-libreg.so-against-the-crypto-library.patch
	95057c7a1c8f2be8b70785356162b86831ba9f198fc43c411267ca97ddb68ed9) # crda-4.14-python-3.patch
