# Maintainer: Phillip Smith <fukawi2@NO-SPAM.gmail.com>
# Contributor: Piotr Beling <qwak@w8.pl>

pkgname=awstats
pkgver=7.0
pkgrel=1
pkgdesc="tool that generates web, streaming, ftp and mail server statistics, graphically"
arch=('any')
license=('GPL')
url="http://awstats.sourceforge.net/"
depends=('perl')
optdepends=('mod_perl: if you are using Apache as your HTTP server' 'mod_cgi: if you are using lighttpd as your HTTP server')
install="awstats.install"
backup=('etc/awstats/awstats.model.conf' 'etc/httpd/conf/extra/httpd-awstats.conf')
source=("http://downloads.sourceforge.net/${pkgname}/${pkgname}-${pkgver}.tar.gz"
        'cron.awstats')
md5sums=('3e8e09b9ebe74513bb34290dbcd37b45'
         '2103e3d97f8b4ff31cd4022c4ee839f7')

package() {
	_SYSCONFDIR='etc'
	_WWWROOT='srv/http/awstats'
	_INSTDIR="usr/share/${pkgname}"
	_DOCDIR="usr/share/doc/${pkgname}-${pkgver}"

	cd $srcdir/${pkgname}-${pkgver}

  install -d -m 0755 $pkgdir/$_SYSCONFDIR/$pkgname/
	install -d -m 0755 $pkgdir/$_INSTDIR/tools/webmin/
	install -d -m 0755 $pkgdir/$_INSTDIR/tools/xslt/
	install -d -m 0755 $pkgdir/$_WWWROOT/
	install -d -m 0755 $pkgdir/$_DOCDIR/
	install -d -m 0755 $pkgdir/var/lib/$pkgname

	# Arch specific path:
	install -m 0644 -D tools/httpd_conf $pkgdir/${_SYSCONFDIR}/httpd/conf/extra/httpd-awstats.conf
	install -m 0644 wwwroot/cgi-bin/awstats.model.conf $pkgdir/${_SYSCONFDIR}/awstats/awstats.model.conf
	install -m 0744 -D $srcdir/cron.awstats $pkgdir/${_SYSCONFDIR}/cron.hourly/awstats

	install -m 0755 tools/logresolvemerge.pl $pkgdir/$_INSTDIR/tools/logresolvemerge.pl
	install -m 0755 tools/maillogconvert.pl $pkgdir/$_INSTDIR/tools/maillogconvert.pl
	install -m 0755 tools/urlaliasbuilder.pl $pkgdir/$_INSTDIR/tools/urlaliasbuilder.pl
	install -m 0755 tools/awstats_buildstaticpages.pl $pkgdir/$_INSTDIR/tools/awstats_buildstaticpages.pl
	install -m 0755 tools/awstats_configure.pl $pkgdir/$_INSTDIR/tools/awstats_configure.pl
	install -m 0755 tools/awstats_exportlib.pl $pkgdir/$_INSTDIR/tools/awstats_exportlib.pl
	install -m 0755 tools/awstats_updateall.pl $pkgdir/$_INSTDIR/tools/awstats_updateall.pl
	install -m 0755 tools/webmin/* $pkgdir/$_INSTDIR/tools/webmin
	install -m 0755 tools/xslt/* $pkgdir/$_INSTDIR/tools/xslt

	# install the documentation
	cp -ra docs/* $pkgdir/$_DOCDIR/

	# www files
	cp -ra wwwroot/* $pkgdir/$_WWWROOT/
  rm -f $pkgdir/$_WWWROOT/cgi-bin/awstats.model.conf
	install -m 0444 README.TXT $pkgdir/$_INSTDIR/README.TXT

	# fix the default http config
	sed \
  	-e "s|/usr/local/awstats/wwwroot|/$_WWWROOT|g" \
	  -i $pkgdir/${_SYSCONFDIR}/httpd/conf/extra/httpd-awstats.conf

  sed \
    -e "s|/usr/local/awstats/wwwroot/cgi-bin/awstats.pl|/$_WWWROOT/cgi-bin/awstats.pl|g" \
    -i $pkgdir/$_INSTDIR/tools/awstats_updateall.pl \
    -i $pkgdir/$_INSTDIR/tools/awstats_buildstaticpages.pl \
    -i $pkgdir/$_INSTDIR/tools/awstats_exportlib.pl \
    -i $pkgdir/$_INSTDIR/tools/awstats_configure.pl

	echo "deny from all" > $pkgdir/.htaccess
}

# vim:set ts=2 sw=2 et:
