# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
# TODO: Add server components.
pkgname=opennebula
pkgver=6.8.0
pkgrel=1
pkgdesc="OpenNebula (currenty empty, install opennebula-tools instead)"
url="https://opennebula.io"
arch="noarch"
license="Apache-2.0"
_depends_ruby="
	ruby
	ruby-ipaddress
	ruby-nokogiri
	ruby-parse-cron
	ruby-rbvmomi
	ruby-rexml
	ruby-treetop
	ruby-xmlrpc
	"
_depends_tools="
	ruby
	ruby-activesupport
	ruby-opennebula=$pkgver-r$pkgrel
	"
makedepends="
	$_depends_ruby
	$_depends_tools
	bash
	"
# The subpackages reflect names of the official Debian/Ubuntu packages.
subpackages="
	ruby-$pkgname:rubylibs:noarch
	$pkgname-tools::noarch
	"
source="https://github.com/OpenNebula/one/archive/release-$pkgver/opennebula-$pkgver.tar.gz
	fix-missing-active_support.patch
	"
builddir="$srcdir/one-release-$pkgver"
options="!check"  # no tests provided

build() {
	./share/rubygems/generate
}

package() {
	mkdir -p "$pkgdir"
}

rubylibs() {
	pkgdesc="Ruby libraries needed to talk to OpenNebula"
	depends="$_depends_ruby"

	cd "$builddir"
	_gem_install opennebula
}

tools() {
	pkgdesc="Command Line interface for OpenNebula"
	depends="$_depends_tools"

	cd "$builddir"
	_gem_install opennebula-cli

	install -D -m644 src/cli/etc/*.yaml -t "$subpkgdir"/etc/one/cli/
}

_gem_install() {
	local gemname="$1"
	local gemdir="$subpkgdir/$(ruby -e 'puts Gem.default_dir')"
	local geminstdir="$gemdir/gems/$gemname-$pkgver"

	gem install \
		--local \
		--install-dir "$gemdir" \
		--bindir "$subpkgdir/usr/bin" \
		--ignore-dependencies \
		--no-document \
		--verbose \
		./$gemname-$pkgver.gem

	# Remove unnecessary files and rubbish...
	(cd "$gemdir" && rm -r cache build_info doc extensions plugins)
	(cd "$geminstdir" && rm -f LICENSE NOTICE)
}

sha512sums="
10f09801fea41e1ff8139f46de7fc1f2ebe0497e062c9179ca1362fdaf71d16a537687ff9e8517b6a7894127dd4dc52a9a5197854f56291a7c988d0deb518d53  opennebula-6.8.0.tar.gz
88b696ddcacbeffe9edc359f8c334b638e1fd0b0e74089548e162fb995cc04e8b0500a88e7bf07882ec620ba59f53fa09378f227920c1f09cd742d1bcd5eda34  fix-missing-active_support.patch
"
