#!/bin/sh

commit=0

if [ -z "$(uci -q get uhttpd.main.ubus_prefix)" ]; then
	uci set uhttpd.main.ubus_prefix=/ubus
	commit=1
fi

[ "$(uci -q get uhttpd.main.ubus_socket)" = "/var/run/ubus.sock" ] && {
	uci set uhttpd.main.ubus_socket='/var/run/ubus/ubus.sock'
	commit=1
}

[ "$commit" = 1 ] && uci commit uhttpd 

#QL: don't reload uhttpd if uhttpd is not running; 
#This is to meet the requirement of preventing uhttpd from auto-starting when the device boots up.
if [ "$commit" == 1 ] && pgrep uhttpd > /dev/null; then
	/etc/init.d/uhttpd reload
fi

exit 0
