#!/bin/sh

# step 1:
# initial batch of units shipped without epic.io section
# we need to make sure it exists for proper operation
if [ -z "$(uci -q get epic.io)" ]; then
    uci set epic.io='section'
    uci set epic.io.notify_relay1='false'
    uci set epic.io.notify_relay2='false'
    uci set epic.io.notify_relay3='false'
    uci set epic.io.notify_relay4='false'
    uci commit
fi


if [ -z "$(uci -q get epic.sip.input_gain)" ]; then
    uci set epic.sip.input_gain='100'
    uci commit
fi


if [ -z "$(uci -q get epic.sip.hdx_level)" ]; then
    uci set epic.sip.hdx_level='0.05'
    uci set epic.sip.hdx_timeout='600'
    uci commit
fi


if [ -z "$(uci -q get epic.snmp)" ]; then
    uci set epic.snmp='snmp'
    uci set epic.snmp.enable='false'
    uci commit
fi

if [ -z "$(uci -q get epic.serialgw.baud)" ]; then
    uci set epic.serialgw.baud='9600'
    uci set epic.serialgw.databits='8'
    uci set epic.serialgw.parity='NONE'
    uci set epic.serialgw.stopbits='1'
    uci commit
fi

if [ -z "$(uci -q get ae_ms.talkback.level_rp1)" ]; then
    uci set ae_ms.talkback.level_rp1='-79'
    uci commit
fi

# Create the snmpd.conf
echo "sysObjectID .1.3.6.1.4.1.17491.1.161" > /etc/snmp/snmpd.conf

SYS_NAME=$(uci get epic.main.device_alias)
echo "sysName \"$SYS_NAME\"" >> /etc/snmp/snmpd.conf

echo "view customView included .1.3.6.1.2.1.1.1" >> /etc/snmp/snmpd.conf
echo "view customView included .1.3.6.1.2.1.1.2" >> /etc/snmp/snmpd.conf
echo "view customView included .1.3.6.1.2.1.1.3" >> /etc/snmp/snmpd.conf
echo "view customView included .1.3.6.1.2.1.1.5" >> /etc/snmp/snmpd.conf
echo "view customView included .1.3.6.1.4.1.17491.1.161" >> /etc/snmp/snmpd.conf

echo "rocommunity AESNMP1978 default -V customView" >> /etc/snmp/snmpd.conf
echo "pass_persist .1.3.6.1.4.1.17491.1.161 /barix/apps/epic-sip/SNMP/snmp_controller.py" >> /etc/snmp/snmpd.conf

/etc/init.d/snmpd restart

touch /barix/apps/epic-sip/updated_flag

#UCI_MODEL=$(uci -q get "epic.main.model")
#if [ "$MODEL" != "$UCI_MODEL" ]; then
#    cp /barix/config/defaults/epic /barix/config/current/epic
#    cp /barix/config/defaults/ae_ms /barix/config/current/ae_ms
#fi

true
