#!/bin/sh
CFG=/etc/hwinfo.json
. /usr/share/libubox/jshn.sh

setuci() {
	uci -q batch <<-EOF >/dev/null
		del ucitrack.@gps[-1]
		add ucitrack gps
		set ucitrack.@gps[0].exec="/etc/init.d/gps reload"
		add_list ucitrack.@gps[0].affects="system"
		commit ucitrack
	EOF
}

# remove LuCI cache
json_init
json_load "$(cat ${CFG})"
json_select gps
json_get_var gps defaultgps

[ "$gps" -gt -1 ] && setuci
rm -rf /tmp/luci-indexcache /tmp/luci-modulecache
mkdir /etc/gps_certkey
exit 0
