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

_upstream_name=license-list-data
_upstream_version=3.22
pkgname=licenses
pkgver=20240115
pkgrel=01
pkgdesc="A set of common license files"
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)

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
    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-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
    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/"

}

#---- arch license gpg-key & sha256sums ----

arch=(x86_64)

license=(LicenseRef-None)

sha256sums=(ecc9b78b590f5460b7713c1fc9e2093979b18edc2eb48084ba36ad35d2f13892) # license-list-data-3.22.tar.gz

##  a620a4cb0b6d5d862a8c64d1dc3593ac1bdad1ab6223fa596908d1bbd38ef866  licenses-20240115-01-x86_64.pkg.tar.lz

