# Maintainer: Kurt Marasco <celilo@lavabit.com>
# Contributor: Pascal Ernster <aur at hardfalcon dot net>

pkgname=hiawatha
pkgver=10.8
pkgrel=0
pkgdesc='Secure and advanced webserver'
url='https://www.hiawatha-webserver.org/'
arch=all
license='GPL'
options="suid !check"
subpackages="$pkgname-doc"
makedepends="cmake libxml2-dev libxslt-dev mbedtls-dev"
source="https://hiawatha-webserver.org/files/$pkgname-$pkgver.tar.gz
        hiawatha.initd
        hiawatha.conf.sample"
builddir="$srcdir"/$pkgname-$pkgver

build() {
  cd "$builddir"
  cmake . -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_BINDIR=/usr/bin \
    -DCMAKE_INSTALL_SBINDIR=/usr/sbin \
    -DCMAKE_INSTALL_SYSCONFDIR=/etc/hiawatha \
    -DCMAKE_INSTALL_LIBDIR=/usr/lib \
    -DCMAKE_INSTALL_MANDIR=/usr/share/man \
    -DCONFIG_DIR=/etc/hiawatha \
    -DLOG_DIR=/var/log/hiawatha \
    -DPID_DIR=/var/run \
    -DUSE_SYSTEM_MBEDTLS=ON \
    -DWEBROOT_DIR=/var/www/hiawatha \
    -DWORK_DIR=/var/lib/hiawatha

    make
}

package() {
  cd "$builddir"
  make DESTDIR="$pkgdir/" install

  sed -i 's|#ServerId = www-data|ServerId = nobody|' \
    "$pkgdir"/etc/hiawatha/hiawatha.conf
  sed -i 's|www-data|nobody|g' logrotate.d/hiawatha
  install -Dm644 logrotate.d/hiawatha \
    "$pkgdir"/etc/logrotate.d/hiawatha
  install -Dm755 "$srcdir"/hiawatha.initd \
    "$pkgdir"/etc/init.d/hiawatha
  install -Dm644 "$srcdir"/hiawatha.conf.sample \
    "$pkgdir"/usr/share/doc/hiawatha/hiawatha.conf.sample
}

sha512sums="949ac41ba9fa61632c592db4738a99b807d31c7ac88d97d0c2bb5fb87cd438f1d5379317fec77c663c4ca4e5c4fb83f7efde2a0ad8d0ca65ac9115ed8e76d46c  hiawatha-10.8.tar.gz
4e1201110396e13b979948caae9c2dfb34f55398225d924164d2f0818b6778500ef3426b0ad358210ef7780289fbd752f7e006220941437fbcdd378746bf5a3d  hiawatha.initd
b2aad6d02e03a3e25dc6dc30deab4637a7de5448255b6b707363e8c71ae1029e669bacdb6b88889ec1aa804fe717560e872dc44d049127af9aa155a8895c8a60  hiawatha.conf.sample"
