#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin;

#info
function amh_module_info()
{
		echo 'AMH-ModuleName: AMFTP-2.0';
		echo 'AMH-ModuleDescription: 最新2.0版本AMFTP - 基于web在线FTP文件管理客户端，支持多文件、大文件极速上传、支持zip、tar、gzip(tar.gz) 在线解压与压缩，支持新建文件、文件编辑、移动、重命名、权限设置等，安装完成可在FTP版块点对应账号管理登录。';
		echo 'AMH-ModuleButton: 安装/卸载';
		echo 'AMH-ModuleDate: 2013-06-10';
		echo 'AMH-ModuleAdmin: ./AMFTP-2.0/index.php';
		echo 'AMH-ModuleWebSite: http://amysql.com';
		echo 'AMH-ModuleIco: http://amysql.com/View/images/amh_module/AMFTP.gif';
		echo 'AMH-ModuleScriptBy: Amysql';
}

#install
function amh_module_install()
{
		if amh_module_status ; then
				exit;
		else
			for module_name in `ls /root/amh/modules/ | grep 'AMFTP' | grep -v 'AMFTP-2.0'`; do
				amh module $module_name uninstall && amh module $module_name delete y;
			done;

			cd /usr/local/;
			wget http://code.amysql.com/files/AMFTP-2.0.zip;
			unzip AMFTP-2.0.zip;
			mv AMFTP /home/wwwroot/index/web/AMFTP-2.0;
			sed -i "/<?php } ?>/a\<a title=\"AMFTP-2.0\" href=\"./AMFTP-2.0/index.php?ftp_user=<?php echo \$val['ftp_name'];?>\" class=\"button\" title=\"AMFTP\" target=\"_blank\"><span class=\"cog icon\"></span> 管理</a>" /home/wwwroot/index/web/View/ftp.php
			amh_module_status;
		fi;
}

#admin
function amh_module_admin()
{
		if amh_module_status ; then
				echo '[OK] AMFTP-2.0 Management:  http://ip:8888/AMFTP-2.0/ ';
		else
				exit;
		fi;
}

#uninstall
function amh_module_uninstall()
{
		if amh_module_status ; then

				rm -rf /home/wwwroot/index/web/AMFTP-2.0;
				rm -f /usr/local/AMFTP-2.0.zip;
				sed -i "/AMFTP-2.0/d" /home/wwwroot/index/web/View/ftp.php
				echo '[OK] AMFTP-2.0 Uninstall successful.';
		else
				exit;
		fi;
}

#status
function amh_module_status()
{
		if [ -d "/home/wwwroot/index/web/AMFTP-2.0" ]; then
				echo '[OK] AMFTP-2.0 is already installed.';
				return 0;
		else
				echo '[Notice] AMFTP-2.0 is not installed.';
				return 1;
		fi;
}

