upgradeFromGit : Move configuration variables in a local.sh file.
[ldapsaisie.git] / upgradeFromGit.sh
1 #!/bin/sh
2
3
4 ROOT_DIR=$( cd `dirname $0`; pwd )
5
6 # Import config
7 if [ ! -f $ROOT_DIR/config.local/local.sh ]
8 then
9     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."
10     exit 1
11 fi
12
13 source $ROOT_DIR/config.local/local.sh
14
15 function msg() {
16     echo $2 "$1" | tee -a "$LOG_FILE"
17 }
18
19 cd $ROOT_DIR
20
21 msg "Clean git repos : "
22 for i in $LOCAL_FILES
23 do
24         msg "\t-> $i : " -en
25         if [ -L $i ]
26         then
27         msg "\n\t\t-> Delete file : " -en
28                 rm -fr $i >> $LOG_FILE 2>&1
29                 if [ $? -gt 0 ]
30                 then
31                         msg "Error"
32                         exit 1
33                 else
34                         msg "Ok"
35                 fi
36                 if [ -f $i.sav ]
37                 then
38                 msg "\t\t-> Restore orignal file : " -en
39                         mv $i.sav $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                 fi
48         else
49                 msg "file does not exist, pass..."
50         fi
51 done
52
53 if [ $DO_DOC -eq 1 ]
54 then
55         msg "-> Clean the doc : " -en
56         cd $ROOT_DIR/doc >> $LOG_FILE && make clean >> $LOG_FILE && cd - >> $LOG_FILE
57         if [ $? -gt 0 ]
58         then
59                 msg "Error"
60                 exit 1
61         else
62                 msg "Ok"
63         fi
64 fi
65
66 if [ "$THEME" != "" ]
67 then
68         msg "\t\t-> Remove theme : " -en
69         rm -f $ROOT_DIR/public_html/templates/$THEME $ROOT_DIR/public_html/images/$THEME $ROOT_DIR/public_html/css/$THEME >> $LOG_FILE 2>&1
70         if [ $? -gt 0 ]
71         then
72         msg "Error"
73     exit 1
74   else
75         msg "Ok"
76   fi
77 fi
78
79 msg "Verification of git repos state : "
80 git status >> $LOG_FILE 2>&1
81 if [ "$ETAT" != "" ]
82 then
83         msg "\n\t-> [Error] Some changes have been made to source code since the last update." -e
84         exit 1
85 fi
86 msg "\t->[OK]" -e
87
88 msg "Upgrade git repos : "
89 RES_GIT=`git pull`
90 RES=$?
91 msg "$RES_GIT" -e
92 if [ $RES -gt 0 ]
93 then
94         msg "\t-> [Error] Problem during git repos pull." -e
95         exit 1
96 fi
97 msg "\t-> [OK]" -e
98
99 msg "Install local files : "
100 for i in $LOCAL_FILES
101 do
102         msg "\t-> $i : " -ne
103         SRC="$LOCAL_SAV_DIR/`basename $i`"
104         if [ -f $SRC ]
105         then
106                 msg
107         if [ -f $ROOT_DIR/$i ]
108                 then
109                         msg "\t\t-> Backup original file : " -en
110                         mv $ROOT_DIR/$i $ROOT_DIR/$i.sav >> $LOG_FILE 2>&1
111                         if [ $? -gt 0 ]
112                         then
113                                 msg "Error"
114                                 exit 1
115                         fi
116                         msg "Ok"
117
118                         msg "\t\t-> Check possible change of the original file since last upgrade : " -en
119                         if [ -f $SRC.orig ]
120                         then
121                                 DIFF=`diff $ROOT_DIR/$i.sav $SRC.orig`
122                                 msg "$DIFF" -e
123                                 if [ "$DIFF" != "" ]
124                                 then    
125                                         msg "\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                                 echo
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 [ $DO_DOC -eq 1 ]
169 then
170         msg "-> Do you want export the documentation (y/N) ? " -en
171         read a
172         if [ "$a" == "y" -o "$a" == "Y" ]
173         then
174         msg "-> Export 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         fi
184 fi