#!/bin/bash # Personnalisation de posh par créteil # Execution par zephir en .zephir # Passage du parametre --force en option VERT="\\033[1;32m" NORMAL="\\033[0;39m" ROUGE="\\033[1;31m" DIR_TMP=personnalisation-cel DIR_SCRIPTS=/root/ DIR_SSO=/usr/share/sso/ DIR_HTML=/var/www/html/ DIR_POSH=/var/www/html/posh/ DIR_RESSOURCES=/var/www/html/ressources/ URL_DIFFUSION=http://diff.ac-creteil.fr/di/ftp/scribe/EnvOLE-2.0 ARCHIVE_PERSONNALISATION=personnalisation.tar.gz SCRIPT_PERSONNALISATION=personnalisation.php FAIRE_PERSONNALISATION="non" FILE_CONFIGURATION=configuration.ini FILE_VERSION=version_personnalisation FILE_FLAG=/home/$FILE_VERSION if [ ! -f $FILE_FLAG ] ; then echo "0" > $FILE_FLAG else #mise à jour systématique de la date afin d'avoir une trace de la dernière exécution du script zéphir touch $FILE_FLAG fi #statut : 0=>personnalisation normale, 1=>personnalisation forcée, 2=>personnalisation de développement forcée STATUT=0 EXECUTER_SCRIPT="oui" #possibilité de ne pas exécuter le script en cas de personnalisation ONE_FILE="non" #possibilité de ne mettre en place qu'un fichier if [[ $# -eq 1 && $1 = "--dev" ]] ; then echo -e $ROUGE "--- Mise en place d'une version de développement ---" $NORMAL STATUT=2 ARCHIVE_PERSONNALISATION=personnalisation_dev.tar.gz #le FILE_FLAG reste par contre le même à savoir /home/version_personnalisation FILE_VERSION=version_personnalisation_dev elif [[ $# -eq 1 && $1 = "--force" ]] ; then STATUT=1 elif [[ $# -eq 1 && $1 = "--fichiers" ]] ; then #ne traiter que les fichiers #on force la procédure sans exécuter le script STATUT=1 EXECUTER_SCRIPT="non" elif [[ $# -eq 2 && $1 = "--fichier" ]] ; then #ne traiter qu'un fichier spécifique #on force la procédure sans exécuter le script STATUT=1 EXECUTER_SCRIPT="non" ONE_FILE="oui" fi . /usr/bin/ParseDico etab=$nom_machine # Nettoyage du rep temporaire cd /tmp rm -rf $DIR_TMP mkdir $DIR_TMP cd /tmp cd $DIR_TMP wget -q $URL_DIFFUSION/$FILE_VERSION if [ -f $FILE_VERSION ] ; then VERSION_ACTUELLE=`cat $FILE_FLAG` VERSION_DISPONIBLE=`cat $FILE_VERSION | grep "personnalisation" | awk -F "=" '{print $2}'` NOM_PAQUET=`cat $FILE_VERSION | grep "paquet" | awk -F "=" '{print $2}'` PAQUET_ATTENDU=`cat $FILE_VERSION | grep "version" | awk -F "=" '{print $2}'` if [ -n "$VERSION_DISPONIBLE" ] && [ -n "$NOM_PAQUET" ] && [ -n "$PAQUET_ATTENDU" ] ; then # toutes les variables du fichier sont récupérées PAQUET_ACTUEL=`dpkg -l "$NOM_PAQUET" | grep "$NOM_PAQUET" | awk '{print $3}'` PAQUET_ACTUEL=${PAQUET_ACTUEL%~*} #pour supprimer le "~..." spécifique aux paquets en phase de tests (exemple: 2.2-eole217~6.gbp4a8a23 devient 2.2-eole217) if [[ ($VERSION_DISPONIBLE -gt $VERSION_ACTUELLE) || $STATUT>0 ]] ; then #une nouvelle personnalisation est à faire if [ $PAQUET_ACTUEL = $PAQUET_ATTENDU ] ; then #le scribe est à jour, on peut donc effectuer la personnalisation FAIRE_PERSONNALISATION="oui" elif [ $VERSION_ACTUELLE = 0 ] ; then FAIRE_PERSONNALISATION="oui" #echo -e $VERT "La personnalisation est prévue pour fonctionner avec le paquet $NOM_PAQUET en version $PAQUET_ATTENDU" $NORMAL else echo -e $VERT "La personnalisation s'effectuera dès que le paquet $NOM_PAQUET sera à jour ($PAQUET_ATTENDU au lieu de $PAQUET_ACTUEL)" $NORMAL fi else echo -e $VERT "La personnalisation est à jour." $NORMAL fi fi else echo -e $ROUGE "Le fichier $FILE_VERSION n'a pas été téléchargé." $NORMAL exit 0 fi if [ $FAIRE_PERSONNALISATION = "oui" ] ; then #récupération et mise en place des fichiers #particularité du répertoire "/var/www/html/ressources" : il doit être accessible en écriture pour l'admin #on met donc les droits comme c'est prévu dans le fichier "debian/postinst" du paquet "eole-posh" sauf pour les fichiers (imposés par la personnalisation) cd /tmp/$DIR_TMP echo -e -n "Récupération des fichiers de la personnalisation Créteil... " wget -q "$URL_DIFFUSION/$ARCHIVE_PERSONNALISATION" tar xzf $ARCHIVE_PERSONNALISATION > /dev/null 2>&1 if [[ -d html && -d sso && -d scripts ]] ; then echo -e $VERT "OK" $NORMAL #mise en place des droits sur les fichiers du répertoire temporaire, ils seront ensuite copiés en conservant ses droits find html -exec chown root:www-data {} \; find html -type d -exec chmod 750 {} \; find html -type f -exec chmod 640 {} \; find sso -exec chown root:root {} \; find sso -type d -exec chmod 755 {} \; find sso -type f -exec chmod 644 {} \; #cas particulier : #pour le dossier "ressources", on s'assure de laisser les répertoires accessibles à l'admin (mais pas les fichiers imposés par la personnalisation) if [[ -d html/ressources ]] ; then find html/ressources -type d -exec chown admin:www-data {} \; find html/ressources -type d -exec chmod 770 {} \; fi if [ $ONE_FILE = "oui" ] ; then echo -e -n "Mise en place du fichier \"$2\"... " #$2 doit être de la forme racine/fichier #si le fichier existe déjà, il est le seul à voir ses droits mis à jour (pas les répertoires dans lesquels il est) #si le fichier n'existe pas et qu'il manque des répertoires, ils sont ajoutés avec les droits correspondants racine=`expr "$2" : '\([a-z]*\)/.*'` fichier=`expr "$2" : '[a-z]*/\(.*\)'` if [[ $racine = "html" && -f $2 ]] ; then cd $racine cp -rpf --parents $fichier $DIR_HTML elif [[ $racine = "sso" && -f $2 ]] ; then cd $racine cp -rpf --parents $fichier $DIR_SSO else echo -e $ROUGE "ERREUR : fichier invalide" $NORMAL exit 0 fi echo -e $VERT "OK" $NORMAL else echo -e -n "Mise en place des fichiers personnalisés... " cp -rpf html/* $DIR_HTML cp -rpf sso/* $DIR_SSO cp -rpf scripts/$SCRIPT_PERSONNALISATION $DIR_SCRIPTS #on ne copie que le script de personnalisation echo -e $VERT "OK" $NORMAL #apache doit avoir le droit d'écrire dans le dossier "portal/selections" pour la génération du cache (api/scr_cache_generate_all.php) echo -e -n "Correction des droits sur le répertoire portal/selections... " find ${DIR_POSH}portal/selections -type d -exec chmod 770 {} \; find ${DIR_POSH}portal/selections -type f -exec chmod 660 {} \; echo -e $VERT "OK" $NORMAL #traitement à part du fichier de configuration if [ -f scripts/$FILE_CONFIGURATION ] && [ ! -f ${DIR_POSH}${FILE_CONFIGURATION} ] ; then echo -e -n "Mise en place du fichier \"$FILE_CONFIGURATION\"... " if [ -f ${DIR_RESSOURCES}${FILE_CONFIGURATION} ] ; then #ancien emplacement mv ${DIR_RESSOURCES}${FILE_CONFIGURATION} ${DIR_POSH}${FILE_CONFIGURATION} else cp -f scripts/$FILE_CONFIGURATION ${DIR_POSH}${FILE_CONFIGURATION} sed -i "s/nom\s*=\s*\"[^\"]*\"/nom = \"$libelle_etab\"/" ${DIR_POSH}${FILE_CONFIGURATION} fi echo -e $VERT "OK" $NORMAL fi #droits remis systématiquement car peuvent changer (suite sans doute à une mise à jour de posh) if [ -f ${DIR_POSH}${FILE_CONFIGURATION} ] ; then chown root:www-data ${DIR_POSH}${FILE_CONFIGURATION} chmod 660 ${DIR_POSH}${FILE_CONFIGURATION} fi fi else echo -e $ROUGE "ERREUR : structure des fichiers invalide" $NORMAL exit 0 fi if [ $EXECUTER_SCRIPT = "oui" ] ; then cd $DIR_SCRIPTS echo -e -n "Exécution du script de personnalisation posh par Créteil... " ./$SCRIPT_PERSONNALISATION -m suivi_cel@ac-creteil.fr#suivieole@ac-creteil.fr --from $VERSION_ACTUELLE --to $VERSION_DISPONIBLE /etc/init.d/posh-profile restart && /etc/init.d/admin-posh-profile restart echo $VERSION_DISPONIBLE > $FILE_FLAG fi echo -e -n "Suppression des fichiers temporaires... " cd /tmp rm -rf $DIR_TMP echo -e $VERT "OK" $NORMAL fi exit 0