#!/bin/bash


chip=$(cat /var/iot/chip)

init_board(){
	model=$(cat /var/iot/model.txt)
	mode=$(uci get gateway.general.server_type)

	if [[ "$chip" = "sx1302" ]] && [[ "$model" = "HP0C" ]] || [[ "$model" = "LPS8-V2" ]] && [[ "$mode" = "lorawan" ]]; then
		ln -sf /usr/bin/fwd_sx1302 /usr/bin/fwd
	    /usr/local/dragino/generate-config.sh start
		systemctl start draginofwd && systemctl enable draginofwd;
		systemctl disable draginostation
	elif [[ "$chip" = "sx1302" ]] && [[ "$model" = "HP0C" ]] || [[ "$model" = "LPS8-V2" ]] && [[ "$mode" = "station" ]]; then
		ln -sf /usr/bin/station_sx1302 /usr/bin/station
		/usr/local/dragino/basic_station.sh start
		systemctl start draginostation && systemctl enable draginostation;
		systemctl disable draginofwd
	fi
}

case "$1" in
	start)
		init_board
		;;
	*)
esac

exit
