#!/bin/bash

### Définition des variables
if [ -f /usr/bin/ParseDico ]
then
    #EOLE 2.3
    RunCmd=RunCmd
    . ParseDico
    . /etc/eole/containers.conf
    . /usr/share/eole/FonctionsEoleNg
else
    activer_sacoche=$(CreoleGet activer_sacoche non)
    web_url=$(CreoleGet web_url)
    adresse_ip_web=$(CreoleGet adresse_ip_web)
    RunCmd=CreoleRun
fi

### Uniquement si sacoche est activé
if [[ "${activer_sacoche}" = "oui" ]]
then
	#
	# Lance la mise à jour de la base sacoche via un CURL
	#
	if [[ -n ${web_url} ]]
	then
	URL="https://${web_url}/sacoche"
	else
	URL="https://${adresse_ip_web}/sacoche"
	fi

	CMD="curl -k ${URL}/updateEnvole.php"

	$RunCmd "/bin/bash -c \"${CMD} > /dev/null 2>&1\""  web
fi

### Correction du pb de droits sur le fichier constantes.php par remise à plat des droits
# (copie de debian/sacoche-apps.postinst de la branche dist/envole/4/master)
ROOT_DIR=/var/www/html/sacoche

$RunCmd "/bin/chown -R root:www-data ${ROOT_DIR}" web
$RunCmd "/bin/chmod -R 640 ${ROOT_DIR}" web
$RunCmd "/bin/chmod -R ug+X ${ROOT_DIR}" web
$RunCmd "/bin/chmod -R 775 ${ROOT_DIR}/__private" web
$RunCmd "/bin/chmod -R 775 ${ROOT_DIR}/__tmp" web
