#!/bin/sh

#check for root
if [ `id -u` -ne 0 ];then
	echo "You should run the installer as root"
	exit 1;
fi
#display information
echo "Thank you for chose UniOTP One-Time-Password Authentication system"
echo " "
echo "Copyright (C) 2011 SecuTech Solution Inc."
echo " "
echo "Welcome to UniOTP Management System installer"
echo " "
DOCUMENTROOT=""
echo "Please input the DocumentsRoot of this Web Service:"
read DOCUMENTROOT
if [ ! -e $DOCUMENTROOT ];then
	echo "Installer cannot go on unless you set the correct"
	echo "DocumentsRoot directory."
	exit 1;
fi

#copy 
iscov=1
if [ -e "${DOCUMENTROOT}/libs" ];then
	echo "Folder libs exist.Cover it?[y/n]"
	read cover
	if [ "$cover" = "n" ];then
		iscov=0
	fi
fi
if [ ${iscov} -eq 1 ];then
	cp -rf ./libs $DOCUMENTROOT
fi
echo "libs install ok."
sleep 1
iscov=1
if [ -e "${DOCUMENTROOT}/UniOTPMGS_V_1_3" ];then
	echo "UniOTPMGS exists.Cover it?[y/n]"
	read cover
	if [ "$cover" = "n" ];then
		iscov=0
	fi
fi

if [ ${iscov} -eq 1 ];then
	cp -rf ./UniOTPMGS_V_1_3 $DOCUMENTROOT
fi
echo "UniOTPMGS install ok"
sleep 1
#change mode
chmod 0755 -R ${DOCUMENTROOT}/UniOTPMGS_V_1_3
chmod 0777 -R ${DOCUMENTROOT}/UniOTPMGS_V_1_3/download
chmod 0777 -R ${DOCUMENTROOT}/UniOTPMGS_V_1_3/upload
chmod 0777 -R ${DOCUMENTROOT}/UniOTPMGS_V_1_3/smarty_cache
chmod 0777 -R ${DOCUMENTROOT}/UniOTPMGS_V_1_3/smarty_compile

echo "UniOTP Management System has installed on this server."
echo "In order to make it work, you should change the configuration"
echo "parameters in configuration file"
echo " ${DOCUMENTROOT}/UniOTPMGS_V_1_3/otp_config.php"
