#!/bin/sh
# Copyright (C) 2025 Ycarus (Yannick Chabanois) <ycarus@zugaina.org> for OpenMPTCProuter project

[ ! -f /etc/init.d/shadowsocks-rust ] && exit 0

if [ -z "$(uci -q get shadowsocks-rust.hi1.keep_alive)" ]; then
	uci -q batch <<-EOF > /dev/null
		set shadowsocks-rust.hi1.keep_alive=15
		set shadowsocks-rust.hi1.no_delay=1
		set shadowsocks-rust.hi1.fast_open=0
		set shadowsocks-rust.hi2.keep_alive=15
		set shadowsocks-rust.hi2.no_delay=1
		set shadowsocks-rust.hi2.fast_open=0
		commit shadowsocks-rust
	EOF
fi
if [ -z "$(uci -q get shadowsocks-rust.dns.forward_address)" ]; then
	uci -q batch <<-EOF > /dev/null
		set shadowsocks-rust.dns.forward_address="8.8.8.8"
		set shadowsocks-rust.dns.forward_port=53
		del shadowsocks-rust.dns.tunnel_address
		commit shadowsocks-rust
	EOF
fi

if [ "$(uci -q get shadowsocks-rust.hi1.fast_open)" = "1" ]; then
	uci -q batch <<-EOF > /dev/null
		set shadowsocks-rust.hi1.fast_open=0
		set shadowsocks-rust.hi2.fast_open=0
		commit shadowsocks-rust
	EOF
fi


rm -f /tmp/luci-indexcache
exit 0
