#!/bin/sh
[ ! -f "/usr/share/ucitrack/luci-app-linkeasefull.json" ] && {
    cat > /usr/share/ucitrack/luci-app-linkeasefull.json << EEOF
{
    "config": "linkeasefull",
    "init": "linkeasefull"
}
EEOF
}

if ! uci -q get linkeasefull.@linkeasefull[0] >/dev/null; then
	uci -q add linkeasefull linkeasefull >/dev/null
fi

set_default() {
	key="$1"
	value="$2"
	current="$(uci -q get "linkeasefull.@linkeasefull[0].$key" 2>/dev/null || true)"
	[ -n "$current" ] && return 0
	uci -q set "linkeasefull.@linkeasefull[0].$key=$value"
}

set_default enabled 1
uci -q commit linkeasefull

uci -q batch <<-EOF >/dev/null
	delete ucitrack.@linkeasefull[-1]
	add ucitrack linkeasefull
	set ucitrack.@linkeasefull[-1].init=linkeasefull
	commit ucitrack
EOF

/etc/init.d/linkeasefull enable
/etc/init.d/linkeasefull restart

exit 0
