pkgbase=xymon
pkgname=('xymonserver' 'xymonclient')
pkgver=4.3.28
pkgrel=7
pkgdesc="Xymon is a system for monitoring of hosts and networks"
license=('GPL')
arch=('i686' 'x86_64')
url="http://www.xymon.com/"
source=("https://downloads.sourceforge.net/project/xymon/Xymon/$pkgver/$pkgbase-$pkgver.tar.gz"
        'alerts.cfg'
        'analysis.cfg.patch'
        'be.png' 'tuner.png' 'tv.png'
        'clientlaunch.cfg.patch'
        'client-local.cfg.patch'
        'graphs.cfg.diff'
        'hbfunc.py'
        'hbnotes.py'
        'hobbit_notify.sh'
        'hobbit-mem-myth.sh'
        'hobbit-myth-orphan.sh'
        'hobbit_myth_data.py'
        'hobbitadd.py'
        'hobbitstorage.py'
        'hosts.cfg.patch'
        'log_list.sh'
        'logfetch.c.patch'
        'led_themes.tar.gz'
        'login_notify.sh'
        'logrotate-server.xymon'
        'logrotate-client.xymon'
        'tasks.d.mv'
        'xymon_ghost_check'
        'xymon-gputemp.sh'
        'xymon-hddtemp.sh'
        'xymon-smart.sh'
        'xymon-server.include'
        'xymon-server.gen_light_conf.d'
        'xymonserver.cfg.diff'
        'xymon-server.rules'
        'xymon-client.rules'
        )
depends=('rrdtool' 'fping' 'pcre' 'python2' 'graphviz' 'smartmontools')
install=xymon-server.install

build() {
    cd ${srcdir}/xymon-$pkgver
    patch -p2 < $srcdir/logfetch.c.patch
    ENABLESSL=n \
    ENABLELDAP=n \
    ENABLELDAPSSL=n \
    XYMONUSER=nobody \
    XYMONTOPDIR=/home/xymon \
    XYMONVAR=/home/xymon/var \
    XYMONHOSTURL=/xymon \
    CGIDIR=/data/srv/httpd/htdocs/xymon/hobbit-cgi \
    XYMONCGIURL=/xymon/hobbit-cgi \
    SECURECGIDIR=/data/srv/httpd/htdocs/xymon/hobbit-seccgi \
    SECUREXYMONCGIURL=/xymon/hobbit-seccgi \
    HTTPDGID=nobody \
    XYMONLOGDIR=/var/log/hobbit \
    XYMONHOSTNAME=localhost \
    XYMONHOSTIP=127.0.0.1 \
    MANROOT=/usr/share/man \
    BARS=all \
    USENEWHIST=y \
    USEXYMONPING=n \
    PIXELCOUNT=960 \
    INSTALLBINDIR=/home/xymon/server/bin \
    INSTALLETCDIR=/home/xymon/etc \
    INSTALLWEBDIR=/home/xymon/web \
    INSTALLEXTDIR=/home/xymon/server/ext \
    INSTALLTMPDIR=/home/xymon/tmp \
    INSTALLWWWDIR=/data/srv/httpd/htdocs/xymon/ \
    ./configure

    make PKGBUILD=1|| return 1
}

package_xymonserver(){
    backup=('data/srv/xymon/etc/hosts.cfg')
    cd ${srcdir}/xymon-$pkgver
    make PKGBUILD=1 INSTALLROOT=${pkgdir} install
    cd ${srcdir}
    install -D -m400 ${srcdir}/xymon-server.rules ${pkgdir}/etc/sudoers.d/xymon_server
    install -D -m755 ${srcdir}/hobbitadd.py ${pkgdir}/home/xymon/server/bin/hobbitadd.py
    install -D -m755 ${srcdir}/hobbitstorage.py ${pkgdir}/home/xymon/server/ext/hobbitstorage.py
    install -D -m755 ${srcdir}/hobbit-myth-orphan.sh ${pkgdir}/home/xymon/server/ext/hobbit-myth-orphan.sh
    install -D -m755 ${srcdir}/hbfunc.py ${pkgdir}/home/xymon/server/ext/hbfunc.py
    install -D -m755 ${srcdir}/hbnotes.py ${pkgdir}/home/xymon/server/ext/hbnotes.py
    install -D -m755 ${srcdir}/hobbit_myth_data.py ${pkgdir}/home/xymon/server/ext/hobbit_myth_data.py
    install -D -m755 ${srcdir}/hobbit-mem-myth.sh ${pkgdir}/home/xymon/server/ext/hobbit-mem-myth.sh
    install -D -m755 ${srcdir}/xymon-gputemp.sh ${pkgdir}/home/xymon/server/ext/xymon-gputemp.sh
    install -D -m755 ${srcdir}/xymon-hddtemp.sh ${pkgdir}/home/xymon/server/ext/xymon-hddtemp.sh
    install -D -m755 ${srcdir}/xymon-smart.sh ${pkgdir}/home/xymon/server/ext/xymon-smart.sh
    install -D -m755 ${srcdir}/log_list.sh ${pkgdir}/home/xymon/client/bin/log_list.sh

    cat alerts.cfg >> ${pkgdir}/home/xymon/etc/alerts.cfg

    install -m755 hobbit_notify.sh ${pkgdir}/home/xymon/server/bin/hobbit_notify.sh
    install -m755 login_notify.sh ${pkgdir}/home/xymon/server/bin/login_notify.sh
    install -m755 ${srcdir}/tv.png ${pkgdir}/data/srv/httpd/htdocs/xymon/gifs/tv.png
    install -m755 ${srcdir}/tuner.png ${pkgdir}/data/srv/httpd/htdocs/xymon/gifs/tuner.png
    install -m755 ${srcdir}/be.png ${pkgdir}/data/srv/httpd/htdocs/xymon/gifs/be.png

    install -D -m644 ${srcdir}/logrotate-server.xymon ${pkgdir}/etc/logrotate.d/xymon-server

    # fix env for mythtv bindings
    echo "MYTHCONFDIR=/usr/share/mythtv" >> ${pkgdir}/home/xymon/etc/xymonserver.cfg
    echo "MYTHCONFDIR=/usr/share/mythtv" >> ${pkgdir}/home/xymon/client/etc/xymonclient.cfg

    #copy in replacment icon set
    DOCDIR=${pkgdir}/data/srv/httpd/htdocs/xymon
    cp -rp ${DOCDIR}/gifs ${DOCDIR}/gifs.orig
    cd ${srcdir}/themes
    cp -fp Common/* ${DOCDIR}/gifs/
    cp -fp ModernLED/* ${DOCDIR}/gifs/

    #apply patches to conf file
    install -D -m775 ${srcdir}/tasks.d.mv ${pkgdir}/home/xymon/etc/tasks.d/mv.cfg
    cd ${pkgdir}/home/xymon/etc
    patch -p0 < ${srcdir}/graphs.cfg.diff || return 1
    patch -p0 < ${srcdir}/xymonserver.cfg.diff || return 1
    patch -p0 < ${srcdir}/analysis.cfg.patch || return 1
    patch -p3 < ${srcdir}/client-local.cfg.patch || return 1
    patch -p3 < ${srcdir}/hosts.cfg.patch || return 1

    #make dir for login alerts
    mkdir ${pkgdir}/home/xymon/var/login_alerts

    #add custom module descriptions
    COLDOC=$pkgdir/home/xymon/etc/columndoc.csv
    echo "myth_mtc;The <b>myth_mtc</b> column shows the status of the MythTV maintenance script.;" >> $COLDOC
    echo "orphan;The <b>orphan</b> column shows the status of the find_orphans.py script.;" >> $COLDOC

    #move cgiwrap to same partiton as hobbit-cgi and hobbit-seccgi
    #because pacman is not able to install hardlinks accross partitions
    mv ${pkgdir}/home/xymon/server/bin/cgiwrap ${pkgdir}/data/srv/httpd/htdocs/xymon/

    #install conf files for lighttpd
    mkdir -p ${pkgdir}/etc/lighttpd
    install -D -m 644 ${srcdir}/xymon-server.include ${pkgdir}/etc/lighttpd/
    #gen_light_conf
    install -D -m 744 ${srcdir}/xymon-server.gen_light_conf.d ${pkgdir}/etc/gen_light_conf.d/xymon-server.conf

    #fix permissions
    chmod 755 ${pkgdir}/data/srv/httpd/htdocs/
    chmod 775 ${pkgdir}/data/srv/httpd/htdocs/xymon/
    chmod 755 ${pkgdir}/data/srv/httpd/htdocs/xymon/cgiwrap
    chmod 775 ${pkgdir}/data/srv/httpd/htdocs/xymon/notes/
    chmod 775 ${pkgdir}/data/srv/httpd/htdocs/xymon/gifs/
    chmod 775 ${pkgdir}/data/srv/httpd/htdocs/xymon/snap/
    chmod 775 ${pkgdir}/data/srv/httpd/htdocs/xymon/rep/
    chmod 750 ${pkgdir}/etc/sudoers.d
    chmod 775 ${pkgdir}/home/xymon/var/login_alerts
    }


package_xymonclient(){
    #create client package as well
    depends=('smartmontools')
    backup=('data/srv/xymon/client/etc/xymonclient.cfg')
    install=xymon-client.install

    install -D -m400 ${srcdir}/xymon-client.rules ${pkgdir}/etc/sudoers.d/xymon_client
    install -D -m755 ${srcdir}/log_list.sh ${pkgdir}/home/xymon/client/bin/log_list.sh
    install -D -m644 ${srcdir}/logrotate-client.xymon ${pkgdir}/etc/logrotate.d/xymon-client
    install -D -m755 ${srcdir}/hobbit_myth_data.py ${pkgdir}/home/xymon/client/ext/hobbit_myth_data.py
    install -D -m755 ${srcdir}/hobbit-mem-myth.sh ${pkgdir}/home/xymon/client/ext/hobbit-mem-myth.sh
    install -D -m755 ${srcdir}/xymon-gputemp.sh ${pkgdir}/home/xymon/client/ext/xymon-gputemp.sh
    install -D -m755 ${srcdir}/xymon-hddtemp.sh ${pkgdir}/home/xymon/client/ext/xymon-hddtemp.sh
    install -D -m755 ${srcdir}/xymon-smart.sh ${pkgdir}/home/xymon/client/ext/xymon-smart.sh
    cp -rp ${pkgdir}/../xymonserver/home/xymon/client/ ${pkgdir}/home/xymon/

    cd -
    cd ${pkgdir}/home/xymon/client/etc
    patch -p0 < ${srcdir}/clientlaunch.cfg.patch
    cd -
    }

md5sums=('14501ab2cfce9a332c1590543dfcbd0f'
         '9af2ad60ac4c3cb653754618f603e311'
         'ecf9c4c878b676ca8be5a547888359ed'
         'd210c43fb9ee9ad6cd7648e0c2e0efea'
         '0c808fa12672289f86b0651545381308'
         '0469d775db9fdd18ea95dd41937ada82'
         'c9a31ea9ae131fb351db913e922c25aa'
         '31ac5c1f6dcc9408b64c4107b325a9a6'
         '1eee1cf4ded13fcef9f3b43faa20dbe1'
         '80d9cfac86c6d96836e6f406e35e7cf5'
         'df77d1de72157d23a301a72288fbf7e5'
         'b1d5592fa92ef71303621964e84c2b9e'
         'f1146cc034f6d11e7d7e68f24bc89dff'
         '2a509d81ee1655130ce40bf970719e0a'
         '313b11e7a22c3c08fb2afaadbfb46d87'
         'a0fbb9cbeb3600a40943e6205790f22f'
         'b2f98ac0df013332deedc1efae0a270d'
         '606f535a49f32b35802ed9d46bd7d068'
         '98e9242ae346f729b14cb195786571f2'
         '7d8689cc88ccca5bf7b2b454a909db72'
         'c7178bbf384bbe86c318b60fef6faf10'
         '22d4c9065fd959efe82f121dcb511305'
         'b4e8641e97e6b689dbc634af785e6799'
         'e2844513e2c92e8b5084818f3b2a478d'
         'a19c8c546dcd95049476bb19f9d4e3ae'
         'c60b0d59bb39505ee3d62c6dd65429c5'
         'd4710f9aaa5aef0c9d0a26fa7d94450f'
         'c4e1575db32c633a531df9514d83aa82'
         '281a5031824c8d98b4e541fed6da09ed'
         '1a00c0b9b9b1a37f1513fa8489ce9d31'
         '3d1f311f0142f41d763276302a7ce396'
         'c75c434ba9c39a914e7693004b580554'
         'e9dbff011e57861266d27dfdf465a4b3'
         'cdfbca43dbae4ce0ca72dd002ec22af1')