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

link="Advanced_Extensions_app05.asp"
echo $1
if [ "$1"x = "stop"x ] ; then
    nvram set app_15=0 #filemanager_enable
    exit
fi

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

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

get_www ()
{

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

}

get_app ()
{

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

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

}

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

