#!/bin/sh
# 网络配置
. /opt/lnxall_app/bin/utils.sh

system_cfg_file="/app/config/system_cfg.json"
bcast_port="lo"
frpc_cfg="/etc/frpc.ini"
bcast_ip="127.0.0.1"
lan_ip="172.18.39.254"
wan_cfg_1="dhcp"
wan_cfg_2="dhcp"
wan_ip=""

sd_pwd="/mnt/ssd"

if [ ! -f "/opt/lnxall_app/bin/emu_lc" ] ; then
	echo "Error, '/opt/lnxall_app/bin/emu_lc' not found, emud exit"
	exit 0
fi

if [ "$1" = "stop" ]; then
    stop_program emu_lc
    exit 0
fi

get_board_sn 
get_sd_pwd "$BOARD_NAME"
create_database_dir "$sd_pwd"

res=$(systemctl is-enabled emsd | grep -wc "enabled")
if [ $res -eq 0 ]; then
    start_httpd_and_ftp "$BOARD_NAME"
    load_json_cfg "$BOARD_NAME"
    set_network "$BOARD_NAME"
    reload_net_cfg "$BOARD_NAME"
    ln_multilingual_resource
fi

bing_opcua_if "$BOARD_NAME" #广播功能

echo "check_program_and_recover start"

while true; do
    check_program_and_recover emu_lc "-n $bcast_port -l 4 -L 4"
    sleep 10
done
