#!/bin/sh

init_system() {
	local x
	local v
	local sys_items="hw_version
modelname
boardid
country_code
user_config_country_code
ethaddr
eth1addr
serial_number"
	local rom_values

	# init system.@system[0] section value with the following priority:
	# u-boot-env  >  /rom/etc/config  >  /etc/config
	IFS=$(echo -en "\n\b")
	for x in $sys_items; do
		v=$(uci -c /rom/etc/config get system.@system[0].$x)
		rom_values="$rom_values$v$(echo -en '\n\b')"
	done
	set -- $rom_values
	for x in $sys_items; do
		v=$(fw_getenv $x)
		v=${v:-$1}
		if [ "$v" != "$(system.@system[0].$x)" ]; then
			uci set system.@system[0].$x=$v
		fi
		shift
	done
}

init_system
