#!/bin/sh

if [ "$(uci -q get luci.diag)" != "internal" ]; then
	host=""

	if [ -s /etc/os-release ]; then
		. /etc/os-release
		host="${HOME_URL:-${BUG_URL:-$LEDE_DEVICE_MANUFACTURER_URL}}"
		host="${host#*://}"
		host="${host%%/*}"
	fi

	uci -q batch <<-EOF >/dev/null
		set luci.diag=internal
		set luci.diag.dns='${host:-openwrt.org}'
		set luci.diag.ping='${host:-openwrt.org}'
		set luci.diag.route='${host:-openwrt.org}'
		commit luci
	EOF
fi

if [ -n "$(command -v cpuinfo)" ]; then
	if [ -n "$(command -v ethinfo)" ]; then
		[ -f /usr/lib/lua/luci/view/admin_status/index_x86.htm ] && {
			mv /usr/lib/lua/luci/view/admin_status/index_x86.htm /usr/lib/lua/luci/view/admin_status/index.htm
		}
	else
		[ -f /usr/lib/lua/luci/view/admin_status/index_arm.htm ] && {
			mv /usr/lib/lua/luci/view/admin_status/index_arm.htm /usr/lib/lua/luci/view/admin_status/index.htm
		}
	fi
fi
rm -f /usr/lib/lua/luci/view/admin_status/index_x86.htm
rm -f /usr/lib/lua/luci/view/admin_status/index_arm.htm
exit 0
