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

#info
function amh_module_info()
{
		echo 'AMH-ModuleName: GaModule-1.0';
		echo 'AMH-ModuleDescription: GaModule AMH二次验证模块。';
		echo 'AMH-ModuleButton: 安装/卸载';
		echo 'AMH-ModuleDate: 2013-03-16';
		echo 'AMH-ModuleAdmin: ./index.php?c=GaAuth';
		echo 'AMH-ModuleWebSite: jump';
		echo 'AMH-MoudleScriptBy: jump.';
}

#install
function amh_module_install()
{
		if amh_module_status ; then
				exit;
		else
				cd /root/amh/modules/GaModule-1.0;
				\cp ./Controller/GaAuth.php  /home/wwwroot/index/web/Controller/;
				\cp ./View/GaAuth_html.php  /home/wwwroot/index/web/View/;
				\cp ./Class/Google2FA.php  /home/wwwroot/index/web/Class/;
				\cp ./file/Amysql/GaConfig.php /home/wwwroot/index/web/Amysql/;
				\cp /home/wwwroot/index/web/Controller/index.php ./Backup/Controller/;
				\cp /home/wwwroot/index/web/View/login.php ./Backup/View/;
				\cp /home/wwwroot/index/web/index.php ./Backup/;
				\cp ./file/Controller/index.php /home/wwwroot/index/web/Controller/index.php;
				\cp ./file/View/login.php /home/wwwroot/index/web/View/login.php;
				\cp ./file/index.php /home/wwwroot/index/web/index.php;
				chown www:www /home/wwwroot/index/web/Amysql/GaConfig.php;
				chmod 600 /home/wwwroot/index/web/Amysql/GaConfig.php;
				amh_module_status;
		fi;
}

#admin
function amh_module_admin()
{
		if amh_module_status ; then
				echo '[OK] Module No management options.';
		else
				exit;
		fi;
}

#uninstall
function amh_module_uninstall()
{
		if amh_module_status ; then
				rm -f /home/wwwroot/index/web/Controller/GaAuth.php /home/wwwroot/index/web/View/GaAuth_html.php;
				rm -f /home/wwwroot/index/web/Class/Google2FA.php /home/wwwroot/index/web/Amysql/GaConfig.php;
				cd /root/amh/modules/GaModule-1.0;
				\cp ./Backup/Controller/index.php /home/wwwroot/index/web/Controller/;
				\cp ./Backup/View/login.php /home/wwwroot/index/web/View/ ;
				\cp ./Backup/index.php /home/wwwroot/index/web/ ;
				echo '[OK] MyModule Uninstall successful.';
		else
				exit;
		fi;
}

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