# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=homer-app
pkgver=1.5.2
pkgrel=1
pkgdesc="HOMER 7.x Front-End and API Server"
url="http://sipcapture.io"
arch="all"
license="AGPL-3.0-or-later"
makedepends="go"
install="$pkgname.pre-install"
options="net"
subpackages="$pkgname-doc $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/sipcapture/homer-app/archive/refs/tags/$pkgver.tar.gz
	homer-ui-$pkgver-2.tgz::https://github.com/sipcapture/homer-app/releases/download/$pkgver/homer-ui-$pkgver.tgz
	$pkgname.initd

	0001-change-web-and-config-paths.patch
	"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

prepare() {
	default_prepare
	go mod download
}

build() {
	go build -a -o homer-app
}

check() {
	"$builddir"/homer-app -version
}

package() {
	install -D -m755 "$builddir"/homer-app "$pkgdir"/usr/bin/homer-app
	install -D -m644 etc/webapp_config.json "$pkgdir"/etc/homer/webapp_config.json
	mkdir -p "$pkgdir"/usr/share/webapps/homer \
		"$pkgdir"/usr/share/licenses/$pkgname
	mv "$srcdir"/dist/3rdpartylicenses.txt \
		"$pkgdir"/usr/share/licenses/$pkgname/3rdpartylicenses.txt
	mv "$srcdir"/dist "$pkgdir"/usr/share/webapps/homer
	install -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
}

sha512sums="
9cc6ad6fa2a3199522424a66bfe40c1805c2763d8ef9379a72c236be1b488c8cfa3d4ab5f399db21a82c972b2b1af5cfd53437dcbcf9d2dfaf280690633660c5  homer-app-1.5.2.tar.gz
864634b93eb2fe27af208bde76527153c135d5362989e75884736fd52c56bd413f3f7ebd3fe0079847389ef88c32202a457ac4a288a26c6d3018f8e2836e9441  homer-ui-1.5.2-2.tgz
05bb7d5d0ddb09dd15c8ed21b2fbb2aa6ae3b17be808d64cd6c863c8e72a20d63f0ee4b8419c006ae0c3348c64c1946ab8d4fedf2e4570fccd8ad6fccd6f9377  homer-app.initd
f4073ebe4dda4d94a62a810179b707b5245a15e80473576253b992fd1c0a5ba3dbc2645c56ad10ce63c12ab494a9d9da5fe172b68f1b5594e28b45c18df99fe9  0001-change-web-and-config-paths.patch
"
