#!/bin/bash


set -e


case "$1" in
    configure)
        echo "[main]" > /etc/yabs-graphite-client/graphite-client.cfg
        #chek if host in production vlan
	if [ -n "$PSEUDO_HOSTNAME" ]
	then
		HOSTNAME="$PSEUDO_HOSTNAME"
	else
		HOSTNAME=`hostname --fqdn`
	fi
        #chek if host in production vlan

       	/usr/bin/yabs-genconf.pl --config=/etc/yabs-graphite-client/graphite-client.yml | sort >> /etc/yabs-graphite-client/graphite-client.cfg
        # restart sender
        service graphite-sender stop  || true
        service graphite-sender start || true
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac


#DEBHELPER#


exit 0
