# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=kiwiirc
_pkgname=KiwiIRC
pkgver=0.9.4
pkgrel=2
pkgdesc="A hand-crafted webirc client"
url="https://www.kiwiirc.com/"
arch="noarch"
license="AGPL-3.0"
depends="nodejs>=0.10.0"
makedepends="nodejs nodejs-npm"
install="$pkgname.pre-install"
subpackages="$pkgname-doc"
pkgusers="kiwiirc"
pkggroups="kiwiirc"
source="$pkgname-$pkgver.tar.gz::https://github.com/prawnsalad/$_pkgname/archive/v$pkgver.tar.gz
	kiwilauncher.patch
	kiwipath.patch
	$pkgname.initd
	$pkgname.confd"

builddir="$srcdir"/$_pkgname-$pkgver
build() {
	cd "$builddir"
	npm -q install
    npm -q dedupe
}

package() {
	cd "$builddir"
	install -D -m644 config.example.js $pkgdir/etc/kiwiirc/config.js
    install -D -m755 kiwi $pkgdir/usr/bin/kiwi
	install -D -m644 package.json $pkgdir/usr/share/webapps/kiwiirc/package.json
	install -d -m755 $pkgdir/usr/lib/kiwiirc/server_modules
    install -d -m755 $pkgdir/var/lib/kiwiirc
    install -d -m775 $pkgdir/var/run/kiwiirc
    install -d -m644 $pkgdir/var/log/kiwiirc
    install -d -m755 $pkgdir/usr/share/webapps/kiwiirc/server
    install -d -m755 $pkgdir/usr/share/webapps/kiwiirc/node_modules

    cp -a client/* $pkgdir/var/lib/kiwiirc
    cp -a node_modules $pkgdir/usr/share/webapps/kiwiirc/
    cp -a server $pkgdir/usr/share/webapps/kiwiirc
    cp -a server_modules $pkgdir/usr/lib/kiwiirc

    chown -R $pkgusers:$pkggroups "$pkgdir"/etc/kiwiirc
    chown -R $pkgusers:$pkggroups "$pkgdir"/usr/lib/kiwiirc
    chown -R $pkgusers:$pkggroups "$pkgdir"/usr/share/webapps/kiwiirc
    chown -R $pkgusers:$pkggroups "$pkgdir"/var/lib/kiwiirc
    chown $pkgusers:$pkggroups "$pkgdir"/var/run/kiwiirc

    install -D -m755 $srcdir/$pkgname.initd $pkgdir/etc/init.d/$pkgname
    install -D -m644 $srcdir/$pkgname.confd $pkgdir/etc/conf.d/$pkgname
	install -D -m644 LICENSE.txt "$pkgdir"/usr/share/doc/$pkgname/LICENSE.txt
}

md5sums="1a06e33088ca6ed89f857f7687470761  kiwiirc-0.9.4.tar.gz
c92dbf55621e1ed5d130c58405b14919  kiwilauncher.patch
c93b69c4bca4bce7e3e7520b6e9f4588  kiwipath.patch
182ce4e2d858e97bb796c222c1a38e30  kiwiirc.initd
372c26f6b491c2a69f4d8fbaff6a598b  kiwiirc.confd"
sha256sums="72d63c3e88b0e510de761b4fd5ee889e77a3df14a8f2aa425bf291f7dafb23dc  kiwiirc-0.9.4.tar.gz
8099343315fadf5fdc84095eba4a2ec53066b36e2f4f51cd871fe95a8fcc1489  kiwilauncher.patch
5803c819cc35aeeab5b9f69d91afa36f752f9749946cfbbed97fa06d0a444ecd  kiwipath.patch
329ede98f372e0d15bae8a0e6b1210ea27b7fc7607b5cb9e26c82a538e86cfe6  kiwiirc.initd
73a1ec4ce7b379bd3e121100258ce03c45818ecee331c690d42d7fc991692466  kiwiirc.confd"
sha512sums="81034d4b1d6af93bd2fbacd302c0780996b87bbf0b936b61abb1ca04fb97939d956bf4704ada63766a4da04feb56957abf141ed74fff02fd7db237b6272a6ac4  kiwiirc-0.9.4.tar.gz
2b2b61d579fe73ba59c05b3bf9a8ac1bc43225ad414ab34474746731a443c56431ddc9156005a7d3890c65e2344c882d8731c1c36b7a07af0c7014fd4d37e811  kiwilauncher.patch
1bc8829398d1311384f8411bd65f6231831d2f24728d779f97a99b5e7e46758771c36b5daba215fe6508c728162bfbb22fdaa3be2b44988d59c53804e7005c40  kiwipath.patch
a0612b562313eaa6eb2f4fafab2d40ce4784685c8a14e57a5eae8c9126cab3370957dc0a56dace370e10ddb02bda01800063baf6fa66b8159d9f99c06ac85c39  kiwiirc.initd
416b807dee290b0d55020fd980dbf232615f173899d13fe859834cdb61af96a30c5edbeafa35e290cb9d9ed9695ae53abfc876fb4b73687dabfcb3467046a304  kiwiirc.confd"
