#!/bin/bash


# Récupération des variables
if [ -f /usr/bin/ParseDico ];then
   # Module < 2.4, le SSO distant n'est pas géré
   exit 0
else
   RunCmd=CreoleRun
   container_path_web=$(CreoleGet container_path_web)
   activer_sso=$(CreoleGet activer_sso)
   eolesso_adresse=$(CreoleGet eolesso_adresse)
   eolesso_port=$(CreoleGet eolesso_port)
   dispatcher_arena_cache=$(CreoleGet dispatcher_arena_cache)

   proxy_client_adresse=$(CreoleGet proxy_client_adresse "")
   proxy_client_port=$(CreoleGet proxy_client_port "")

   dispatcher=$(CreoleGet dispatcher non)

fi

if [ "$dispatcher" == "oui" ]
then
    # Gestion du cache pour twig
    CACHE=$container_path_web"/var/www/html/edispatcher/ng/cache"
    [ ! -d $CACHE ] && mkdir $CACHE
    rm -rf $container_path_web/var/www/html/edispatcher/ng/cache/*
    chown -R  www-data.www-data $CACHE

    chown -R www-data.www-data $container_path_web"/var/www/html/edispatcher/ng/public"
    chown -R www-data.www-data $container_path_web"/var/www/html/edispatcher/ng/index.php"

    # Crontab pour update cache Arena
    cronFile="/etc/cron.d/edispatcher_arena_cache"
    if [ "$dispatcher_arena_cache" = "oui" ]; then

      echo "# Maj Cache ARENA
    */5 * * * * root cd ${container_path_web}/var/www/html/edispatcher &&  php utils/updateCacheArena.php  >> /tmp/edispatcher_arena_cache.log" > $cronFile

    else
      [ -e $cronFile ] && rm -rf $cronFile

    fi
fi
