pkgbase=xymon
pkgname=(xymonserver xymonclient)
pkgver=4.3.5
pkgrel=41
pkgdesc="Hobbit is a system for monitoring servers and networks. "
license="GPL"
arch=('i686' 'x86_64')

url="http://www.xymon.com/"

source=(http://voxel.dl.sourceforge.net/project/xymon/Xymon/4.3.5/xymon-4.3.5.tar.gz  hobbitadd.py xymon_ghost_check graph.cfg.diff xymonserver.cfg.diff tasks.d.mv clientlaunch.cfg.patch hobbitstorage.py  hbnotes.py hobbit-myth-orphan.sh  analysis.cfg hbfunc.py be.png tuner.png tv.png  hobbit-mem-myth.sh hobbit_notify.sh alerts.cfg hobbit_myth_data.py logrotate-server.xymon logrotate-client.xymon log_list.sh client-local.cfg.patch led_themes.tar.gz xymon-server.rules hosts.cfg.patch)

depends=(rrdtool fping pcre python2 graphviz 'linhes-scripts>=7-24')

install=xymon.install

build() {

    cd $startdir/src/xymon-$pkgver
    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 \
    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 $startdir/src/xymon-$pkgver
      make PKGBUILD=1 INSTALLROOT=$startdir/pkg/xymonserver install
      cd $startdir/src
      install -D -m400 $startdir/src/xymon-server.rules $startdir/pkg/xymonserver/etc/sudoers.d/xymon_server
      install -D -m755 $startdir/src/hobbitadd.py  $startdir/pkg/xymonserver/home/xymon/server/bin/hobbitadd.py
      install -D -m755 $startdir/src/hobbitstorage.py  $startdir/pkg/xymonserver/home/xymon/server/ext/hobbitstorage.py
      install -D -m755 $startdir/src/hobbit-myth-orphan.sh $startdir/pkg/xymonserver/home/xymon/server/ext/hobbit-myth-orphan.sh
      install -D -m755 $startdir/src/hbfunc.py $startdir/pkg/xymonserver/home/xymon/server/ext/hbfunc.py
      install -D -m755 $startdir/src/hbnotes.py $startdir/pkg/xymonserver/home/xymon/server/ext/hbnotes.py
      install -D -m755 $startdir/src/hobbit_myth_data.py $startdir/pkg/xymonserver/home/xymon/server/ext/hobbit_myth_data.py
      install -D -m755 $startdir/src/hobbit-mem-myth.sh $startdir/pkg/xymonserver/home/xymon/server/ext/hobbit-mem-myth.sh
      install -D -m755 $startdir/src/log_list.sh $startdir/pkg/xymonserver/home/xymon/client/bin/log_list.sh

      install  -m755 analysis.cfg $startdir/pkg/xymonserver/home/xymon/etc/analysis.cfg
      cat alerts.cfg >> $startdir/pkg/xymonserver/home/xymon/etc/alerts.cfg

      install  -m755 hobbit_notify.sh $startdir/pkg/xymonserver/home/xymon/server/bin/hobbit_notify.sh
      install  -m755 $startdir/src/tv.png  $startdir/pkg/xymonserver/data/srv/httpd/htdocs/xymon/gifs/tv.png
      install  -m755 $startdir/src/tuner.png  $startdir/pkg/xymonserver/data/srv/httpd/htdocs/xymon/gifs/tuner.png
      install  -m755 $startdir/src/be.png  $startdir/pkg/xymonserver/data/srv/httpd/htdocs/xymon/gifs/be.png

      install -D  -m644 $startdir/src/logrotate-server.xymon $startdir/pkg/xymonserver/etc/logrotate.d/xymon-server

# fix env for mythtb bindingds
      echo "MYTHCONFDIR=/usr/share/mythtv" >> $startdir/pkg/xymonserver/home/xymon/etc/xymonserver.cfg 


      #copy in replacment icon set
      DOCDIR=$startdir/pkg/xymonserver/data/srv/httpd/htdocs/xymon
      cp -rp  $DOCDIR/gifs $DOCDIR/gifs.orig
      cd $startdir/src/themes
      cp -fp Common/* $DOCDIR/gifs/
      cp -fp ModernLED/* $DOCDIR/gifs/
      #apply patches to conf file
      install -D -m775 $startdir/src/tasks.d.mv $startdir/pkg/xymonserver/home/xymon/etc/tasks.d/mv.cfg
      cd $startdir/pkg/xymonserver/home/xymon/etc
      patch -p0 <  $startdir/src/graph.cfg.diff || return 1
      patch -p0 <  $startdir/src/xymonserver.cfg.diff || return 1
      patch -p3 < $startdir/src/client-local.cfg.patch || return 1
      patch -p3 < $startdir/src/hosts.cfg.patch || return 1
      
      #fix permissions
      chmod 775 $startdir/pkg/xymonserver/data/srv/httpd/htdocs/
      chmod 775 $startdir/pkg/xymonserver/data/srv/httpd/htdocs/xymon/
      chmod 775 $startdir/pkg/xymonserver/data/srv/httpd/htdocs/xymon/notes/
      chmod 775 $startdir/pkg/xymonserver/data/srv/httpd/htdocs/xymon/gifs/
      chmod 750 $startdir/pkg/xymonserver/etc/sudoers.d
    }


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

    install -D -m755 $startdir/src/log_list.sh $startdir/pkg/xymonclient/home/xymon/client/bin/log_list.sh
    install -D  -m644 $startdir/src/logrotate-client.xymon $startdir/pkg/xymonclient/etc/logrotate.d/xymon-client
    install -D -m755 $startdir/src/hobbit-mem-myth.sh $startdir/pkg/xymonclient/home/xymon/client/ext/hobbit-mem-myth.sh
    cp -rp /$startdir/pkg/xymonserver/home/xymon/client/ $startdir/pkg/xymonclient/home/xymon/

    cd -
    cd $startdir/pkg/xymonclient/home/xymon/client/etc
    patch -p0 <  $startdir/src/clientlaunch.cfg.patch
    cd -
    }

md5sums=('31923ec126fe1c264fceb459d2175161'
         'a0fbb9cbeb3600a40943e6205790f22f'
         'c60b0d59bb39505ee3d62c6dd65429c5'
         'a45dd4cdb84817bcf3e51b25cc713799'
         '034658a1084510ecbbb0dc166c0401eb'
         '2d88e59ab17114030da514ba3f0a5b64'
         'ee608dcafc050d790e28647a670f6b60'
         'b2f98ac0df013332deedc1efae0a270d'
         'a652448ebcae3f439c8f23369b69ecf2'
         '0f70e76a164f648f0a4a01110137cb20'
         'f6921f0413215ae174e81306be80d37f'
         '80d9cfac86c6d96836e6f406e35e7cf5'
         'd210c43fb9ee9ad6cd7648e0c2e0efea'
         '0c808fa12672289f86b0651545381308'
         '0469d775db9fdd18ea95dd41937ada82'
         '0757294eec13771f8e63da23cf066796'
         '622f400fd098cbc43c203e3210a6694e'
         '84442377c6e914b65519076bda4e17a4'
         'cd6e52b17f8582614bb52a8157d486c6'
         '67621b6c5a766ac03c5f407bdbdca810'
         '7ad4871af35f82c7824bb682b9325dba'
         '98e9242ae346f729b14cb195786571f2'
         '31ac5c1f6dcc9408b64c4107b325a9a6'
         'c7178bbf384bbe86c318b60fef6faf10'
         '72bf7caf0f53928d97ff5cd9810d6d4d'
         '606f535a49f32b35802ed9d46bd7d068')