upgradeFromGit : fix bug
[ldapsaisie.git] / upgradeFromGit.sh
1 #!/bin/sh
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 cd $ROOT_DIR
21
22 msg "-> Clean git repos : "
23 for i in $LOCAL_FILES
24 do
25         msg "\t-> $i : " -en
26         if [ -L $i ]
27         then
28         msg "\n\t\t-> Delete file : " -en
29                 rm -fr $i >> $LOG_FILE 2>&1
30                 if [ $? -gt 0 ]
31                 then
32                         msg "Error"
33                         exit 1
34                 else
35                         msg "Ok"
36                 fi
37                 if [ -f $i.sav ]
38                 then
39                 msg "\t\t-> Restore orignal file : " -en
40                         mv $i.sav $i >> $LOG_FILE 2>&1
41                         if [ $? -gt 0 ]
42                         then
43                                 msg "Error"
44                                 exit 1
45                         else
46                                 msg "Ok"
47                         fi
48                 fi
49         else
50                 msg "file does not exist, pass..."
51         fi
52 done
53
54 if [ $BUILD_DOC -eq 1 ]
55 then
56         msg "-> Clean the doc : " -en
57         cd $ROOT_DIR/doc >> $LOG_FILE && make clean >> $LOG_FILE && cd - >> $LOG_FILE
58         if [ $? -gt 0 ]
59         then
60                 msg "Error"
61                 exit 1
62         else
63                 msg "Ok"
64         fi
65 fi
66
67 if [ "$THEME" != "" ]
68 then
69         msg "\t\t-> Remove theme : " -en
70         rm -f $ROOT_DIR/public_html/templates/$THEME $ROOT_DIR/public_html/images/$THEME $ROOT_DIR/public_html/css/$THEME >> $LOG_FILE 2>&1
71         if [ $? -gt 0 ]
72         then
73         msg "Error"
74     exit 1
75   else
76         msg "Ok"
77   fi
78 fi
79
80 msg "-> Verification of git repos state : "
81 git status >> $LOG_FILE 2>&1
82 if [ "$ETAT" != "" ]
83 then
84         msg "\n\t-> [Error] Some changes have been made to source code since the last update." -e
85         exit 1
86 fi
87 msg "\t->[OK]" -e
88
89 msg "-> Upgrade git repos : "
90 RES_GIT=`git pull`
91 RES=$?
92 msg "$RES_GIT" -e
93 if [ $RES -gt 0 ]
94 then
95         msg "\t-> [Error] Problem during git repos pull." -e
96         exit 1
97 fi
98 msg "\t-> [OK]" -e
99
100 msg "-> Install local files : "
101 for i in $LOCAL_FILES
102 do
103         msg "\t-> $i : " -ne
104         SRC="$LOCAL_SAV_DIR/`basename $i`"
105         if [ -f $SRC ]
106         then
107                 msg
108         if [ -f $ROOT_DIR/$i ]
109                 then
110                         msg "\t\t-> Backup original file : " -en
111                         mv $ROOT_DIR/$i $ROOT_DIR/$i.sav >> $LOG_FILE 2>&1
112                         if [ $? -gt 0 ]
113                         then
114                                 msg "Error"
115                                 exit 1
116                         fi
117                         msg "Ok"
118
119                         msg "\t\t-> Check possible change of the original file since last upgrade : " -en
120                         if [ -f $SRC.orig ]
121                         then
122                                 DIFF=`diff $ROOT_DIR/$i.sav $SRC.orig`
123                                 if [ "$DIFF" != "" ]
124                                 then    
125                                     msg "\n$DIFF\n\t\t\t-> Caution : This file changed. Do you want edit this file now ? [y/N] " -en
126                                         read a
127                                         echo "Reponse : $a"  >> $LOG_FILE
128                                         if [ "$a" == "y" -o "$a" == "Y" ]
129                                         then
130                                                 vi -d $SRC $ROOT_DIR/$i.sav
131                                         fi
132                                 else
133                                         msg "No change"
134                                 fi
135                         else
136                                 msg "Original backup file does not exist. Pass ..."
137                         fi
138                         msg "\t\t-> Backup file for next upgrade : " -en
139                         cp -f $ROOT_DIR/$i.sav $SRC.orig >> $LOG_FILE 2>&1
140                         if [ $? -gt 0 ]
141                         then
142                                 msg "Error"
143                 exit 1
144                         fi
145                         msg "Ok"
146                 fi
147                 msg "\t\t-> Install local file : " -en
148                 ln -s $SRC $ROOT_DIR/$i >> $LOG_FILE 2>&1
149                 if [ $? -gt 0 ]
150                 then
151                         msg "Error"
152                         exit 1
153                 fi
154                 msg "Ok"
155         else
156                 msg "file does not exist. Pass..."
157         fi
158 done
159 if [ "$THEME" != "" ]
160 then
161         msg "-> Install theme : " -en
162         ln -s $LOCAL_SAV_DIR/theme/templates $ROOT_DIR/public_html/templates/$THEME >> $LOG_FILE 2>&1
163         ln -s $LOCAL_SAV_DIR/theme/images $ROOT_DIR/public_html/images/$THEME >> $LOG_FILE 2>&1
164         ln -s $LOCAL_SAV_DIR/theme/css $ROOT_DIR/public_html/css/$THEME >> $LOG_FILE 2>&1
165         msg "Ok"
166 fi
167
168 if [ $BUILD_DOC -eq 1 ]
169 then
170         msg "-> Do you want build the documentation (y/N) ? " -en
171         read a
172         if [ "$a" == "y" -o "$a" == "Y" ]
173         then
174         msg "-> Build the doc : " -en
175                 cd $ROOT_DIR/doc >> $LOG_FILE 2>&1 && make >> $LOG_FILE 2>&1 && cd - >> $LOG_FILE 2>&1
176                 if [ $? -gt 0 ]
177                 then
178                         msg "Error"
179                         exit 1
180                 else
181                         msg "Ok"
182                 fi
183
184         if [ -n "$EXPORT_DOC_DIR" ]
185         then
186             $ROOT_DIR/buildDocExports.sh
187         fi
188     fi
189 fi