2011-05-20 17:46:59 +02:00
#!/bin/bash
2009-11-13 16:41:02 +01:00
2020-05-06 12:49:11 +02:00
JUST_CLEAN = 0
while getopts ":jh" opt
do
case " $opt " in
j)
JUST_CLEAN = 1
; ;
h)
echo " Usage: $0 [-h] [-j] "
echo " -j Just clean (do not upgrade)"
echo " -h Show this message"
exit 0
; ;
esac
done
2009-11-13 16:41:02 +01:00
2009-11-13 17:04:59 +01:00
ROOT_DIR = $( cd ` dirname $0 ` ; pwd )
2009-11-13 17:21:30 +01:00
LOCAL_SAV_DIR = " $ROOT_DIR /config.local "
2009-11-13 16:41:02 +01:00
2009-11-13 17:04:59 +01:00
# Import config
2009-11-13 17:21:30 +01:00
if [ ! -f $LOCAL_SAV_DIR /local.sh ]
2009-11-13 17:04:59 +01:00
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
2009-11-13 16:41:02 +01:00
2009-11-13 17:21:30 +01:00
source $LOCAL_SAV_DIR /local.sh
2009-11-13 16:41:02 +01:00
function msg( ) {
echo $2 " $1 " | tee -a " $LOG_FILE "
}
2009-12-23 11:24:59 +01:00
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
}
2009-11-13 16:41:02 +01:00
cd $ROOT_DIR
2019-06-17 14:02:31 +02:00
msg "-> Store gettext MO files state : "
2020-05-06 12:17:35 +02:00
MO_STATE_BEFORE = $( find $ROOT_DIR /src/lang/ -type f -name '*.mo' | sort -u| xargs md5sum )
2019-06-17 14:02:31 +02:00
msg "done."
2009-11-13 18:14:14 +01:00
msg "-> Clean git repos : "
2009-11-13 16:41:02 +01:00
for i in $LOCAL_FILES
do
2009-11-13 16:55:48 +01:00
msg " \t-> $i : " -en
2009-11-13 16:41:02 +01:00
if [ -L $i ]
then
2009-11-13 16:55:48 +01:00
msg "\n\t\t-> Delete file : " -en
2009-11-13 16:41:02 +01:00
rm -fr $i >> $LOG_FILE 2>& 1
if [ $? -gt 0 ]
then
msg "Error"
exit 1
else
msg "Ok"
fi
if [ -f $i .sav ]
then
msg "\t\t-> Restore orignal file : " -en
mv $i .sav $i >> $LOG_FILE 2>& 1
if [ $? -gt 0 ]
then
msg "Error"
exit 1
else
msg "Ok"
fi
fi
else
msg "file does not exist, pass..."
fi
done
2009-11-13 18:05:59 +01:00
if [ $BUILD_DOC -eq 1 ]
2009-11-13 16:41:02 +01:00
then
2009-11-13 16:55:48 +01:00
msg "-> Clean the doc : " -en
2009-11-13 16:46:53 +01:00
cd $ROOT_DIR /doc >> $LOG_FILE && make clean >> $LOG_FILE && cd - >> $LOG_FILE
2009-11-13 16:41:02 +01:00
if [ $? -gt 0 ]
then
msg "Error"
exit 1
else
msg "Ok"
fi
fi
if [ " $THEME " != "" ]
then
msg "\t\t-> Remove theme : " -en
2020-05-06 12:17:35 +02:00
rm -f $ROOT_DIR /src/templates/$THEME $ROOT_DIR /src/images/$THEME $ROOT_DIR /src/css/$THEME >> $LOG_FILE 2>& 1
2009-11-13 16:41:02 +01:00
if [ $? -gt 0 ]
then
msg "Error"
exit 1
else
msg "Ok"
fi
fi
2016-01-28 17:35:03 +01:00
msg "\t\t-> Clean template cache : " -en
2020-05-06 12:17:35 +02:00
rm -f $ROOT_DIR /src/tmp/*.tpl.php
2016-01-28 17:35:03 +01:00
if [ $? -gt 0 ]
then
msg "Error"
exit 1
else
msg "Ok"
fi
2009-11-13 18:14:14 +01:00
msg "-> Verification of git repos state : "
2009-11-13 16:41:02 +01:00
git status >> $LOG_FILE 2>& 1
if [ " $ETAT " != "" ]
then
msg "\n\t-> [Error] Some changes have been made to source code since the last update." -e
exit 1
fi
msg "\t->[OK]" -e
2020-05-06 12:49:11 +02:00
if [ $JUST_CLEAN -eq 1 ]
then
msg "-> Just-clean mode : stop."
exit 0
fi
msg "-> Store MD5 sum of the upgrade script to detect update on it :"
UPGRADE_SCRIPT_MD5 = $( md5sum $0 )
msg "\t->[OK]" -e
2009-11-13 18:14:14 +01:00
msg "-> Upgrade git repos : "
2009-11-13 16:41:02 +01:00
RES_GIT = ` git pull`
RES = $?
msg " $RES_GIT " -e
if [ $RES -gt 0 ]
then
msg "\t-> [Error] Problem during git repos pull." -e
exit 1
fi
msg "\t-> [OK]" -e
2020-05-06 12:49:11 +02:00
msg "-> Check change on upgrade script :"
2020-05-06 12:52:13 +02:00
if [ " $UPGRADE_SCRIPT_MD5 " != " $( md5sum $0 ) " ]
2020-05-06 12:49:11 +02:00
then
msg " \t-> [WARNING] Changes detected on $0 script => Re-run it from start " -e
$0 $@
exit $?
else
2020-05-06 12:52:13 +02:00
msg "\t-> [OK] No change detected on upgrade script." -e
2020-05-06 12:49:11 +02:00
fi
2009-11-13 18:14:14 +01:00
msg "-> Install local files : "
2009-11-13 16:41:02 +01:00
for i in $LOCAL_FILES
do
msg " \t-> $i : " -ne
SRC = " $LOCAL_SAV_DIR /`basename $i ` "
if [ -f $SRC ]
then
msg
2009-11-13 16:46:53 +01:00
if [ -f $ROOT_DIR /$i ]
2009-11-13 16:41:02 +01:00
then
msg "\t\t-> Backup original file : " -en
2009-11-13 16:46:53 +01:00
mv $ROOT_DIR /$i $ROOT_DIR /$i .sav >> $LOG_FILE 2>& 1
2009-11-13 16:41:02 +01:00
if [ $? -gt 0 ]
then
msg "Error"
exit 1
fi
msg "Ok"
msg "\t\t-> Check possible change of the original file since last upgrade : " -en
if [ -f $SRC .orig ]
then
2009-11-13 16:46:53 +01:00
DIFF = ` diff $ROOT_DIR /$i .sav $SRC .orig`
2009-11-13 16:41:02 +01:00
if [ " $DIFF " != "" ]
2020-05-06 12:17:35 +02:00
then
2009-11-13 17:21:30 +01:00
msg " \n $DIFF \n\t\t\t-> Caution : This file changed. Do you want edit this file now ? [y/N] " -en
2009-11-13 16:41:02 +01:00
read a
echo " Reponse : $a " >> $LOG_FILE
if [ " $a " = = "y" -o " $a " = = "Y" ]
then
2009-11-13 16:46:53 +01:00
vi -d $SRC $ROOT_DIR /$i .sav
2009-11-13 16:41:02 +01:00
fi
else
msg "No change"
fi
else
2009-11-13 17:21:30 +01:00
msg "Original backup file does not exist. Pass ..."
2009-11-13 16:41:02 +01:00
fi
msg "\t\t-> Backup file for next upgrade : " -en
2009-11-13 16:46:53 +01:00
cp -f $ROOT_DIR /$i .sav $SRC .orig >> $LOG_FILE 2>& 1
2009-11-13 16:41:02 +01:00
if [ $? -gt 0 ]
then
msg "Error"
exit 1
fi
msg "Ok"
fi
msg "\t\t-> Install local file : " -en
2009-11-13 16:46:53 +01:00
ln -s $SRC $ROOT_DIR /$i >> $LOG_FILE 2>& 1
2009-11-13 16:41:02 +01:00
if [ $? -gt 0 ]
then
msg "Error"
exit 1
fi
msg "Ok"
else
msg "file does not exist. Pass..."
fi
done
2009-12-15 18:33:22 +01:00
2009-11-13 16:41:02 +01:00
if [ " $THEME " != "" ]
then
2009-12-15 18:33:22 +01:00
msg "-> Install theme : "
# TPL
msg "\t- Template : " -e
2020-05-06 12:17:35 +02:00
ln -s $LOCAL_SAV_DIR /theme/templates $ROOT_DIR /src/templates/$THEME >> $LOG_FILE 2>& 1
if [ -d $ROOT_DIR /src/templates/$THEME_TPL_REF ]
2009-12-15 18:33:22 +01:00
then
msg "\t\t-> Vérification de la présence des fichiers : " -e
2020-05-06 12:17:35 +02:00
for i in $ROOT_DIR /src/templates/$THEME_TPL_REF /*
2009-12-15 18:33:22 +01:00
do
f = ` basename $i `
msg " \t\t\t- $f : " -en
2020-05-06 12:17:35 +02:00
if [ ` check_file_or_symlink " $ROOT_DIR /src/templates/ $THEME / $f " ` -eq 0 ]
2009-12-15 18:33:22 +01:00
then
msg "present."
else
2020-05-06 12:17:35 +02:00
ln -s $ROOT_DIR /src/templates/$THEME_TPL_REF /$f $ROOT_DIR /src/templates/$THEME /$f
2009-12-15 18:33:22 +01:00
msg "link."
fi
done
fi
# IMG
msg "\t- Images : " -e
2020-05-06 12:17:35 +02:00
ln -s $LOCAL_SAV_DIR /theme/images $ROOT_DIR /src/images/$THEME >> $LOG_FILE 2>& 1
if [ -d $ROOT_DIR /src/images/$THEME_IMG_REF ]
2009-12-15 18:33:22 +01:00
then
msg "\t\t-> Vérification de la présence des fichiers : " -e
2020-05-06 12:17:35 +02:00
for i in $ROOT_DIR /src/images/$THEME_IMG_REF /*
2009-12-15 18:33:22 +01:00
do
f = ` basename $i `
msg " \t\t\t- $f : " -en
2020-05-06 12:17:35 +02:00
if [ ` check_file_or_symlink " $ROOT_DIR /src/images/ $THEME / $f " ` -eq 0 ]
2009-12-15 18:33:22 +01:00
then
msg "present."
else
2020-05-06 12:17:35 +02:00
ln -s $ROOT_DIR /src/images/$THEME_IMG_REF /$f $ROOT_DIR /src/images/$THEME /$f
2009-12-15 18:33:22 +01:00
msg "link."
fi
done
fi
# CSS
msg "\t- CSS : " -e
2020-05-06 12:17:35 +02:00
ln -s $LOCAL_SAV_DIR /theme/css $ROOT_DIR /src/css/$THEME >> $LOG_FILE 2>& 1
if [ -d $ROOT_DIR /src/css/$THEME_CSS_REF ]
2009-12-15 18:33:22 +01:00
then
msg "\t\t-> Vérification de la présence des fichiers : " -e
2020-05-06 12:17:35 +02:00
for i in $ROOT_DIR /src/css/$THEME_CSS_REF /*
2009-12-15 18:33:22 +01:00
do
f = ` basename $i `
msg " \t\t\t- $f : " -en
2020-05-06 12:17:35 +02:00
if [ ` check_file_or_symlink " $ROOT_DIR /src/css/ $THEME / $f " ` -eq 0 ]
2009-12-15 18:33:22 +01:00
then
msg "present."
else
2020-05-06 12:17:35 +02:00
ln -s $ROOT_DIR /src/css/$THEME_CSS_REF /$f $ROOT_DIR /src/css/$THEME /$f
2009-12-15 18:33:22 +01:00
msg "link."
fi
done
fi
2009-11-13 16:41:02 +01:00
fi
2019-06-17 14:02:31 +02:00
msg "-> Check for gettext MO files changes : "
2020-05-06 12:17:35 +02:00
MO_STATE_AFTER = $( find $ROOT_DIR /src/lang/ -type f -name '*.mo' | sort -u| xargs md5sum )
2019-06-17 14:02:31 +02:00
if [ " $MO_STATE_AFTER " = = " $MO_STATE_BEFORE " ]
then
msg "No change detected."
elif [ -n " $WEBSERVER_RELOAD_CMD " ]
then
msg "Changed detected : try to webserver to handle changes..."
$WEBSERVER_RELOAD_CMD
if [ $? -eq 0 ]
then
msg "done."
else
msg "ERROR"
fi
else
msg "Changed detected :\n\n/!\\ You have to force-reload your webserver to handle it ! /!\\\n\n"
fi
2009-11-13 18:05:59 +01:00
if [ $BUILD_DOC -eq 1 ]
2009-11-13 16:41:02 +01:00
then
2020-05-06 12:17:35 +02:00
[ -n " $LAST_UPDATE_FILE " ] && [ " ` $ROOT_DIR /checkDocExportsNecessity.sh` " = = "" ] && echo "Export documentation is not necessary. Pass." && exit
2009-11-13 18:50:48 +01:00
msg "-> Do you want build the documentation (y/N) ? " -en
2009-11-13 16:41:02 +01:00
read a
if [ " $a " = = "y" -o " $a " = = "Y" ]
then
2010-04-21 14:18:43 +02:00
msg "-> Build the doc : " -en
cd $ROOT_DIR /doc
2020-05-06 12:17:35 +02:00
2010-04-21 14:18:43 +02:00
make clean >> $LOG_FILE 2>& 1
make >> $LOG_FILE 2>& 1 &
2020-05-06 12:17:35 +02:00
2010-04-21 14:18:43 +02:00
export P = $!
2020-05-06 12:17:35 +02:00
2010-04-21 14:18:43 +02:00
trap exitwhell INT
2020-05-06 12:17:35 +02:00
2010-04-21 14:18:43 +02:00
function exitwhell( ) {
[ -n " $P " ] && kill -9 $P 2> /dev/null
echo " -- INT -- "
exit 1
}
2020-05-06 12:17:35 +02:00
2010-04-21 14:18:43 +02:00
while [ -d /proc/$P ]
do
echo -n .
sleep 1
done
echo done .
2009-11-13 18:05:59 +01:00
2010-04-21 14:18:43 +02:00
if [ -n " $EXPORT_DOC_DIR " ]
then
$ROOT_DIR /buildDocExports.sh
fi
fi
2009-11-13 16:41:02 +01:00
fi