# vim:set sw=2 et:
#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer	: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobextra/$pkgname"
# Website		: https://pozol.eu
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgname=docbook-xml
_vers=(4.{2..5})
pkgver=${_vers[-1]}
pkgrel=09
pkgdesc="A widely used XML scheme for writing documentation and help"
url="https://www.oasis-open.org/docbook/"
arch=(any)
depends=(libxml2)
install=docbook-xml.install
source=(https://docbook.org/xml/4.1.2/docbkx412.zip
        LICENSE)
noextract=(docbkx412.zip)

for _ver in ${_vers[@]}; do
  source+=("https://docbook.org/xml/$_ver/docbook-xml-$_ver.zip")
  noextract+=("docbook-xml-$_ver.zip")
done

package() {
  local ver xml

  mkdir -p "$pkgdir/etc/xml"
  xmlcatalog --noout --create "$pkgdir/etc/xml/docbook-xml"

  mkdir docbook-xml-4.1.2
  bsdtar -C docbook-xml-4.1.2 -xf docbkx412.zip
  for ver in ${_vers[@]}; do
    mkdir docbook-xml-$ver
    bsdtar -C docbook-xml-$ver -xf docbook-xml-$ver.zip
  done

  for ver in 4.1.2 ${_vers[@]}; do
    pushd docbook-xml-$ver
    mkdir -p "$pkgdir/usr/share/xml/docbook/xml-dtd-$ver"
    cp -dr docbook.cat *.dtd ent/ *.mod \
        "$pkgdir/usr/share/xml/docbook/xml-dtd-$ver"
    popd

    xml=
    case $ver in
      4.1.2) xml=' XML' ;;&
      *)
        xmlcatalog --noout --add "public" \
          "-//OASIS//DTD DocBook XML V$ver//EN" \
          "http://www.oasis-open.org/docbook/xml/$ver/docbookx.dtd" \
          "$pkgdir/etc/xml/docbook-xml"
        xmlcatalog --noout --add "public" \
          "-//OASIS//DTD DocBook$xml CALS Table Model V$ver//EN" \
          "http://www.oasis-open.org/docbook/xml/$ver/calstblx.dtd" \
          "$pkgdir/etc/xml/docbook-xml"
        xmlcatalog --noout --add "public" \
          "-//OASIS//DTD XML Exchange Table Model 19990315//EN" \
          "http://www.oasis-open.org/docbook/xml/$ver/soextblx.dtd" \
          "$pkgdir/etc/xml/docbook-xml"
        xmlcatalog --noout --add "public" \
          "-//OASIS//ELEMENTS DocBook$xml Information Pool V$ver//EN" \
          "http://www.oasis-open.org/docbook/xml/$ver/dbpoolx.mod" \
          "$pkgdir/etc/xml/docbook-xml"
        xmlcatalog --noout --add "public" \
          "-//OASIS//ELEMENTS DocBook$xml Document Hierarchy V$ver//EN" \
          "http://www.oasis-open.org/docbook/xml/$ver/dbhierx.mod" \
          "$pkgdir/etc/xml/docbook-xml"
        xmlcatalog --noout --add "public" \
          "-//OASIS//ENTITIES DocBook$xml Additional General Entities V$ver//EN" \
          "http://www.oasis-open.org/docbook/xml/$ver/dbgenent.mod" \
          "$pkgdir/etc/xml/docbook-xml"
        xmlcatalog --noout --add "public" \
          "-//OASIS//ENTITIES DocBook$xml Notations V$ver//EN" \
          "http://www.oasis-open.org/docbook/xml/$ver/dbnotnx.mod" \
          "$pkgdir/etc/xml/docbook-xml"
        xmlcatalog --noout --add "public" \
          "-//OASIS//ENTITIES DocBook$xml Character Entities V$ver//EN" \
          "http://www.oasis-open.org/docbook/xml/$ver/dbcentx.mod" \
          "$pkgdir/etc/xml/docbook-xml"
        ;;&
      4.[45])
        xmlcatalog --noout --add "public" \
          "-//OASIS//ELEMENTS DocBook XML HTML Tables V$ver//EN" \
          "http://www.oasis-open.org/docbook/xml/$ver/htmltblx.mod" \
          "$pkgdir/etc/xml/docbook-xml"
        ;;&
      *)
        xmlcatalog --noout --add "rewriteSystem" \
          "http://www.oasis-open.org/docbook/xml/$ver" \
          "/usr/share/xml/docbook/xml-dtd-$ver" \
          "$pkgdir/etc/xml/docbook-xml"
        xmlcatalog --noout --add "rewriteURI" \
          "http://www.oasis-open.org/docbook/xml/$ver" \
          "/usr/share/xml/docbook/xml-dtd-$ver" \
          "$pkgdir/etc/xml/docbook-xml"
        ;;&
    esac
  done

  install -Dt "$pkgdir/usr/share/licenses/$pkgname" -m644 LICENSE

  # Fix permissions
  find "$pkgdir" -type f -exec chmod -c a-x {} +
  chmod -Rc u=rwX,go=rX "$pkgdir"
}

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

license=(MIT)

sha256sums=(30f0644064e0ea71751438251940b1431f46acada814a062870f486c772e7772 # docbkx412.zip
	adf79c0ee42b5b0d9b0d10def6aca4f7c97a0ce7333b3012af2c929e1ed72b77 # LICENSE
	acc4601e4f97a196076b7e64b368d9248b07c7abf26b34a02cca40eeebe60fa2 # docbook-xml-4.2.zip
	23068a94ea6fd484b004c5a73ec36a66aa47ea8f0d6b62cc1695931f5c143464 # docbook-xml-4.3.zip
	02f159eb88c4254d95e831c51c144b1863b216d909b5ff45743a1ce6f5273090 # docbook-xml-4.4.zip
	4e4e037a2b83c98c6c94818390d4bdd3f6e10f6ec62dd79188594e26190dc7b4) # docbook-xml-4.5.zip
