#!/bin/bash
if [ -f /usr/bin/ParseDico ];then
    #EOLE 2.3
    . ParseDico
    . /etc/eole/containers.conf
	. /usr/share/eole/FonctionsEoleNg
	RunCmd=RunCmd
else
    #EOLE 2.4
    activer_envole=$(CreoleGet activer_envole)
    container_path_web=$(CreoleGet container_path_web)
    RunCmd=CreoleRun
fi

if [ "$activer_envole" == "oui" ]
then
	# droits sur les fichiers de log
	LOG_PATH="/var/log/posh"
	mkdir -p "$container_path_web/$LOG_PATH"
	touch "$container_path_web/$LOG_PATH/interface.log"
	touch "$container_path_web/$LOG_PATH/profile.log"
	touch "$container_path_web/$LOG_PATH/api.log"
	touch "$container_path_web/$LOG_PATH/client.log"
	$RunCmd "chown www-data $LOG_PATH $LOG_PATH/interface.log $LOG_PATH/profile.log $LOG_PATH/api.log $LOG_PATH/client.log" web

	### création des répertoires ressources et du lien symbolique pour le plugin widget ressource
	ADMIN=/home/a/admin
	PERSO=$ADMIN/perso
	RESSOURCES=$PERSO/ressources
	WRESSOURCES=/var/www/html/ressources

	# Réglage des droits
	chmod o+x $ADMIN
	chmod o+x $PERSO

	# Création répertoire ressources, du script index.php et ses droits 
	mkdir -p $RESSOURCES
	if [ ! -f $RESSOURCES/index.php ]; then
		cp /usr/share/envole/posh/ressources.php $RESSOURCES/index.php
	fi
	chown root:www-data $RESSOURCES/index.php
	chmod 640 $RESSOURCES/index.php

	# Vérifications	
	if [ -x /usr/bin/setfacl ]; then
		setfacl -Rbk $RESSOURCES
		setfacl -d -Rm g:www-data:r-x $RESSOURCES
		chmod 750 $RESSOURCES
		chown admin:www-data $RESSOURCES
	else 
		chown -R root:www-data $RESSOURCES
	fi
	
	# Création lien symbolique
	$RunCmd "if [ -d $WRESSOURCES -a ! \( -h $WRESSOURCES \) ] ; then /bin/rmdir $WRESSOURCES ; fi" web
	$RunCmd "/bin/ln -nfs $RESSOURCES $WRESSOURCES" web
fi
exit 0

