#! /bin/bash

container_path_web=$(CreoleGet container_path_web non)
container_ip_mysql=$(CreoleGet adresse_ip_mysql non)
activer_themes=$(CreoleGet activer_themes non)
activer_moodle=$(CreoleGet activer_moodle non)
activer_dokuwiki=$(CreoleGet activer_dokuwiki non)
activer_wordpress=$(CreoleGet activer_wordpress non)
activer_envole=$(CreoleGet activer_envole non)
activer_fluxbb=$(CreoleGet activer_fluxbb non)
activer_opensondage=$(CreoleGet activer_opensondage non)
activer_eportail=$(CreoleGet activer_eportail non)
activer_envolemobile=$(CreoleGet activer_envolemobile non)
activer_iconito=$(CreoleGet activer_iconito non)
activer_owncloud=$(CreoleGet activer_owncloud non)
activer_piwigo=$(CreoleGet activer_piwigo non)
activer_etherhome=$(CreoleGet activer_etherhome non)
dispatcher=$(CreoleGet dispatcher non)
nom_theme=$(CreoleGet nom_theme cloud)

themes_dir="/usr/share/envole/envole-themes"

www_dir="$container_path_web/var/www/html"
dokuwiki_dir="$www_dir/dokuwiki"
moodle_dir="$www_dir/moodle"
moodle_data="$container_path_web/home/www-data/var/www/html/moodle"
wordpress_dir="$www_dir/wordpress"
posh_dir="$www_dir/posh"
edispatcher_dir="$www_dir/edispatcher"
ead_dir="/usr/share/ead2"
sso_dir="/usr/share/sso"
fluxbb_dir="$www_dir/fluxbb"
opensondage_dir="$www_dir/opensondage"
eportail_dir="$www_dir/eportail"
envolemobile_dir="$www_dir/envolemobile"
iconito_dir="$www_dir/iconito"
owncloud_dir="$www_dir/owncloud"
piwigo_dir="$www_dir/piwigo"
poshprofil_dir="$www_dir/posh-profil"
etherhome_dir="$www_dir/etherhome"


RunCmd=CreoleRun


if [ "$activer_themes" = 'non' ]
then
    exit 0
fi

function update_moodle
{
   CMD="cd ${moodle_dir} ; php admin/cli/upgrade.php --non-interactive > /dev/null 2>&1"

   $RunCmd "/bin/bash -c \"${CMD}\"" web
   RET=${?}

   $RunCmd "touch ${moodle_dir}/.config.lock" web
   $RunCmd "chmod 600 ${moodle_dir}/.config.lock" web

   return ${RET}
}

function droits_moodle
{
    # attribution des droits minimaux
    $RunCmd "chown -R root:www-data ${moodle_dir}" web
    $RunCmd "chmod -R 640 ${moodle_dir}" web
    $RunCmd "chmod -R ug+X ${moodle_dir}" web
    $RunCmd "chmod +x ${moodle_dir}/filter/tex/mimetex.linux" web

    if [[ -d "${moodle_dir}/moosh" ]]
    then
        $RunCmd "chown -R root:root ${moodle_dir}/moosh" web
    fi    

    $RunCmd "chown -R root:www-data ${moodle_data}" web
    $RunCmd "chmod -R 770 ${moodle_data}" web

    file_path="var/www/html/moodle/writeable_folders"
    con_path=${container_path_web}/${file_path}
    for i in `cat ${con_path}`;
    do
        if [[ -d "${i}" ]]
        then
            $RunCmd "chmod -R g+w ${i}" web
        fi
    done      
}

# MOODLE
if [ "$activer_moodle" = 'oui' ]
then
   . /usr/share/envole/eoledb/moodle
   export MYSQL_PWD=$dbpassMOODLE

	# Flag de mise en oeuvre
	fgmoodle=0

    #Récupération du password wordpress
    moodledbpass=`grep "CFG->dbpass" "$moodle_dir/config.php" | awk -F "'" '{print $2}'`

	#Récupération de la version de Moodle
	versionmoodle=$(mysql -umoodle -h$dbhostMOODLE -P$dbportMOODLE  --batch --skip-column-names -Dmoodle -e "select value from mdl_config where name='version'")

	if [ "$versionmoodle" \< "2013051402.11" ]
	then
		moodle_theme_dir="moodle"
		if [ -d "$themes_dir/$nom_theme/moodle" ]
		then
			fgmoodle=1
		fi
    elif [ "$versionmoodle" \< "2015051102.09" ]
    then
		moodle_theme_dir="moodle25"
		if [ -d "$themes_dir/$nom_theme/moodle25" ]
		then
			fgmoodle=1
		fi
    elif [ "$versionmoodle" \< "2017111302.04" ]
    then
		moodle_theme_dir="moodle29"
		if [ -d "$themes_dir/$nom_theme/moodle29" ]
		then
			fgmoodle=1
		fi        
    else
        moodle_theme_dir="moodle46"
        if [ -d "$themes_dir/$nom_theme/moodle46" ]
        then
            fgmoodle=1
        fi
	fi

	if [ "$fgmoodle" == 1 ]
	then
        echo "  >> Moodle"

		#Suppression de l'ancien theme
		rm -rf "$moodle_dir/theme/$nom_theme"

		#Copie des sources
		cp -rf "$themes_dir/$nom_theme/$moodle_theme_dir/theme" "$www_dir/moodle"

		#Permission
		chown -R www-data:root "$moodle_dir/theme/$nom_theme"
		chmod -R 700 "$moodle_dir/theme/$nom_theme"

		#Mise à jour de la base
		echo "UPDATE mdl_config SET value='$nom_theme' WHERE name='theme';" | mysql -umoodle -h$dbhostMOODLE -P$dbportMOODLE moodle
		versiontheme=$(mysql -umoodle -h$dbhostMOODLE -P$dbportMOODLE  --batch --skip-column-names -Dmoodle -e "select id from mdl_config_plugins where plugin='theme_$nom_theme' and name='version'")
		if [ "$versiontheme" == "" ]
		then
			if [ "$versionmoodle" \< "2013051402.11" ]
			then
				echo "INSERT INTO mdl_config_plugins (plugin,name,value) VALUES('theme_$nom_theme','version','2013030100');" | mysql -umoodle -h$dbhostMOODLE -P$dbportMOODLE moodle
			elif [ "$versionmoodle" \< "2015051102.09" ]
            then
				echo "INSERT INTO mdl_config_plugins (plugin,name,value) VALUES('theme_$nom_theme','version','2013050100');" | mysql -umoodle -h$dbhostMOODLE -P$dbportMOODLE moodle
			else
				echo "INSERT INTO mdl_config_plugins (plugin,name,value) VALUES('theme_$nom_theme','version','2015051100');" | mysql -umoodle -h$dbhostMOODLE -P$dbportMOODLE moodle
			fi
		else
			if [ "$versionmoodle" \< "2013051402.11" ]
			then
				echo "UPDATE mdl_config_plugins SET value='2013030100' WHERE plugin='theme_$nom_theme' AND name='version';" | mysql -umoodle -h$dbhostMOODLE -P$dbportMOODLE moodle
			elif [ "$versionmoodle" \< "2015051102.09" ]
            then
				echo "UPDATE mdl_config_plugins SET value='2013050100' WHERE plugin='theme_$nom_theme' AND name='version';" | mysql -umoodle -h$dbhostMOODLE -P$dbportMOODLE moodle
			else
				echo "UPDATE mdl_config_plugins SET value='2015051100' WHERE plugin='theme_$nom_theme' AND name='version';" | mysql -umoodle -h$dbhostMOODLE -P$dbportMOODLE moodle
			fi
		fi

        update_moodle
        droits_moodle
	fi
fi

# DOKUWIKI
if [[ "$activer_dokuwiki" = 'oui' && -d "$themes_dir/$nom_theme/dokuwiki" ]]
then
    echo "  >> Dokuwiki"

    #Suppression de l'ancien theme
    rm -rf "$dokuwiki_dir/lib/tpl/$nom_theme"

    #Creation de l'arborescence
    mkdir -p "$dokuwiki_dir/lib/tpl/$nom_theme/images"

    #Copie des sources
    cp -r "$themes_dir/$nom_theme/dokuwiki" "$www_dir"

    #Permission
    chown -R root:www-data "$dokuwiki_dir/lib/tpl/$nom_theme"
    chmod -R 755 "$dokuwiki_dir/lib/tpl/$nom_theme"

    #Changer la conf
    nblig=`grep -n "'template" "$dokuwiki_dir/conf/dokuwiki.php" | cut -d: -f1`
    lbrep="\$conf['template']    = '$nom_theme';"
    sed ${nblig}s/.*/"$lbrep"/ $dokuwiki_dir/conf/dokuwiki.php > $dokuwiki_dir/conf/dokuwiki.php.tmp
    rm -rf $dokuwiki_dir/conf/dokuwiki.php
    mv $dokuwiki_dir/conf/dokuwiki.php.tmp $dokuwiki_dir/conf/dokuwiki.php
fi

# WORDPRESS
if [[ "$activer_wordpress" = 'oui' && -d "$themes_dir/$nom_theme/wordpress" ]]
then
    echo "  >> Wordpress"
    . /usr/share/envole/eoledb/wordpress
    export MYSQL_PWD=$dbpassWORDPRESS

    #Suppression de l'ancien theme
    rm -rf "$wordpress_dir/wp-content/themes/$nom_theme"

    #Creation de l'arborescence
    mkdir -p "$wordpress_dir/wp-content/themes/$nom_theme/images"

    #Copie des sources
    cp -r "$themes_dir/$nom_theme/wordpress" "$www_dir"

    #Mise à jour de la base
    echo "UPDATE wp_options SET option_value='$nom_theme' WHERE option_name='template' OR option_name='stylesheet';" | mysql -uwordpress -h$dbhostWORDPRESS -P$dbportWORDPRESS wordpress
fi

# EOLE-POSH
if [[ "$activer_envole" = 'oui' && -d "$themes_dir/$nom_theme/posh" ]]
then
    echo "  >> Posh"
    . /usr/share/envole/eoledb/posh
    export MYSQL_PWD=$dbpassPOSH

    #Récupération du password wordpress
    poshdbpass=`grep "define(\"__PASS\"" "$posh_dir/includes/config.inc.php" | awk -F "\"" '{print $4}'`

    #Suppression de l'ancien theme
    rm -rf "$posh_dir/template/$nom_theme"
    rm -rf "$posh_dir/style/themes/$nom_theme.thm"
    rm -rf "$posh_dir/style/themes/$nom_theme"

    if [[ -d "$themes_dir/$nom_theme/posh" ]]
    then
		rm -rf "$posh_dir/includes/plugins/plugin_desktop/style/default.css"
		rm -rf "$posh_dir/includes/plugins/plugin_xdesktop/themes/$nom_theme"
	fi

    #Copie des sources
    cp -r "$themes_dir/$nom_theme/posh" "$www_dir"
    cp -r "$themes_dir/$nom_theme/posh/styles/themes/$nom_theme.thm" "$posh_dir/styles/main1.css"

    #Changer la conf
    nblig=`grep -n "__template" "$posh_dir/includes/config.inc.php" | cut -d: -f1`
    lbrep="define(\"__template\",\"$nom_theme\");"
    sed ${nblig}s/.*/$lbrep/ $posh_dir/includes/config.inc.php > $posh_dir/includes/config.inc.tmp
    rm -rf $posh_dir/includes/config.inc.php
    mv $posh_dir/includes/config.inc.tmp $posh_dir/includes/config.inc.php

    #Mise à jour de la base
    echo "UPDATE adm_config SET value='$nom_theme' WHERE parameter='theme';" | mysql -uposh -h$dbhostPOSH -P$dbportPOSH posh
    echo "UPDATE adm_config SET value=1 WHERE parameter='themeNb';" | mysql -uposh -h$dbhostPOSH -P$dbportPOSH posh
    echo "UPDATE adm_config SET value='$nom_theme' WHERE parameter='template';" | mysql -uposh -h$dbhostPOSH -P$dbportPOSH posh
    echo "UPDATE adm_config SET value='\'$nom_theme\'' WHERE parameter='themeList';" | mysql -uposh -h$dbhostPOSH -P$dbportPOSH posh
    echo "TRUNCATE TABLE adm_themes;" | mysql -uposh -h$dbhostPOSH posh
    echo "INSERT INTO adm_themes (name, seq) VALUES('$nom_theme',1);" | mysql -uposh -h$dbhostPOSH -P$dbportPOSH posh

    #Permission
    chown -R root:www-data "$posh_dir/includes/config.inc.php"
    chmod -R 664 "$posh_dir/includes/config.inc.php"
    if [[ -d "$posh_dir/includes/plugins/plugin_xdesktop/themes/$nom_theme" ]]
    then
		chown -R root:www-data "$posh_dir/includes/plugins/plugin_xdesktop/themes/$nom_theme"
	fi

fi

# FLUXBB
if [[ "$activer_fluxbb" = 'oui' && -d "$themes_dir/$nom_theme/fluxbb" ]]
then
    echo "  >> Fluxbb"

    #Récupération du password wordpress
    fluxbbdbpass=`grep "mdp=" "$fluxbb_dir/config.php" | awk -F "\"" '{print $2}'`
    export MYSQL_PWD=$fluxbbdbpass

    #Suppression de l'ancien theme
    rm -rf "$fluxbb_dir/style/$nom_theme.css"
    rm -rf "$fluxbb_dir/style/$nom_theme"

    #Copie des sources
    cp -r "$themes_dir/$nom_theme/fluxbb" "$www_dir"

    #Mise à jour de la base
    echo "UPDATE flux_config SET conf_value='$nom_theme' WHERE conf_name='o_default_style';" | mysql -ufluxbb -h$container_ip_mysql fluxbb
    echo "UPDATE flux_users  SET style='$nom_theme';" | mysql -ufluxbb -h$container_ip_mysql fluxbb

    #Permission
    chown -R root:www-data "$fluxbb_dir/style/$nom_theme.css"
    chown -R root:www-data "$fluxbb_dir/style/$nom_theme"

    #Suppression du cache config
    if [[ -f "$fluxbb_dir/cache/cache_config.php" ]]
    then
		 rm -rf "$fluxbb_dir/cache/cache_config.php"
    fi
fi

# OPENSONDAGE
if [[ "$activer_opensondage" = 'oui' && -d "$themes_dir/$nom_theme/opensondage" ]]
then
    echo "  >> Opensondage"

    #Suppression de l'ancien theme
    rm -rf "$opensondage_dir/webroot/css/$nom_theme.theme.css"

    #Copie des sources
    cp -r "$themes_dir/$nom_theme/opensondage" "$www_dir"

    #Permission
    chown -R root:www-data "$opensondage_dir/webroot/css/$nom_theme.theme.css"

    #Changement de la configuration
    nblig=`grep -n "CSStheme" "$opensondage_dir/config/conf.php" | cut -d: -f1`
    lbrep="    static \$CSStheme = '${nom_theme}';"
    sed ${nblig}s/.*/"$lbrep"/ $opensondage_dir/config/conf.php > $opensondage_dir/config/conf.php.tmp

    rm -rf $opensondage_dir/config/conf.php
    mv $opensondage_dir/config/conf.php.tmp $opensondage_dir/config/conf.php
fi


# EPORTAIL
if [[ "$activer_eportail" = 'oui' && -d "$themes_dir/$nom_theme/eportail" ]]
then
    echo "  >> ePortail"

    #Suppression de l'ancien theme
    rm -rf "$eportail_dir/style/themes/$nom_theme"

    #Copie des sources
    cp -r "$themes_dir/$nom_theme/eportail/$nom_theme" "$eportail_dir/style/themes"

    #Permission
    chown -R root:www-data "$eportail_dir/style/themes/$nom_theme"

    #Changer la conf
    if [[ ! -f "$eportail_dir/local/config/config.php" ]]
    then
		lbrep="<? \n \$config['theme']                       = '$nom_theme'; \n?>"
		echo -e "$lbrep" > "$eportail_dir/local/config/config.php"
    fi

    if [[ -f "$eportail_dir/local/config/config.php" ]]
    then
		nblig=`grep -n "'theme'" "$eportail_dir/local/config/config.php" | cut -d: -f1`
		lbrep="\$config\['theme'\]                       = '$nom_theme';"
		sed ${nblig}s/.*/"$lbrep"/ $eportail_dir/local/config/config.php > $eportail_dir/local/config/config.php.tmp
		rm -rf $eportail_dir/local/config/config.php
		mv $eportail_dir/local/config/config.php.tmp $eportail_dir/local/config/config.php

		#Permission
		chown -R root:www-data $eportail_dir/local/config/config.php
		chmod -R 775 $eportail_dir/local/config/config.php
	fi
fi

# ENVOLEMOBILE
if [[ "$activer_envolemobile" = 'oui' && -d "$themes_dir/$nom_theme/envolemobile" ]]
then
    echo "  >> envoleMobile"

    #Suppression de l'ancien theme
    rm -rf "$envolemobile_dir/style/themes/$nom_theme"

    #Copie des sources
    cp -r "$themes_dir/$nom_theme/envolemobile/$nom_theme" "$envolemobile_dir/style/themes"

    #Permission
    chown -R root:www-data "$envolemobile_dir/style/themes/$nom_theme"

    #Changer la conf
    if [[ ! -f "$envolemobile_dir/local/config/config.php" ]]
    then
		lbrep="<? \n \$config['themedir']                       = '$nom_theme'; \n?>"
		echo -e "$lbrep" > "$envolemobile_dir/local/config/config.php"
    fi

    if [[ -f "$envolemobile_dir/local/config/config.php" ]]
    then
		nblig=`grep -n "'themedir'" "$envolemobile_dir/local/config/config.php" | cut -d: -f1`
		lbrep="\$config\['themedir'\]                       = '$nom_theme';"
		sed ${nblig}s/.*/"$lbrep"/ $envolemobile_dir/local/config/config.php > $envolemobile_dir/local/config/config.php.tmp
		rm -rf $envolemobile_dir/local/config/config.php
		mv $envolemobile_dir/local/config/config.php.tmp $envolemobile_dir/local/config/config.php

		#Permission
		chown -R root:www-data $envolemobile_dir/local/config/config.php
		chmod -R 775 $envolemobile_dir/local/config/config.php
	fi
fi

#ICONITO
if [[ "$activer_iconito" = 'oui' && -d "$themes_dir/$nom_theme/iconito" ]]
then
    echo "  >> Iconito"

    #Copie des sources
    cp -r "$themes_dir/$nom_theme/iconito/default" "$iconito_dir/www/themes"
    chown -R root:www-data $iconito_dir/www/themes
fi

# EOLE-DISPATCHER dispatcher
if [[ "$dispatcher" = 'oui' && -d "$themes_dir/$nom_theme/edispatcher" ]]
then
    echo "  >> eDispatcher"

	#Suppression de l'ancien theme
	rm -rf "$edispatcher_dir/images/*"
	rm -rf "$edispatcher_dir/css/*"

	#Copie des sources
	cp -r "$themes_dir/$nom_theme/edispatcher" "$www_dir"
fi

#OWNCLOUD
if [[ "$activer_owncloud" = 'oui' && -d "$themes_dir/$nom_theme/owncloud" ]]
then
    echo "  >> Owncloud"

    rm -rf "$owncloud_dir/themes/*"
    cp -r "$themes_dir/$nom_theme/owncloud/themes/$nom_theme" "$owncloud_dir/themes"
    themed=false
    theme_reg="^.*'theme'=>.*$"
    while read line
    do
        if [[ "$line" =~ $theme_reg ]]
        then
            themed=true
        fi
    done < ${owncloud_dir}/config/config.php

    if [[ "${themed}" == true ]]
    then
        sed -i "s/.*'theme'=.*/'theme'=>'${nom_theme}',/"  ${owncloud_dir}/config/config.php
    else
        mv ${owncloud_dir}/config/config.php ${owncloud_dir}/config/config.php.orig
        touch ${owncloud_dir}/config/config.php
        chown www-data:www-data ${owncloud_dir}/config/config.php
        chmod 660 ${owncloud_dir}/config/config.php
        while read line
        do
            if [[ ${line} =~ ");" ]]
            then
                echo "'theme'=>'${nom_theme}'," >> ${owncloud_dir}/config/config.php
            fi
            echo ${line} >> ${owncloud_dir}/config/config.php
        done < ${owncloud_dir}/config/config.php.orig
        rm -rf ${owncloud_dir}/config/config.php.orig
    fi
elif [[ "$activer_owncloud" = oui && ! -d "$theme_dir/$nom_theme/owncloud" ]]
then
    themed=false
    theme_reg="^.*'theme'=>.*$"
    while read line
    do
        if [[ ${line} =~ $theme_reg ]]
        then
            themed=true
        fi
    done < ${owncloud_dir}/config/config.php
    if [[ ${themed} ]]
    then
        sed -i "s/.*'theme'=.*//"  ${owncloud_dir}/config/config.php
    fi
    sed -i '/^$/d' ${owncloud_dir}/config/config.php
    
    chown www-data:www-data ${owncloud_dir}/config/config.php
    chmod 660 ${owncloud_dir}/config/config.php    
fi

#PIWIGO
if [[ "$activer_piwigo" = 'oui' && -d "$themes_dir/$nom_theme/piwigo" ]]
then
    echo "  >> Piwigo"
    . /usr/share/envole/eoledb/piwigo
    export MYSQL_PWD=$dbpassPIWIGO

     #Suppression de l'ancien theme
    rm -rf "$piwigo_dir/themes/$nom_theme"

    #Copie des sources
    cp -r "$themes_dir/$nom_theme/piwigo" "$www_dir"
    theme_version=$(grep Version $piwigo_dir/themes/${nom_theme}/themeconf.inc.php | awk -F ": " '{print $2}')
    ptheme_name=$(grep "Theme Name" $piwigo_dir/themes/${nom_theme}/themeconf.inc.php | awk -F ": " '{print $2}')

    #Mise à jour de la base
    echo "UPDATE piwigo_user_infos SET theme='$nom_theme' WHERE status IN ('webmaster','guest','normal');" | mysql -upiwigo -h$dbhostPIWIGO -P$dbportPIWIGO piwigo
    echo "UPDATE piwigo_config SET value='$nom_theme' WHERE param='mail_theme';" | mysql -upiwigo -h$dbhostPIWIGO -P$dbportPIWIGO piwigo
    echo "UPDATE piwigo_config SET value='$nom_theme' WHERE param='mobile_theme';" | mysql -upiwigo -h$dbhostPIWIGO -P$dbportPIWIGO piwigo
    echo "DELETE FROM piwigo_themes WHERE id='$nom_theme';" | mysql -upiwigo -h$dbhostPIWIGO -P$dbportPIWIGO piwigo
    echo "INSERT INTO piwigo_themes (id, version, name) VALUES ('$nom_theme','$theme_version','$ptheme_name');" | mysql -upiwigo -h$dbhostPIWIGO -P$dbportPIWIGO piwigo

    #Permission
    chown -R root:www-data "$piwigo_dir/themes/$nom_theme"
fi

#POSHPROFIL
if [[ -d "$themes_dir/$nom_theme/posh-profil" ]]
then
    echo "  >> PoshProfil"

    rm -rf "$poshprofil_dir/styles/$nom_theme"

    cp -r "$themes_dir/$nom_theme/posh-profil/$nom_theme" "$poshprofil_dir/styles"
    sed -i "s/styles\/.*\/css/styles\/${nom_theme}\/css/" "$poshprofil_dir/include/envole.php"
    sed -i "s/styles\/.*\/tpl/styles\/${nom_theme}\/tpl/" "$poshprofil_dir/include/envole.php"

    chgrp -R www-data "$poshprofil_dir/styles/$nom_theme"
fi

# ETHERHOME
if [[ "$activer_etherhome" = "oui" && -d "${themes_dir}/${nom_theme}/etherhome" ]]
then
    cp -r ${themes_dir}/${nom_theme}/etherhome/assets/css/style-${nom_theme}.css ${etherhome_dir}/assets/css
    cp -r ${themes_dir}/${nom_theme}/etherhome/assets/libs/bootstrap/css/bootstrap-${nom_theme}.min.css ${etherhome_dir}/assets/libs/bootstrap/css
    cp -r ${themes_dir}/${nom_theme}/etherhome/assets/img/* ${etherhome_dir}/assets/img
    # CSS
    sed -i "s/href='assets\/css\/style.*\.css'/href='assets\/css\/style-${nom_theme}.css'/" "$etherhome_dir/index.php"
    # CSS BOOTSTRAP
    sed -i "s/href='assets\/libs\/bootstrap\/css\/bootstrap.*\.min\.css'/href='assets\/libs\/bootstrap\/css\/bootstrap-${nom_theme}.min.css'/" "$etherhome_dir/index.php"
    #IMAGES
    sed -i "s/\+'_pads.*.png/+'_pads-${nom_theme}.png/" "$etherhome_dir/assets/js/presentation.js"
    sed -i "s/\+'_calcs.*.png/+'_calcs-${nom_theme}.png/" "$etherhome_dir/assets/js/presentation.js"
elif [[ -f http://test-eole.ac-dijon.fr/envole/ ]]
then
    # CSS
    sed -i "s/href='assets\/css\/style.*\.css'/href='assets\/css\/style-orig.css'/" "$etherhome_dir/index.php"
    # CSS BOOTSTRAP
    sed -i "s/href='assets\/libs\/bootstrap\/css\/bootstrap.*\.min\.css'/href='assets\/libs\/bootstrap\/css\/bootstrap-orig.min.css'/" "$etherhome_dir/index.php"
    #IMAGES
    sed -i "s/\+'_pads.*.png/+'_pads-orig.png/" "$etherhome_dir/assets/js/presentation.js"
    sed -i "s/\+'_calcs.*.png/+'_calcs-orig.png/" "$etherhome_dir/assets/js/presentation.js"
fi


# EOLE-EAD
if [[ -d "$themes_dir/$nom_theme/ead/frontend" ]]
then
    echo "  >> EAD"

	#Suppression de l'ancien theme
	rm -rf "$ead_dir/frontend/web/static/style/*.css"

	#Copie des sources
	cp -r "$themes_dir/$nom_theme/ead/frontend" "$ead_dir"
fi

# EOLE-SSO
if [[ -d "$themes_dir/$nom_theme/eole-sso/interface" ]]
then
    echo "  >> eoleSSO"

	#Suppression de l'ancien theme
	rm -rf "$sso_dir/interface/theme/style/*"
	rm -rf "$sso_dir/interface/theme/image/*"

	#Copie des sources
	cp -r "$themes_dir/$nom_theme/eole-sso/interface" "$sso_dir"
fi
