# Maintainer: Lukas Fleischer <lfleischer@archlinux.org>
# Contributor: Jaroslav Lichtblau <dragonlord@aur.archlinux.org>
# Contributor: Pierre Schmitz <pierre@archlinux.de>

pkgname=rkhunter
pkgver=1.4.6
pkgrel=4
pkgdesc='Checks machines for the presence of rootkits and other unwanted tools.'
arch=('any')
url='http://rkhunter.sourceforge.net/'
license=('GPL')
depends=('bash' 'perl' 'wget')
optdepends=('unhide')
backup=('etc/rkhunter.conf')
source=("https://downloads.sourceforge.net/sourceforge/${pkgname}/${pkgname}-${pkgver}.tar.gz"{,.asc})
md5sums=('35bf1e2850343a4768e34a3fc260b8a1'
         'SKIP')
sha256sums=('f750aa3e22f839b637a073647510d7aa3adf7496e21f3c875b7a368c71d37487'
            'SKIP')
validpgpkeys=('9713808A269FA0326356958BE9C5DC50D13AAA83')  # John Horne

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

  # fix installer for x86_64
  sed -i -e "s/lib64/lib/g" installer.sh

  # install to "/usr"
  install -dm0755 "${pkgdir}/usr"
  ./installer.sh --layout custom "${pkgdir}/usr" --striproot "${pkgdir}" --install

  # fix paths
  mv "${pkgdir}/usr/etc" "${pkgdir}"
  mv "${pkgdir}/usr/var" "${pkgdir}"

  sed -i -e "s#/usr/etc/rkhunter.conf#/etc/rkhunter.conf#g" "${pkgdir}/usr/bin/${pkgname}"
  sed -i -e "s#/usr/etc/rkhunter.conf#/etc/rkhunter.conf#g" "${pkgdir}/etc/${pkgname}.conf"
  sed -i -e "s#/usr/var/lib/rkhunter/db#/var/lib/rkhunter/db#g" "${pkgdir}/etc/${pkgname}.conf"
  sed -i -e "s#/usr/var/lib/rkhunter/tmp#/var/lib/rkhunter/tmp#g" "${pkgdir}/etc/${pkgname}.conf"

  # cleanup
  rm -f "${pkgdir}/var/lib/${pkgname}/tmp/"{group,passwd}

  # we trust in udev
  sed -i 's|^#ALLOWHIDDENDIR=/dev/.udev$|ALLOWHIDDENDIR=/dev/.udev|' \
    "${pkgdir}/etc/${pkgname}.conf"
}
