# Packager = Tuxcore <dev@tuxcore.org> 
pkgname=wireless-regdb
pkgver=2024.10.07
pkgrel=1
pkgdesc="Central Regulatory Domain Database"
arch=('any')
url="https://wireless.wiki.kernel.org/en/developers/regulatory/wireless-regdb"
license=('LicenseRef-custom')
depends=('bash' 'iw')
makedepends=('git')
replaces=('crda')
provides=('crda')
conflicts=('crda')
backup=(etc/conf.d/wireless-regdom)
source=("git+https://git.kernel.org/pub/scm/linux/kernel/git/wens/wireless-regdb.git?signed#tag=master-${pkgver//./-}"
        wireless-regdom
        set-wireless-regdom
        85-regulatory.rules)
b2sums=('c4abd453848fee4544f9b26877e7227ca757d83cc9de61c940b2757be52347490e94d1cfaf1bc1ff7a1b612ffc9c025326ef8c2ba051acf9c088294b27ea2c22'
        '4d470f76ba0ac3c9c25425cd2ce5c9cb93292e565ab3038e975aa837abaad83325f1340cef8ca73150a07f8e77cd542a485e35daef8c403d48c93814f1ccacea'
        '0d245faf594f9051a9941fd5e1b6c02fd0668cf4241ca8bdaa2b2e56a805d5d013db59191b0899745f842974fe978ad4add1cad21c7f5a71bc58968c5d1c4be2'
        '50ff5e8d21db396f57b29677e65970f35433399a2268b22099a48d9dc45817734b544699e1efc6b0e4f4fa95e191e101b25226b4df02f6b7fa75f5036c94d2c0')
validpgpkeys=('B3F2469D78D78BD09D366F37C94035C21B4F2AEB') #Chen-Yu Tsai <wens@kernel.org>

package() {
  install -Dm644 wireless-regdom -t "${pkgdir}"/etc/conf.d
  install -Dm644 85-regulatory.rules -t "${pkgdir}"/usr/lib/udev/rules.d
  install -Dm755 set-wireless-regdom -t "${pkgdir}"/usr/bin

  cd "${pkgname}"
  make install DESTDIR="${pkgdir}" MANDIR=usr/share/man FIRMWARE_PATH=usr/lib/firmware

  for dom in $(grep ^country db.txt | cut -d' ' -f2 | sed 's|:||g'); do
    echo "#WIRELESS_REGDOM=\"${dom}\"" >> "${pkgdir}"/etc/conf.d/wireless-regdom.tmp
  done
  sort -u "${pkgdir}"/etc/conf.d/wireless-regdom.tmp >> "${pkgdir}"/etc/conf.d/wireless-regdom
  rm "${pkgdir}"/etc/conf.d/wireless-regdom.tmp

  install -D -m644 "${srcdir}/${pkgname}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
