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