# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=apcupsd
pkgver=3.14.14
pkgrel=0
pkgdesc="A Daemon to control APC UPSes"
subpackages="$pkgname-doc $pkgname-webif"
url="http://www.apcupsd.org"
arch="all"
license="GPL-2.0"
depends="util-linux"
makedepends="net-snmp-dev man linux-headers gd-dev"
source="http://downloads.sourceforge.net/$pkgname/$pkgname-$pkgver.tar.gz
	apcupsd.initd
	apcupsd-alpine.patch
	"

_builddir="$srcdir/$pkgname-$pkgver"
prepare() {
	cd "$_builddir"
	update_config_sub || return 1
}

build() {
	cd "$_builddir"
	patch -p1 < ../apcupsd-alpine.patch || return 1

	export CHARSET="ISO8859-1"
	export LANG="C"

	ac_cv_path_SHUTDOWN="/sbin/poweroff" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--mandir=/usr/share/man \
		--enable-usb \
		--enable-snmp \
		--enable-cgi \
		|| return 1
	make || return 1
}

package() {
	cd "$_builddir"
	make DESTDIR=$pkgdir install || return 1
	install -D -m755 "$srcdir"/apcupsd.initd "$pkgdir"/etc/init.d/apcupsd
}

webif() {
	cd "$_builddir"
	mkdir -p "$subpkgdir"/usr/share/webapps/apcupsd
	mv "$pkgdir"/etc/apcupsd/*.cgi "$subpkgdir"/usr/share/webapps/apcupsd
}

md5sums="cc8f5ced77f38906a274787acb9bc980  apcupsd-3.14.14.tar.gz
72f6a0392cef1120b88233c5a7266bd0  apcupsd.initd
e22bd5b8361faca0f4d1a1a508c7a906  apcupsd-alpine.patch"
sha256sums="db7748559b6b4c3784f9856561ef6ac6199ef7bd019b3edcd7e0a647bf8f9867  apcupsd-3.14.14.tar.gz
c9bf632a83228966d4ecc268c4ab5e20b2cd4100c1100f3ecb11d2c8efacc1c4  apcupsd.initd
e2ff324b94e80b701e2cba36226706653829d46535f41b5bd9b2ffd2fb705681  apcupsd-alpine.patch"
sha512sums="c953bbf3e08f809748a7978a3952604176390d1cd276f187fe096d9bc3c8993b52127e8350c0363387da41318e24b4d1e00ea58df71f3bb8f50c9a5a64cd2d7f  apcupsd-3.14.14.tar.gz
cd9cb3c812dfd72660007807965cac866dfb2ce4bd8200668f08e94fdcce874cce2ec87a0d832b8f37f254908d093aff0cc2db26e9403d5e613dc192072da617  apcupsd.initd
4f0712519213c4ef14f41eeef681c5498fac7bf42f205de8a855938f8e834d9488d86820d7c883e89d0d305ee287e17e2d321dbbc98ae12f8487bf58aa0d4a6b  apcupsd-alpine.patch"
