#!/bin/sh /etc/rc.common
# (C) 2024 nosignal

START=99

BIN="/etc/neko/core/neko"
SINGBOX="/etc/neko/core/singbox"

start() {
	core_mode=$(uci -q get neko.cfg.core_mode)
	sleep 1
	
	if [ "$core_mode" = "singbox" ]; then
		$SINGBOX -s
	else
		$BIN -s
	fi

	if [ "$(uci -q get neko.cfg.php_server)" = "1" ]; then
		$BIN -p
	fi
}

restart() {
	core_mode=$(uci -q get neko.cfg.core_mode)
	
	if [ "$core_mode" = "singbox" ]; then
		$SINGBOX -r
	else
		$BIN -r
	fi
}

stop() {
	core_mode=$(uci -q get neko.cfg.core_mode)
	
	if [ "$(uci -q get neko.cfg.php_server)" = "1" ]; then
		$BIN -c
	else
		if [ "$core_mode" = "singbox" ]; then
			$SINGBOX -k
		else
			$BIN -k
		fi
	fi
}

stop_service() {
	stop
}

reload_service() {
	restart
}
