#! /bin/bash
#
USER=$(whoami)
if [ $USER = "root" ] ;then
    [ "$#" = 0 ] && echo -e "Especifique um usuario." && exit 1
    [ "$1" ] && _USER="$1"
else
    _USER="$USER"
    :
fi

#	DEFININDO CAMINHO DE ARQUIVOS
_HOME="/home/$_USER"
_PATH_EDIR="/home/$_USER/edirectory"
CONFIG_INC="$_PATH_EDIR/web/conf/config.inc.php"
CONSTANTS_INC="$_PATH_EDIR/web/conf/constants.inc.php"
DOMAIN_INC="$_PATH_EDIR/web/custom/domain/domain.inc.php"
BD_INFO="$_HOME/.info_projeto.txt"

KERNEL_V="$_PATH_EDIR/src/ArcaSolutions/CoreBundle/Kernel/Kernel.php"
EDIR_VERSION="$(grep "const VERSION = " $KERNEL_V | awk -F\' '{print $2}')"

#	Se ja existe, limpe o arquivo
[ -f $BD_INFO ] && cat /dev/null > $BD_INFO
#	Se nao existe crie-o
[ ! -f $BD_INFO ] && touch $BD_INFO

#	Pegar DB_USER
DB_USER=$(grep "USER" $CONFIG_INC | awk -F'"' '{print $4}')

#	Pegar DB_PASS
DB_PASS=$(grep "PASS" $CONFIG_INC | awk -F'"' '{print $4}')

#	Pegar DB_MAIN
DB_MAIN=$(grep "NAME\"" $CONFIG_INC | awk -F'"' '{print $4}')

#	Pegar DB_PREFIX
DB_PREFIX=$(grep "NAME_" $CONFIG_INC | awk -F'"' '{print $4}')

#	Pegar dominios e ids
indice="$(cat $DOMAIN_INC | grep -v "^#" | grep "domainInfo" | wc -l)"
for i in $indice; do
	#	Pegar os ids e dominios
	echo -e "\
	$(grep "domainInfo" $DOMAIN_INC | grep -v "^#" | awk -F'=' '{ print $2 }' | \
	tr -d '\ \;')\
	:\
	$(grep "domainInfo" $DOMAIN_INC | grep -v "^#" | awk -F'"' '{ print $2 }')\
	" >> $BD_INFO
done

HOST=$(hostname)
if [[ -f "$_HOME/tmp_upgrade/fix_sitemgr.log" ]] ;then
	ARCALOGIN_PASS="$(cat $_HOME/tmp_upgrade/fix_sitemgr.log | grep Senha | awk -F': ' '{print $2}')"	
else
	echo -e "
[!] v11tools-fix_sitemgr_acc nunca foi executado.
Por isso nao foi possivel encontrar senha do sitemgr.
"

fi

echo -e "

#### INFORMACOES GERAIS DO USUARIO $_USER ####

Versao:\t\t $EDIR_VERSION
Arcalogin:\t $ARCALOGIN_PASS \t  (!)
MySQL User:\t $DB_USER
MySQL PASS:\t $DB_PASS
DB_MAIN:\t $DB_MAIN
Host:\t\t $HOST

##### ID : Dominio #####

$(cat $BD_INFO | sed 's/\t/\ /g')

---------------------------------------


(!) Caso tenha problemas com a senha do 
sitemgr, utilize o v11tools-fix_sitemgr
com o usuario em questao.
"

