# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=geoip2-database
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=20180522
pkgrel=1
pkgdesc="GeoLite country geolocation database compiled by MaxMind (mingw-w64)"
arch=('any')
url="https://dev.maxmind.com/geoip/geoip2/geolite2/"
license=('custom:Creative Commons Attribution-ShareAlike 3.0 Unported')
source=(GeoLite2-City-${pkgver}.tar.gz::https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
        GeoLite2-Country-${pkgver}.tar.gz::https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz
        GeoLite2-ASN-${pkgver}.tar.gz::https://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz)
noextract=(GeoLite2-City-${pkgver}.tar.gz
           GeoLite2-Country-${pkgver}.tar.gz
           GeoLite2-ASN-${pkgver}.tar.gz)
sha256sums=('0f3c1d1115e764481962766323e838a634c16eff08e6c9229b87973ac380bb48'
            '6977a408a4f3eca76523b5bf39780fd2c8529f263ce8cc94c1da208dc9be678b'
            'b7f3c783d77fc2f3f39ccd86930eb1e47f7aef7e1b2d1bc861e6b6efc4f2c90a')

prepare() {
  cd "${srcdir}"

  for _db in GeoLite2-{City,Country,ASN}; do
    tar --strip-components=1 -xf ${_db}-${pkgver}.tar.gz --wildcards "*/${_db}.mmdb"
  done

  tar --strip-components=1 -xf GeoLite2-ASN-${pkgver}.tar.gz --wildcards "*/COPYRIGHT.txt" "*/LICENSE.txt"
}

package() {
  cd "${srcdir}"

  install -d "${pkgdir}${MINGW_PREFIX}/share/GeoIP"
  install -m644 -t "${pkgdir}${MINGW_PREFIX}/share/GeoIP" GeoLite2-{City,Country,ASN}.mmdb

  install -Dm644 COPYRIGHT.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYRIGHT.txt"
  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.txt"
}
