#!/bin/sh

PATH=/sbin:/usr/sbin:/bin:/usr/bin
export PATH

. /etc/onapp.conf

ETHERNET=`ls -d /var/run/dhclient\-*\.pid 2>/dev/null | head -1 | cut -d '-' -f 2 | cut -d '.' -f 1`
if [ -z "${ETHERNET}" ]; then
	ETHERNET=MGT
fi
IP=`/sbin/ip addr show ${ETHERNET} scope global primary | grep -Ex "[[:blank:]]+inet.+scope global ${ETHERNET}" | sed 's/^.*inet\ //;s/[\/\ ].*$//'`
[ -n "${IP}" ] || exit 1

# Setup snmpd and snmptrapd
SNMPDCONF=/etc/snmp/snmpd.conf
SNMPTRAPDCONF=/etc/snmp/snmptrapd.conf
sed -i -e "s/\<IP_OF_HV\>/${IP}/g" ${SNMPDCONF}
sed -i -e "s/\<IP_OF_CP\>/${HOST}/g" ${SNMPDCONF}
sed -i -e "s/\<IP_OF_HV\>/${IP}/g" ${SNMPTRAPDCONF}
sed -i -e "s/\<IP_OF_CP\>/${HOST}/g" ${SNMPTRAPDCONF}
