# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=osinfo-db
pkgver=20170813
pkgrel=1
pkgdesc="osinfo database files"
url="http://libosinfo.org/"
arch="noarch"
license="LGPL-2.0-or-later"
depends=""
makedepends="osinfo-db-tools"
install=""
subpackages=""
source="https://releases.pagure.org/libosinfo/osinfo-db-$pkgver.tar.xz
	0001-Add-alpine-linux-3.5-and-3.6.patch
	"
builddir="$srcdir/osinfo-db-$pkgver"

build() {
	cd "$builddir"
}

check() {
	osinfo-db-validate --dir "$builddir"
}


mk_xml() {
	local ver="$1"
	cat <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<libosinfo version="0.0.1">

  <os id="http://alpinelinux.org/alpinelinux/$ver">
    <short-id>alpinelinux$ver</short-id>
    <name>Alpine Linux $ver</name>
    <version>$ver</version>
    <vendor>Alpine Linux Project</vendor>
    <family>linux</family>
    <distro>alpinelinux</distro>
    <resources arch="all">
      <minimum>
        <cpu>1000000000</cpu>
	<n-cpus>1</n-cpus>
	<ram>134217728</ram>
	<storage>1073741824</storage>
      </minimum>
      <recommended>
        <cpu>1000000000</cpu>
	<n-cpus>1</n-cpus>
	<ram>805306368</ram>
	<storage>4294967296</storage>
      </recommended>
    </resources>
    <media arch="i686">
      <iso>
        <volume-id>alpine-.* $ver.\d.* x86.*</volume-id>
      </iso>
    </media>
    <media arch="x86_64">
      <iso>
        <volume-id>alpine-.* $ver.\d.* x86_64.*</volume-id>
      </iso>
    </media>
  </os>
</libosinfo>
EOF
}

package() {
	local ver=
	cd "$builddir"
	osinfo-db-import --root "$pkgdir" \
		--dir /usr/share/osinfo "$srcdir"/osinfo-db-$pkgver.tar.xz
	mkdir -p "$pkgdir"/usr/share/osinfo/os/alpinelinux.org
	for ver in 3.6 3.7; do
		mk_xml $ver > "$pkgdir"/usr/share/osinfo/os/alpinelinux.org/alpinelinux-$ver.xml
	done
}

sha512sums="0ae4906b5c3eb400ca397f0c3baf5146b8197ee2dc712b1b89dd2f443f9505aee208327f008118628407b54ce52390a8b6138425f3f6f974b94f4a8d79955653  osinfo-db-20170813.tar.xz
f56cc5598fcc426e1c1b03814c9e6167602d7ebb096f7a0288ba6c432910405d26692135d7edd13c9d3de11507d1b361a1951056952a462f951d9b75be71f17f  0001-Add-alpine-linux-3.5-and-3.6.patch"
