#!/bin/sh
#
# # Copyright (C) 2024 Teltonika-Networks
#

. /lib/functions/system.sh
. /lib/functions/uci-defaults.sh

[ -f /lib/functions/target-defaults.sh ] && \
	. /lib/functions/target-defaults.sh

setup_json() {
	local model="$(mnf_info --name)" 2>/dev/null;
	local branch_path="/sys/mnf_info/branch"
	local branch
	[ -f "$branch_path" ] && branch="$(cut -c -2 $branch_path)"

	local hw_ver="$(cut -c -2 /sys/mnf_info/hwver)"
	[ "$hw_ver" = "00" ] && hw_ver="$(cut -c 3-4 /sys/mnf_info/hwver)"

	case "$model" in
## DEVICE_CUSTOM_OPTIONS ##
	*)
		;;
	esac

	type ucidef_target_defaults &> /dev/null && \
		ucidef_target_defaults "$model" "$hw_ver" "$branch"
}


platform="$(cat /proc/device-tree/platform)" 2>/dev/null

board_config_update
setup_json
ucidef_set_board_platform "$platform"
ucidef_check_esim
ucidef_check_tpm
board_config_flush

exit 0
