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

link="Advanced_Extensions_app03.asp"
echo $1
if [ "$1"x = "stop"x ] ; then
    nvram set app_8=0 #upd2pro_enable
    nvram set app_9=0 #upd2pro2_enable
    nvram set app_18=0 #upd2pro3_enable
    exit
fi

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

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

get_www ()
{

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

}

get_app ()
{

# 更新程序启动脚本
[ "$1" = "del" ] && rm -rf /etc/storage/script/Sh26_upd2pro.sh
if [ ! -f "/etc/storage/script/Sh26_upd2pro.sh" ] || [ ! -s "/etc/storage/script/Sh26_upd2pro.sh" ] ; then
	wgetcurl.sh /etc/storage/script/Sh26_upd2pro.sh "$hiboyscript/script/Sh26_upd2pro.sh" "$hiboyscript/script/Sh26_upd2pro.sh"
fi
chmod 777 /etc/storage/script -R
# 初始配置脚本
if [ ! -f "/etc/storage/app_3.sh" ] || [ ! -s "/etc/storage/app_3.sh" ] || [ ! -f "/etc/storage/app_4.sh" ] || [ ! -s "/etc/storage/app_4.sh" ] || [ ! -f "/etc/storage/app_6.sh" ] || [ ! -s "/etc/storage/app_6.sh" ] ; then
	/etc/storage/script/Sh26_upd2pro.sh update_app
fi
[ "$1" = "del" ] && exit

}

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

