#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin;
module_dir="/root/amh/modules/AMProxy-2.0/";

#info
function amh_module_info()
{
    echo 'AMH-ModuleName: AMProxy-2.0';
    echo 'AMH-ModuleDescription: AMProxy-2.0 反向代理模块修改版(用于API兼容HYProxy)';
    echo 'AMH-ModuleButton: 安装/卸载';
    echo 'AMH-ModuleDate: 2020-01-17';
    echo 'AMH-ModuleAdmin: ./index.php?c=amproxy';
    echo 'AMH-ModuleWebSite: http://www.huayizhiyun.com';
    echo 'AMH-ModuleScriptBy: HITSword.';
}

#install
function amh_module_install()
{
    if amh_module_status ; then
        param_list=${1//,/ };
        set -- $param_list;
        action=$1;
        domain=$2;

        if [ "$action" == '' ]; then
            
        fi;
        
        case $1 in
            list)
                echo "list something"
            ;;
            start)
                echo "start something"
            ;;
            stop)
                echo "stop something"
            ;;
            add)
                echo "add something"
            ;;
            edit)
                echo "edit something"
            ;;
            del)
                echo "del something"
            ;;
            start-cache)
                echo "start cache"
            ;;
            stop-cache)
                echo "stop cache"
            ;;
            cache)
                echo "暂不支持缓存配置"
            ;;
            cache-index)
                echo "暂不支持缓存索引"
            ;;
            cache-delete)
                echo "暂不支持缓存删除"
            ;;
            *)
                echo "[Notice] AMProxy management, please select: (1~4)"
                    select action in 'list' 'add' 'start' 'stop' 'edit' 'del' 'start-cache' 'stop-cache' 'cache' 'cache-index' 'cache-delete'; do
                        break;
                    done;
            ;;
        esac
        exit;
    else
        amh_module_status;
    fi;
}

#uninstall
function amh_module_uninstall()
{
    if amh_module_status ; then
        echo '[OK] AMProxy-2.0 Uninstall successful.';
    else
        exit;
    fi;
}

#admin
function amh_module_admin()
{
    if amh_module_status ; then
    else
        exit;
    fi;
}


#status
function amh_module_status()
{
    if [ -f "/root/amh/modules/AMProxy-2.0/InstallComplete" ]; then
        echo '[OK] AMProxy-2.0 is already installed.';
        return 0;
    else
        echo '[Notice] AMProxy-2.0 is not installed.';
        return 1;
    fi;
}