# $Id$
# Maintainer: Florian Pritz <bluewind@xinu.at>
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Todd Musall <tmusall@comcast.net>
# Contributor: Massimiliano Torromeo <massimiliano.torromeo@gmail.com>

pkgname=apcupsd
pkgver=3.14.13
pkgrel=2
pkgdesc="Power mangement and controlling most of APC's UPS models"
arch=(i686 x86_64)
url="http://www.apcupsd.org"
license=('GPL')
depends=('gcc-libs' 'systemd-sysvcompat')
optdepends=('gd: for CGI'
            'gconf: for frontend'
            'gtk2: for frontend')
makedepends=('pkgconfig' 'gd' 'gconf' 'gtk2')
install=apcupsd.install
backup=(etc/apcupsd/apcupsd.conf
        etc/apcupsd/hosts.conf
        etc/apcupsd/multimon.conf
        etc/apcupsd/apcupsd.css
        etc/apcupsd/changeme
        etc/apcupsd/commfailure
        etc/apcupsd/commok
        etc/apcupsd/offbattery
        etc/apcupsd/onbattery
        etc/apcupsd/apccontrol)
source=(http://downloads.sourceforge.net/apcupsd/$pkgname-$pkgver.tar.gz{,.sig}
        apcupsd.service
        apcupsd-tmpfiles.conf)
sha256sums=('57ecbde01d0448bf8c4dbfe0ad016724ae66ab98adf2de955bf2be553c5d03f9'
            'SKIP'
            '145e88863335f077fc354b4d263b15f64af67b45a10ed37c68ebd468181e23f7'
            'a4474cfcd607c5e9b64e27eec7cbc2b0bcf08c8ea37fd1f0f28e98ac2883fd4f')
validpgpkeys=(635B9D943945DCA05BE9AB0A24E84804A57B2D90)

build() {
	cd "$srcdir/$pkgname-$pkgver"
	./configure --prefix=/usr  --libexecdir=/usr/lib/$pkgname \
		--sbindir=/usr/bin \
		--enable-cgi --enable-usb --enable-net \
		--with-upstype=usb --with-upscable=usb \
		--with-serial-dev=/dev/usb/hid/hiddev[0-9] \
		--enable-pthreads --enable-gapcmon
	make
}

package() {
	cd "$srcdir/$pkgname-$pkgver"

	make DESTDIR="$pkgdir" install

	sed -i 's#^LOCKFILE .*$#LOCKFILE /run/apcupsd#' "$pkgdir/etc/apcupsd/apcupsd.conf"

	install -Dm644 "$srcdir/apcupsd.service" "$pkgdir/usr/lib/systemd/system/apcupsd.service"
	install -Dm644 "$srcdir/apcupsd-tmpfiles.conf" "$pkgdir/usr/lib/tmpfiles.d/apcupsd.conf"

	chmod 755 "$pkgdir"/usr/bin/*

	install -dm755 "$pkgdir/usr/lib/$pkgname/cgi-bin"
	mv "$pkgdir"/etc/apcupsd/*.cgi "$pkgdir/usr/lib/$pkgname/cgi-bin"

	rm -rf "$pkgdir/usr/share/hal"
}