#!/bin/sh

uci set luci.main.pollinterval='5'
uci set rpcd.@rpcd[0].timeout='60'
uci set system.manualtime='manualtime'
uci commit system
uci commit luci
uci commit rpcd

# remove LuCI cache
rm -rf /tmp/luci-indexcache /tmp/luci-modulecache

SERIALNUM=`head -c6 /proc/device-tree/lantronix/macaddrs/macaddr0/mac-address | hexdump -v -e '/1 "%2X"' | sed 's/\ /0/g' | grep -v "000000000000"`
EDS5K=`cat /proc/device-tree/lantronix/hwcfg 2>/dev/null | grep 'EDS50' | awk -F'sku=' '{print $2}' | awk -F',' '{print $1}' | awk '{print substr($0,0,7)}' | tr -d '\n'`

if [[ "$EDS5K" != "" ]]; then
	MODEL=$EDS5K
else
	MODEL="EDS5K"
fi

if [[ "$SERIALNUM" != "" ]]; then
	uci set system.system.hostname='Lantronix'-$MODEL-$SERIALNUM
	uci commit system
else
	uci set system.system.hostname='Lantronix'-$MODEL
	uci commit system
fi

exit 0
