#!/bin/sh

uci set uhttpd.main.script_timeout='300'
uci set uhttpd.main.network_timeout='300'
uci set uhttpd.main.rpctimeout='300'
uci set uhttpd.main.max_requests='6'
#uci set uhttps.main.redirect_https='1'
SERIALNUM=`head -c6 /proc/device-tree/lantronix/macaddrs/macaddr0/mac-address | hexdump -v -e '/1 "%2X"' | sed 's/\ /0/g' | grep -v "000000000000"`
MODEL=`cat /proc/device-tree/lantronix/pid | awk '{print substr($0,0,4)}' | tr -d '\n'`
G526RP=`cat /proc/device-tree/lantronix/hwcfg 2>/dev/null | grep 'G526RP' | awk -F'sku=' '{print $2}' | awk -F',' '{print $1}' | awk '{print substr($0,0,6)}' | tr -d '\n'`
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 [[ "$G526RP" != "" ]]; then
	MODEL=$G526RP
fi
[ "$MODEL" == "X30x" ] && {
  	MODEL=`cat /proc/device-tree/lantronix/pid | awk '{print substr($0,6,4)}' | 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


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

exit 0
