LSmail : add possibilty to set some display options from JS
[ldapsaisie.git] / upgradeFromGit.sh
index 19a6726..46e5f96 100755 (executable)
@@ -1,34 +1,41 @@
-#!/bin/sh
+#!/bin/bash
 
-ROOT_DIR=$( cd `dirname $0`; pwd )
-
-# List of local files which will be install in web root
-LOCAL_FILES="
-"
 
+ROOT_DIR=$( cd `dirname $0`; pwd )
 LOCAL_SAV_DIR="$ROOT_DIR/config.local"
-LOG_FILE="$ROOT_DIR/upgrade.log"
 
-# The theme name to install (optional)
-#THEME="inha"
+# Import config
+if [ ! -f $LOCAL_SAV_DIR/local.sh ]
+then
+    echo "Error : You don't have create your own local.sh file in config.local directory. You could rely on the local.sh.example file to create your version."
+    exit 1
+fi
 
-# Do doc export ?
-DO_DOC=1
+source $LOCAL_SAV_DIR/local.sh
 
 function msg() {
     echo $2 "$1" | tee -a "$LOG_FILE"
 }
 
+function check_file_or_symlink() {
+    [ -f "$1" ] && echo 0 && return 0
+    if [ -L "$1" ]
+    then
+        [ -r "$1" ] && echo 0 && return 0
+        rm -f "$1"
+    fi
+    echo 1 && return 1
+}
+
 cd $ROOT_DIR
 
-msg "Clean git repos : "
+msg "-> Clean git repos : "
 for i in $LOCAL_FILES
 do
-       msg "\t-> $i :" -en
+       msg "\t-> $i : " -en
        if [ -L $i ]
        then
-               msg
-        msg "\t\t-> Delete file : " -en
+        msg "\n\t\t-> Delete file : " -en
                rm -fr $i >> $LOG_FILE 2>&1
                if [ $? -gt 0 ]
                then
@@ -54,10 +61,10 @@ do
        fi
 done
 
-if [ $DO_DOC -eq 1 ]
+if [ $BUILD_DOC -eq 1 ]
 then
-       msg "-> Clean de la doc :" -en
-       cd $SVN_DIR/doc >> $LOG_FILE && make clean >> $LOG_FILE && cd - >> $LOG_FILE
+       msg "-> Clean the doc : " -en
+       cd $ROOT_DIR/doc >> $LOG_FILE && make clean >> $LOG_FILE && cd - >> $LOG_FILE
        if [ $? -gt 0 ]
        then
                msg "Error"
@@ -70,7 +77,7 @@ fi
 if [ "$THEME" != "" ]
 then
        msg "\t\t-> Remove theme : " -en
-       rm -f $SVN_DIR/trunk/templates/$THEME $SVN_DIR/trunk/images/$THEME $SVN_DIR/trunk/css/$THEME >> $LOG_FILE 2>&1
+       rm -f $ROOT_DIR/public_html/templates/$THEME $ROOT_DIR/public_html/images/$THEME $ROOT_DIR/public_html/css/$THEME >> $LOG_FILE 2>&1
        if [ $? -gt 0 ]
        then
        msg "Error"
@@ -80,7 +87,17 @@ then
   fi
 fi
 
-msg "Verification of git repos state : "
+msg "\t\t-> Clean template cache : " -en
+rm -f $ROOT_DIR/public_html/tmp/*.tpl.php
+if [ $? -gt 0 ]
+then
+       msg "Error"
+       exit 1
+else
+       msg "Ok"
+fi
+
+msg "-> Verification of git repos state : "
 git status >> $LOG_FILE 2>&1
 if [ "$ETAT" != "" ]
 then
@@ -89,7 +106,7 @@ then
 fi
 msg "\t->[OK]" -e
 
-msg "Upgrade git repos : "
+msg "-> Upgrade git repos : "
 RES_GIT=`git pull`
 RES=$?
 msg "$RES_GIT" -e
@@ -100,7 +117,7 @@ then
 fi
 msg "\t-> [OK]" -e
 
-msg "Install local files : "
+msg "-> Install local files : "
 for i in $LOCAL_FILES
 do
        msg "\t-> $i : " -ne
@@ -108,10 +125,10 @@ do
        if [ -f $SRC ]
        then
                msg
-        if [ -f $SVN_DIR/$i ]
+        if [ -f $ROOT_DIR/$i ]
                then
                        msg "\t\t-> Backup original file : " -en
-                       mv $SVN_DIR/$i $SVN_DIR/$i.sav >> $LOG_FILE 2>&1
+                       mv $ROOT_DIR/$i $ROOT_DIR/$i.sav >> $LOG_FILE 2>&1
                        if [ $? -gt 0 ]
                        then
                                msg "Error"
@@ -122,25 +139,24 @@ do
                        msg "\t\t-> Check possible change of the original file since last upgrade : " -en
                        if [ -f $SRC.orig ]
                        then
-                               DIFF=`diff $SVN_DIR/$i.sav $SRC.orig`
-                               msg "$DIFF" -e
+                               DIFF=`diff $ROOT_DIR/$i.sav $SRC.orig`
                                if [ "$DIFF" != "" ]
                                then    
-                                       msg "\n\t\t\t-> Caution : This file changed. Do you want edit this file now ? [y/N] " -en
+                                   msg "\n$DIFF\n\t\t\t-> Caution : This file changed. Do you want edit this file now ? [y/N] " -en
                                        read a
                                        echo "Reponse : $a"  >> $LOG_FILE
                                        if [ "$a" == "y" -o "$a" == "Y" ]
                                        then
-                                               vi -d $SRC $SVN_DIR/$i.sav
+                                               vi -d $SRC $ROOT_DIR/$i.sav
                                        fi
                                else
                                        msg "No change"
                                fi
                        else
-                               echo
+                               msg "Original backup file does not exist. Pass ..."
                        fi
                        msg "\t\t-> Backup file for next upgrade : " -en
-                       cp -f $SVN_DIR/$i.sav $SRC.orig >> $LOG_FILE 2>&1
+                       cp -f $ROOT_DIR/$i.sav $SRC.orig >> $LOG_FILE 2>&1
                        if [ $? -gt 0 ]
                        then
                                msg "Error"
@@ -149,7 +165,7 @@ do
                        msg "Ok"
                fi
                msg "\t\t-> Install local file : " -en
-               ln -s $SRC $SVN_DIR/$i >> $LOG_FILE 2>&1
+               ln -s $SRC $ROOT_DIR/$i >> $LOG_FILE 2>&1
                if [ $? -gt 0 ]
                then
                        msg "Error"
@@ -160,29 +176,105 @@ do
                msg "file does not exist. Pass..."
        fi
 done
+
 if [ "$THEME" != "" ]
 then
-       msg "-> Install theme : " -en
-       ln -s $LOCAL_SAV_DIR/theme/templates $SVN_DIR/trunk/templates/$THEME >> $LOG_FILE 2>&1
-       ln -s $LOCAL_SAV_DIR/theme/images $SVN_DIR/trunk/images/$THEME >> $LOG_FILE 2>&1
-       ln -s $LOCAL_SAV_DIR/theme/css $SVN_DIR/trunk/css/$THEME >> $LOG_FILE 2>&1
-       msg "Ok"
+       msg "-> Install theme : "
+
+       # TPL
+       msg "\t- Template : " -e
+       ln -s $LOCAL_SAV_DIR/theme/templates $ROOT_DIR/public_html/templates/$THEME >> $LOG_FILE 2>&1
+       if [ -d $ROOT_DIR/public_html/templates/$THEME_TPL_REF ]
+       then
+               msg "\t\t-> Vérification de la présence des fichiers : " -e
+               for i in $ROOT_DIR/public_html/templates/$THEME_TPL_REF/*
+               do
+                       f=`basename $i`
+                       msg "\t\t\t- $f : " -en
+                       if [ `check_file_or_symlink "$ROOT_DIR/public_html/templates/$THEME/$f"` -eq 0 ]
+                       then
+                               msg "present."
+                       else
+                               ln -s $ROOT_DIR/public_html/templates/$THEME_TPL_REF/$f $ROOT_DIR/public_html/templates/$THEME/$f
+                               msg "link."
+                       fi
+               done
+       fi
+
+       # IMG
+       msg "\t- Images : " -e
+       ln -s $LOCAL_SAV_DIR/theme/images $ROOT_DIR/public_html/images/$THEME >> $LOG_FILE 2>&1
+       if [ -d $ROOT_DIR/public_html/images/$THEME_IMG_REF ]
+       then
+               msg "\t\t-> Vérification de la présence des fichiers : " -e
+               for i in $ROOT_DIR/public_html/images/$THEME_IMG_REF/*
+               do
+                       f=`basename $i`
+                       msg "\t\t\t- $f : " -en
+                       if [ `check_file_or_symlink "$ROOT_DIR/public_html/images/$THEME/$f"` -eq 0 ]
+                       then
+                               msg "present."
+                       else
+                               ln -s $ROOT_DIR/public_html/images/$THEME_IMG_REF/$f $ROOT_DIR/public_html/images/$THEME/$f
+                               msg "link."
+                       fi
+               done
+       fi
+
+       # CSS
+       msg "\t- CSS : " -e
+       ln -s $LOCAL_SAV_DIR/theme/css $ROOT_DIR/public_html/css/$THEME >> $LOG_FILE 2>&1
+       if [ -d $ROOT_DIR/public_html/css/$THEME_CSS_REF ]
+       then
+               msg "\t\t-> Vérification de la présence des fichiers : " -e
+               for i in $ROOT_DIR/public_html/css/$THEME_CSS_REF/*
+               do
+                       f=`basename $i`
+                       msg "\t\t\t- $f : " -en
+                       if [ `check_file_or_symlink "$ROOT_DIR/public_html/css/$THEME/$f"` -eq 0 ]
+                       then
+                               msg "present."
+                       else
+                               ln -s $ROOT_DIR/public_html/css/$THEME_CSS_REF/$f $ROOT_DIR/public_html/css/$THEME/$f
+                               msg "link."
+                       fi
+               done
+       fi
 fi
 
-if [ $DO_DOC -eq 1 ]
+if [ $BUILD_DOC -eq 1 ]
 then
-       msg "-> Do you want export the documentation (y/N) ? " -en
+       [ -n "$LAST_UPDATE_FILE" ] && [ "`$ROOT_DIR/checkDocExportsNecessity.sh`" == "" ] && echo "Export documentation is not necessary. Pass." && exit 
+       msg "-> Do you want build the documentation (y/N) ? " -en
        read a
        if [ "$a" == "y" -o "$a" == "Y" ]
        then
-        msg "-> Compile de la doc :" -en
-               cd $SVN_DIR/doc >> $LOG_FILE && make >> $LOG_FILE && cd - >> $LOG_FILE
-               if [ $? -gt 0 ]
-               then
-                       msg "Error"
-                       exit 1
-               else
-                       msg "Ok"
-               fi
+               msg "-> Build the doc : " -en
+               cd $ROOT_DIR/doc
+               
+               make clean >> $LOG_FILE 2>&1
+               make >> $LOG_FILE 2>&1 &
+               
+               export P=$!
+               
+               trap exitwhell INT
+               
+               function exitwhell() {
+                       [ -n "$P" ] && kill -9 $P 2> /dev/null
+                       echo " -- INT -- "
+                       exit 1
+               }
+               
+               while [ -d /proc/$P ]
+               do
+                       echo -n .
+                       sleep 1
+               done
+               echo done.
+
+               if [ -n "$EXPORT_DOC_DIR" ]
+               then
+                   $ROOT_DIR/buildDocExports.sh
+               fi
        fi
 fi