#!/bin/sh

export KSROOT=/koolshare
source $KSROOT/scripts/base.sh
eval $(dbus export merlinclash_)
alias echo_date='echo 【$(date +%Y年%m月%d日\ %X)】:'
#
#host
rm -rf  /tmp/upload/clash_hosts.txt
ln -sf /koolshare/merlinclash/yaml_basic/hosts.yaml /tmp/upload/clash_hosts.txt
#head
rm -rf  /tmp/upload/clash_head.txt
ln -sf /koolshare/merlinclash/yaml_basic/head.yaml /tmp/upload/clash_head.txt
#dns
[ ! -L "/tmp/upload/clash_redirhost.txt" ] && ln -s /koolshare/merlinclash/yaml_dns/redirhost.yaml /tmp/upload/clash_redirhost.txt
[ ! -L "/tmp/upload/clash_fakeip.txt" ] && ln -s /koolshare/merlinclash/yaml_dns/fakeip.yaml /tmp/upload/clash_fakeip.txt
#sniffer
rm -rf /tmp/upload/clash_sniffercontent.txt
ln -sf /koolshare/merlinclash/yaml_basic/sniffer.yaml /tmp/upload/clash_sniffercontent.txt
#iptlist
rm -rf /tmp/upload/clash_ipsetproxyarround.txt
rm -rf /tmp/upload/clash_ipsetproxy.txt
if [ -f "/koolshare/merlinclash/yaml_basic/ipsetproxyarround.yaml" ]; then
	ln -sf /koolshare/merlinclash/yaml_basic/ipsetproxyarround.yaml /tmp/upload/clash_ipsetproxyarround.txt
fi
if [ -f "/koolshare/merlinclash/yaml_basic/ipsetproxy.yaml" ]; then
	ln -sf /koolshare/merlinclash/yaml_basic/ipsetproxy.yaml /tmp/upload/clash_ipsetproxy.txt
fi

#自定义规则
yamlname=${merlinclash_set_yamlsel_start}
rm -rf /tmp/upload/${yamlname}_rules.txt

if [ -f "/koolshare/merlinclash/rule_use/${yamlname}_rules.yaml" ]; then
	ln -sf /koolshare/merlinclash/rule_use/${yamlname}_rules.yaml /tmp/upload/${yamlname}_rules.txt
else
	ln -sf /koolshare/merlinclash/rule_bak/${yamlname}_rules.yaml /tmp/upload/${yamlname}_rules.txt
fi

http_response $1