# $Id: PKGBUILD 158941 2012-05-13 14:21:11Z thomas $
# Maintainer: Thomas Bächler <thomas@archlinux.org>

pkgname=watchdog
pkgver=5.12
pkgrel=1
pkgdesc="Watchdog daemon"
arch=(i686 x86_64)
url="http://sourceforge.net/projects/watchdog"
license=('GPL')
depends=('glibc')
backup=(etc/watchdog.conf
        etc/conf.d/watchdog
        etc/conf.d/wd_keepalive)
source=(http://downloads.sourceforge.net/${pkgname}/${pkgname}-${pkgver}.tar.gz
        watchdog.sh
        watchdog.cf
        watchdog-5.12-fix-oom-in-wd_keepalive.patch)
md5sums=('cea28bea70e54f3625062bc808aef9af'
         '854451f554718b55186599faaa8d85f6'
         '01c1e2e13f515131180b4ebe9b8b7cc3'
         'c90c2686975b5254f82b3de683f1f442')

build() {
  cd "${srcdir}"/${pkgname}-${pkgver}

  patch -p1 -i "${srcdir}"/watchdog-5.12-fix-oom-in-wd_keepalive.patch
  ./configure \
	--prefix=/usr \
	--mandir=/usr/share/man \
	--sysconfdir=/etc \
	--localstatedir=/var
  make
}

package() {
  cd "${srcdir}"/${pkgname}-${pkgver}
  make install DESTDIR="${pkgdir}"
  for fil in watchdog wd_keepalive ; do
	install -D -m755 "${srcdir}"/watchdog.sh "${pkgdir}"/etc/rc.d/${fil}
	install -D -m644 "${srcdir}"/watchdog.cf "${pkgdir}"/etc/conf.d/${fil}
  done

  sed -i 's/watchdog/wd_keepalive/g' "${pkgdir}"/etc/rc.d/wd_keepalive
  sed -i 's/watchdog/wd_keepalive/g' "${pkgdir}"/etc/conf.d/wd_keepalive
  sed -i 's/Watchdog/Simple Watchdog/' "${pkgdir}"/etc/rc.d/wd_keepalive
}