LSform : preserve current tab between view, modify and create pages
[ldapsaisie.git] / upgradeFromGit.sh
1 #!/bin/bash
2
3
4 ROOT_DIR=$( cd `dirname $0`; pwd )
5 LOCAL_SAV_DIR="$ROOT_DIR/config.local"
6
7 # Import config
8 if [ ! -f $LOCAL_SAV_DIR/local.sh ]
9 then
10     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."
11     exit 1
12 fi
13
14 source $LOCAL_SAV_DIR/local.sh
15
16 function msg() {
17     echo $2 "$1" | tee -a "$LOG_FILE"
18 }
19
20 function check_file_or_symlink() {
21     [ -f "$1" ] && echo 0 && return 0
22     if [ -L "$1" ]
23     then
24         [ -r "$1" ] && echo 0 && return 0
25         rm -f "$1"
26     fi
27     echo 1 && return 1
28 }
29
30 cd $ROOT_DIR
31
32 msg "-> Clean git repos : "
33 for i in $LOCAL_FILES
34 do
35         msg "\t-> $i : " -en
36         if [ -L $i ]
37         then
38         msg "\n\t\t-> Delete file : " -en
39                 rm -fr $i >> $LOG_FILE 2>&1
40                 if [ $? -gt 0 ]
41                 then
42                         msg "Error"
43                         exit 1
44                 else
45                         msg "Ok"
46                 fi
47                 if [ -f $i.sav ]
48                 then
49                 msg "\t\t-> Restore orignal file : " -en
50                         mv $i.sav $i >> $LOG_FILE 2>&1
51                         if [ $? -gt 0 ]
52                         then
53                                 msg "Error"
54                                 exit 1
55                         else
56                                 msg "Ok"
57                         fi
58                 fi
59         else
60                 msg "file does not exist, pass..."
61         fi
62 done
63
64 if [ $BUILD_DOC -eq 1 ]
65 then
66         msg "-> Clean the doc : " -en
67         cd $ROOT_DIR/doc >> $LOG_FILE && make clean >> $LOG_FILE && cd - >> $LOG_FILE
68         if [ $? -gt 0 ]
69         then
70                 msg "Error"
71                 exit 1
72         else
73                 msg "Ok"
74         fi
75 fi
76
77 if [ "$THEME" != "" ]
78 then
79         msg "\t\t-> Remove theme : " -en
80         rm -f $ROOT_DIR/public_html/templates/$THEME $ROOT_DIR/public_html/images/$THEME $ROOT_DIR/public_html/css/$THEME >> $LOG_FILE 2>&1
81         if [ $? -gt 0 ]
82         then
83         msg "Error"
84     exit 1
85   else
86         msg "Ok"
87   fi
88 fi
89
90 msg "-> Verification of git repos state : "
91 git status >> $LOG_FILE 2>&1
92 if [ "$ETAT" != "" ]
93 then
94         msg "\n\t-> [Error] Some changes have been made to source code since the last update." -e
95         exit 1
96 fi
97 msg "\t->[OK]" -e
98
99 msg "-> Upgrade git repos : "
100 RES_GIT=`git pull`
101 RES=$?
102 msg "$RES_GIT" -e
103 if [ $RES -gt 0 ]
104 then
105         msg "\t-> [Error] Problem during git repos pull." -e
106         exit 1
107 fi
108 msg "\t-> [OK]" -e
109
110 msg "-> Install local files : "
111 for i in $LOCAL_FILES
112 do
113         msg "\t-> $i : " -ne
114         SRC="$LOCAL_SAV_DIR/`basename $i`"
115         if [ -f $SRC ]
116         then
117                 msg
118         if [ -f $ROOT_DIR/$i ]
119                 then
120                         msg "\t\t-> Backup original file : " -en
121                         mv $ROOT_DIR/$i $ROOT_DIR/$i.sav >> $LOG_FILE 2>&1
122                         if [ $? -gt 0 ]
123                         then
124                                 msg "Error"
125                                 exit 1
126                         fi
127                         msg "Ok"
128
129                         msg "\t\t-> Check possible change of the original file since last upgrade : " -en
130                         if [ -f $SRC.orig ]
131                         then
132                                 DIFF=`diff $ROOT_DIR/$i.sav $SRC.orig`
133                                 if [ "$DIFF" != "" ]
134                                 then    
135                                     msg "\n$DIFF\n\t\t\t-> Caution : This file changed. Do you want edit this file now ? [y/N] " -en
136                                         read a
137                                         echo "Reponse : $a"  >> $LOG_FILE
138                                         if [ "$a" == "y" -o "$a" == "Y" ]
139                                         then
140                                                 vi -d $SRC $ROOT_DIR/$i.sav
141                                         fi
142                                 else
143                                         msg "No change"
144                                 fi
145                         else
146                                 msg "Original backup file does not exist. Pass ..."
147                         fi
148                         msg "\t\t-> Backup file for next upgrade : " -en
149                         cp -f $ROOT_DIR/$i.sav $SRC.orig >> $LOG_FILE 2>&1
150                         if [ $? -gt 0 ]
151                         then
152                                 msg "Error"
153                 exit 1
154                         fi
155                         msg "Ok"
156                 fi
157                 msg "\t\t-> Install local file : " -en
158                 ln -s $SRC $ROOT_DIR/$i >> $LOG_FILE 2>&1
159                 if [ $? -gt 0 ]
160                 then
161                         msg "Error"
162                         exit 1
163                 fi
164                 msg "Ok"
165         else
166                 msg "file does not exist. Pass..."
167         fi
168 done
169
170 if [ "$THEME" != "" ]
171 then
172         msg "-> Install theme : "
173
174         # TPL
175         msg "\t- Template : " -e
176         ln -s $LOCAL_SAV_DIR/theme/templates $ROOT_DIR/public_html/templates/$THEME >> $LOG_FILE 2>&1
177         if [ -d $ROOT_DIR/public_html/templates/$THEME_TPL_REF ]
178         then
179                 msg "\t\t-> Vérification de la présence des fichiers : " -e
180                 for i in $ROOT_DIR/public_html/templates/$THEME_TPL_REF/*
181                 do
182                         f=`basename $i`
183                         msg "\t\t\t- $f : " -en
184                         if [ `check_file_or_symlink "$ROOT_DIR/public_html/templates/$THEME/$f"` -eq 0 ]
185                         then
186                                 msg "present."
187                         else
188                                 ln -s $ROOT_DIR/public_html/templates/$THEME_TPL_REF/$f $ROOT_DIR/public_html/templates/$THEME/$f
189                                 msg "link."
190                         fi
191                 done
192         fi
193
194         # IMG
195         msg "\t- Images : " -e
196         ln -s $LOCAL_SAV_DIR/theme/images $ROOT_DIR/public_html/images/$THEME >> $LOG_FILE 2>&1
197         if [ -d $ROOT_DIR/public_html/images/$THEME_IMG_REF ]
198         then
199                 msg "\t\t-> Vérification de la présence des fichiers : " -e
200                 for i in $ROOT_DIR/public_html/images/$THEME_IMG_REF/*
201                 do
202                         f=`basename $i`
203                         msg "\t\t\t- $f : " -en
204                         if [ `check_file_or_symlink "$ROOT_DIR/public_html/images/$THEME/$f"` -eq 0 ]
205                         then
206                                 msg "present."
207                         else
208                                 ln -s $ROOT_DIR/public_html/images/$THEME_IMG_REF/$f $ROOT_DIR/public_html/images/$THEME/$f
209                                 msg "link."
210                         fi
211                 done
212         fi
213
214         # CSS
215         msg "\t- CSS : " -e
216         ln -s $LOCAL_SAV_DIR/theme/css $ROOT_DIR/public_html/css/$THEME >> $LOG_FILE 2>&1
217         if [ -d $ROOT_DIR/public_html/css/$THEME_CSS_REF ]
218         then
219                 msg "\t\t-> Vérification de la présence des fichiers : " -e
220                 for i in $ROOT_DIR/public_html/css/$THEME_CSS_REF/*
221                 do
222                         f=`basename $i`
223                         msg "\t\t\t- $f : " -en
224                         if [ `check_file_or_symlink "$ROOT_DIR/public_html/css/$THEME/$f"` -eq 0 ]
225                         then
226                                 msg "present."
227                         else
228                                 ln -s $ROOT_DIR/public_html/css/$THEME_CSS_REF/$f $ROOT_DIR/public_html/css/$THEME/$f
229                                 msg "link."
230                         fi
231                 done
232         fi
233 fi
234
235 if [ $BUILD_DOC -eq 1 ]
236 then
237         [ -n "$LAST_UPDATE_FILE" ] && [ "`$ROOT_DIR/checkDocExportsNecessity.sh`" == "" ] && echo "Export documentation is not necessary. Pass." && exit 
238         msg "-> Do you want build the documentation (y/N) ? " -en
239         read a
240         if [ "$a" == "y" -o "$a" == "Y" ]
241         then
242                 msg "-> Build the doc : " -en
243                 cd $ROOT_DIR/doc
244                 
245                 make clean >> $LOG_FILE 2>&1
246                 make >> $LOG_FILE 2>&1 &
247                 
248                 export P=$!
249                 
250                 trap exitwhell INT
251                 
252                 function exitwhell() {
253                         [ -n "$P" ] && kill -9 $P 2> /dev/null
254                         echo " -- INT -- "
255                         exit 1
256                 }
257                 
258                 while [ -d /proc/$P ]
259                 do
260                         echo -n .
261                         sleep 1
262                 done
263                 echo done.
264
265                 if [ -n "$EXPORT_DOC_DIR" ]
266                 then
267                     $ROOT_DIR/buildDocExports.sh
268                 fi
269         fi
270 fi