#!/bin/sh
#copyright by hiboy
source /etc/storage/script/init.sh

link="Advanced_Extensions_app18.asp"
echo $1
if [ "$1"x = "stop"x ] ; then
    nvram set app_88=0 #clash_enable
    exit
fi

if [ "$1" != "del" ] ; then
eval 'nvram set tablink'$1'='$link';'

nvram set clash_L2="$(($3 + 10))"
nvram set clash_L3="$2"
#     show_menu(8,<% nvram_get_x("", "clash_L2"); %>,<% nvram_get_x("", "clash_L3"); %>);
fi

get_www ()
{

# 加载程序配置页面
mkdir -p /opt/app/clash
if [ ! -f "/opt/app/clash/Advanced_Extensions_clash.asp" ] || [ ! -s "/opt/app/clash/Advanced_Extensions_clash.asp" ] ; then
	wgetcurl.sh /opt/app/clash/Advanced_Extensions_clash.asp "$hiboyfile/Advanced_Extensions_clashasp" "$hiboyfile2/Advanced_Extensions_clashasp"
fi
umount /www/Advanced_Extensions_app18.asp
if [ -f "/opt/app/clash/Advanced_Extensions_clash.asp" ] ; then
	mount --bind /opt/app/clash/Advanced_Extensions_clash.asp /www/Advanced_Extensions_app18.asp
	app18_ver=$(grep 'app18_ver=' /opt/app/clash/Advanced_Extensions_clash.asp | awk -F '=' '{print $2;}')
	nvram set app18_ver=${app18_ver}
fi

}

get_app ()
{

# 更新程序启动脚本
[ "$1" = "del" ] && rm -rf /etc/storage/script/Sh10_clash.sh
if [ ! -f "/etc/storage/script/Sh10_clash.sh" ] || [ ! -s "/etc/storage/script/Sh10_clash.sh" ] ; then
	wgetcurl.sh /etc/storage/script/Sh10_clash.sh "$hiboyscript/script/Sh10_clash.sh" "$hiboyscript/script/Sh10_clash.sh"
fi
chmod 777 /etc/storage/script -R
if [ ! -f "/etc/storage/app_20.sh" ] || [ ! -s "/etc/storage/app_20.sh" ] ; then
/etc/storage/script/Sh10_clash.sh update_app
fi

[ "$1" = "del" ] && exit

}

if [ -f /tmp/webui_yes ] ; then
get_www &
get_app $1 &
[ "$1" = "del" ] && exit
fi

