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