# Maintainer: Developer <dev@opalos.org>
# Maintainer: Developer <dev@opalos.org>

_upstream_name=license-list-data
_upstream_version=3.22
pkgname=licenses
pkgver=%version%
pkgrel=%release%
pkgdesc="A set of common license files"
arch=(any)
license=(LicenseRef-None)
url="https://www.archlinux.org/"
makedepends=(
  jq
)
source=(
  $_upstream_name-$_upstream_version.tar.gz::https://github.com/spdx/$_upstream_name/archive/refs/tags/v$_upstream_version.tar.gz
)
sha512sums=('b213fe66699770d75a4c994a01a5c08325751423516c2fb871088a47e7e7ce605736064f5ce3a63dc1d3c462271832db7bc464ac968df1888f9823787964c786')
b2sums=('751d4a31a74b1f0c6831b2e2ad7b361fddca6f9e71f58f57b2dc4fdf13f3ad2a63c652d0333e97d25c1748b7ced62db0b799cc5421c7ed4e117b46fa0869bf3c')

prepare() {
  local license
  touch known_spdx_license_exceptions.txt known_spdx_license_identifiers.txt

  # create list of known, non-deprecated SPDX license identifiers
  for license in $(jq -r '.licenses[] | select(.isDeprecatedLicenseId == false) | .licenseId' $_upstream_name-$_upstream_version/json/licenses.json); do
    printf "%s\n" "$license" >> known_spdx_license_identifiers.txt
  done

  # create list of known SPDX exception identifiers
  for license in $(jq -r '.exceptions[] | .licenseExceptionId' $_upstream_name-$_upstream_version/json/exceptions.json); do
    printf "%s\n" "$license" >> known_spdx_license_exceptions.txt
  done
}

package() {
  local license
  local standard_licenses=(
    AGPL-3.0-only
    AGPL-3.0-or-later
    Apache-2.0
    Artistic-1.0-Perl
    Artistic-2.0
    BSL-1.0
    CC0-1.0
    CC-BY-1.0
    CC-BY-2.0
    CC-BY-2.5
    CC-BY-3.0-AT
    CC-BY-3.0
    CC-BY-3.0-US
    CC-BY-4.0
    CC-BY-NC-1.0
    CC-BY-NC-2.0
    CC-BY-NC-2.5
    CC-BY-NC-3.0
    CC-BY-NC-4.0
    CC-BY-NC-ND-1.0
    CC-BY-NC-ND-2.0
    CC-BY-NC-ND-2.5
    CC-BY-NC-ND-3.0-IGO
    CC-BY-NC-ND-3.0
    CC-BY-NC-ND-4.0
    CC-BY-NC-SA-1.0
    CC-BY-NC-SA-2.0
    CC-BY-NC-SA-2.5
    CC-BY-NC-SA-3.0
    CC-BY-NC-SA-4.0
    CC-BY-ND-1.0
    CC-BY-ND-2.0
    CC-BY-ND-2.5
    CC-BY-ND-3.0
    CC-BY-ND-4.0
    CC-BY-SA-1.0
    CC-BY-SA-2.0
    CC-BY-SA-2.0-UK
    CC-BY-SA-2.1-JP
    CC-BY-SA-2.5
    CC-BY-SA-3.0-AT
    CC-BY-SA-3.0
    CC-BY-SA-4.0
    CC-PDDC
    CDDL-1.0
    CDDL-1.1
    CPL-1.0
    EPL-1.0
    EPL-2.0
    FSFAP
    GFDL-1.1-invariants-only
    GFDL-1.1-invariants-or-later
    GFDL-1.1-no-invariants-only
    GFDL-1.1-no-invariants-or-later
    GFDL-1.1-only
    GFDL-1.1-or-later
    GFDL-1.2-invariants-only
    GFDL-1.2-invariants-or-later
    GFDL-1.2-no-invariants-only
    GFDL-1.2-no-invariants-or-later
    GFDL-1.2-only
    GFDL-1.2-or-later
    GFDL-1.3-invariants-only
    GFDL-1.3-invariants-or-later
    GFDL-1.3-no-invariants-only
    GFDL-1.3-no-invariants-or-later
    GFDL-1.3-only
    GFDL-1.3-or-later
    GPL-1.0-only
    GPL-1.0-or-later
    GPL-2.0-only
    GPL-2.0-or-later
    GPL-3.0-only
    GPL-3.0-or-later
    GPL-CC-1.0
    LGPL-2.0-only
    LGPL-2.0-or-later
    LGPL-2.1-only
    LGPL-2.1-or-later
    LGPL-3.0-only
    LGPL-3.0-or-later
    LGPLLR
    LPPL-1.0
    LPPL-1.1
    LPPL-1.2
    LPPL-1.3a
    LPPL-1.3c
    MPL-1.0
    MPL-1.1
    MPL-2.0
    PHP-3.01
    PHP-3.0
    PSF-2.0
    Ruby
    Unlicense
    W3C
    ZPL-1.1
    ZPL-2.0
    ZPL-2.1
  )
  local standard_exceptions=(
    GPL-3.0-linking-exception
    GPL-3.0-linking-source-exception
    LGPL-3.0-linking-exception
    LLGPL
    Linux-syscall-note
    MPL-2.0-no-copyleft-exception
  )

  for license in "${standard_licenses[@]}"; do
    install -vDm 644 "$_upstream_name-$_upstream_version/text/$license.txt" -t "$pkgdir/usr/share/licenses/spdx/"
  done
  for license in "${standard_exceptions[@]}"; do
    install -vDm 644 "$_upstream_name-$_upstream_version/text/$license.txt" -t "$pkgdir/usr/share/licenses/spdx/exceptions/"
  done

  install -vDm 644 known_spdx_license_identifiers.txt -t "$pkgdir/usr/share/licenses/"
  install -vDm 644 known_spdx_license_exceptions.txt -t "$pkgdir/usr/share/licenses/"
}

# vim: ts=2 sw=2 et:
