root/trunk/MapFish/deploy/deploy.sh

Revision 1374, 9.8 kB (checked in by elemoine, 3 weeks ago)

correct typo

Line 
1 #
2 # Copyright (C) 2008  Camptocamp
3 #
4 # This file is part of MapFish
5 #
6 # MapFish is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Lesser General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # MapFish is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU Lesser General Public License for more details.
15 #
16 # You should have received a copy of the GNU Lesser General Public License
17 # along with MapFish.  If not, see <http://www.gnu.org/licenses/>.
18
19 # MapFish deploy scripts
20 #
21 # This file should be sourced from the project deploy file.
22 # See http://trac.mapfish.org/trac/mapfish/wiki/deployment for documentation
23 #
24
25 UPSTREAM_COMPAT_VERSION=1
26
27 if [ "$COMPAT_VERSION" != "$UPSTREAM_COMPAT_VERSION" ]; then
28     echo "Your deployment file is not compatible with the latest deploy"
29     echo "script. Please check the MapFish trac for information."
30     echo " (deployment version: $COMPAT_VERSION, upstream version: $UPSTREAM_COMPAT_VERSION)"
31     exit 1
32 fi
33
34 # Default variable definitions, these can be overridden in the deploy file.
35 # See deploy-sample.sh for explanation
36
37 HAS_MAPFISH=1
38
39 # Internal definitions, shouldn't be overridden
40
41 BASE=$(cd $(dirname $0); pwd)
42 SVN="svn -q"
43 PYTHON_ENV=$BASE/env
44 SETUPTOOLS_SVN="http://svn.python.org/projects/sandbox/branches/setuptools-0.6"
45
46 #
47 # Global and Initialization functions
48 #
49
50 run_hook() {
51     if [ "$(type -t $1)" = "function" ]; then
52         echo "Running $1 hook"
53         $1
54     fi
55 }
56
57 create_python_env() {
58     if [ "$FETCH_PYTHON_ENV" != "1" ]; then
59         return
60     fi
61
62     echo "Installing python env in $PYTHON_ENV"
63
64     rm -rf $PYTHON_ENV
65     mkdir $PYTHON_ENV
66     (cd $PYTHON_ENV && \
67      wget http://svn.colorstudy.com/virtualenv/trunk/virtualenv.py && \
68      python virtualenv.py .)
69
70     # because of a bug in setuptools we need to check it out
71     # from svn and setup.py-install it
72     # see https://trac.mapfish.org/trac/mapfish/ticket/226
73     # for an explanation
74     echo "Installing setuptools in $PYTHON_ENV"
75
76     rm -rf $PYTHON_ENV/setuptools
77     (cd $PYTHON_ENV && \
78      $SVN co $SETUPTOOLS_SVN setuptools && \
79      cd setuptools && \
80      $PYTHON_ENV/bin/python setup.py install)
81 }
82
83 init_light() {
84     run_hook pre_init_light
85
86     if [ -d $PROJECT ]; then
87         rm -rf $PROJECT
88     fi
89     fetch_project $1
90
91     run_hook post_init_light
92 }
93
94 init_all() {
95     run_hook pre_init_all
96
97     create_python_env
98     init_light $1
99
100     run_hook post_init_all
101 }
102
103 #
104 # Project functions
105 #
106
107 subst_in_files() {
108     run_hook pre_subst_in_files
109
110     export PROJECT_DIR=$BASE/$PROJECT
111     echo "PROJECT_DIR: $PROJECT_DIR"
112
113     for f in \
114         $BASE/deploy/config-defaults \
115         $PROJECT_DIR/configs/defaults \
116         $PROJECT_DIR/configs/$(hostname -f) \
117         $PROJECT_DIR/configs/$(hostname -f)$(echo $PROJECT_DIR | sed s@/@-@g)\
118         ; do
119         if [ -f $f ]; then
120             echo "Importing $f"
121             . $f
122         else
123             echo "Tried to import $f"
124         fi
125     done
126
127     run_hook after_import_subst_in_files
128
129     if [ -d "$PROJECT_DIR/$PROJECT/$PROJECT/public" ]; then
130         PROCESSED_HTML=$(find $PROJECT_DIR/$PROJECT/$PROJECT/public -name "*.html.in" \
131                          -exec grep -l PROD_COMMENT_START {} \;)
132     else
133         PROCESSED_HTML=""
134     fi
135
136     if [ "$DEBUG" = "true" ]; then
137         export PROD_COMMENT_START="<!--"
138         export PROD_COMMENT_END="-->"
139     else
140         export DEBUG_COMMENT_START="<!--"
141         export DEBUG_COMMENT_END="-->"
142     fi
143
144     for f in $PROCESSED_HTML; do
145         # Create map_debug.html and map_prod.html files
146         perl -pne 's/DEBUG_COMMENT/__/g; s/%PROD_COMMENT_START%/<!--/g; s/%PROD_COMMENT_END%/-->/g' \
147                 $f > ${f%%.html.in}_debug.html.in
148         perl -pne 's/PROD_COMMENT/__/g; s/%DEBUG_COMMENT_START%/<!--/g; s/%DEBUG_COMMENT_END%/-->/g' \
149                 $f > ${f%%.html.in}_prod.html.in
150     done
151
152     echo "Substituting config variables"
153
154     find $PROJECT_DIR -name '*.in' | while read i; do
155         echo "Replacing $i"
156         perl -pne 's/%(?!\\)([\w]+)%/$ENV{$1}/ge; s/%\\([\w]+)%/%$1%/g' $i > ${i%%.in};
157     done
158
159     # This script may be generated from a .in, so we need to chmod it afterwards
160     if [ -f $PROJECT/run_standalone.sh ]; then
161         chmod +x $PROJECT/run_standalone.sh
162     fi
163
164     run_hook post_subst_in_files
165
166     for f in $PROCESSED_HTML; do
167         python $BASE/deploy/merge_js.py ${f%%.in} ${f%%.html.in}_merged.js
168     done
169 }
170
171 init_mapfish() {
172     run_hook pre_fetch_mapfish
173
174     if [ "$HAS_MAPFISH" != "1" -o "$SKIP_INIT_MAPFISH" = "1" ]; then
175         return
176     fi
177
178     if [ -z $PROJECT_MAPFISH_DIR ]; then
179         PROJECT_MAPFISH_DIR=$PROJECT/MapFish
180     fi
181
182     if [ ! -d $PROJECT_MAPFISH_DIR ]; then
183         echo "Error: no MapFish directory in project, but HAS_MAPFISH is set to 1"
184         exit 1
185     fi
186
187     CFG_FILE=""
188     if [ -f "$PROJECT/mapfish.cfg" ]; then
189         # This is relative to the build.sh file
190         CFG_FILE="../../../mapfish.cfg"
191     fi
192
193     (cd $PROJECT_MAPFISH_DIR/client/build/ && sh ./build.sh $CFG_FILE)
194
195     # Install MapFish in env if fetched
196     if [ "$FETCH_PYTHON_ENV" = "1" ]; then
197         (cd $PROJECT_MAPFISH_DIR/server/python && $PYTHON_ENV/bin/python setup.py develop)
198     fi
199
200     run_hook post_fetch_mapfish
201 }
202
203 fetch_project() {
204     run_hook pre_fetch_project
205    
206     echo "Fetching/updating project"
207     if [ -d "project_source/$PROJECT" ]; then
208         echo "Detected directory project_source/$PROJECT, using it instead of SVN"
209         rsync -av project_source/$PROJECT .
210     else
211         (echo "${PROJECT_SVN_BASE}" | egrep "(trunk|branches|tags)\/${PROJECT}\/*")
212         if [ $? -eq 0 ]; then
213             project_svn="${PROJECT_SVN_BASE}"
214         else
215             if [ -n $1 ]; then
216                 project_svn="${PROJECT_SVN_BASE}/${1}/${PROJECT}"
217             else
218                 project_svn="${PROJECT_SVN_BASE}/trunk/${PROJECT}"
219             fi
220         fi
221         $SVN co $SVN_CO_OPTIONS ${project_svn}
222     fi
223     init_mapfish
224
225     # Launch project setup.py to install project dependencies if needed
226     if [ -f $PROJECT/$PROJECT/setup.py -a "$HAS_MAPFISH" = "1" \
227          -a "$SKIP_INIT_MAPFISH" != "1" -a "$FETCH_PYTHON_ENV" = "1" ]; then
228         (cd $PROJECT/$PROJECT && $PYTHON_ENV/bin/python setup.py develop)
229     fi
230
231     subst_in_files
232
233     run_hook post_fetch_project
234 }
235
236 create_branch() {
237     $SVN mkdir -m "create dir for branch $1" ${PROJECT_SVN_BASE}/branches/$1/
238     $SVN cp -m "create branch $1" ${PROJECT_SVN_BASE}/trunk/$PROJECT ${PROJECT_SVN_BASE}/branches/$1
239     if [ "$HAS_MAPFISH" = "1" ]; then
240         #
241         # The branch includes a copy (snapshot) of MapFish as opposed
242         # to an svn:externals to MapFish trunk
243         #
244         (
245             cd /tmp
246             rm -rf $PROJECT
247             echo "fetching project, it may take some time..."
248             $SVN co ${PROJECT_SVN_BASE}/branches/$1/$PROJECT
249             cd $PROJECT
250             $SVN export MapFish MapFish_
251             $SVN propdel svn:externals MapFish .
252             $SVN commit -m "remove externals to MapFish" .
253             rm -rf MapFish
254             mv MapFish_ MapFish
255             $SVN add MapFish
256             $SVN commit -m "add MapFish" MapFish
257         )
258     fi
259 }
260
261 create_tag() {
262     echo "Enter branch name, followed by [ENTER]"
263     read branch
264     $SVN mkdir -m "create dir for tag $1" ${PROJECT_SVN_BASE}/tags/$1/
265     $SVN cp -m "create tag $1" ${PROJECT_SVN_BASE}/branches/$branch/$PROJECT ${PROJECT_SVN_BASE}/tags/$1
266 }
267
268
269 #
270 # Main function
271 #
272
273 main() {
274
275     # sanity checks
276     if [ -z "$PROJECT" ]; then
277         echo "You must declare a PROJECT variable"
278         exit 1
279     fi
280
281     opt_i="no"
282     opt_j="no"
283     opt_u="no"
284     opt_b="no"
285     opt_t="no"
286
287     while getopts ijurhb:t: OPT; do
288         case $OPT in
289         i)
290             opt_i="yes"
291             ;;
292         j)
293             opt_j="yes"
294             ;;
295         u)
296             opt_u="yes"
297             ;;
298         r)
299             echo "Replace .in files"
300             subst_in_files
301             ;;
302         b)
303             opt_b="$OPTARG"
304             ;;
305         t)
306             opt_t="$OPTARG"
307             ;;
308         \?|h)
309             echo "Usage: $0 OPTION"
310             echo " -h: help"
311             echo " -i: initialize everything "
312             echo "     WARNING: this deletes existing directories"
313             echo "     can be used with -t or -b to retrieve a specific tag or branch"
314             echo " -j: initialize MapFish and project "
315             echo "     (WARNING: this deletes existing project and MapFish)"
316             echo "     can be used with -t or -b to retrieve a specific tag or branch"
317             echo " -u: update project"
318             echo "     can be used with -t or -b to retrieve a specific tag or branch"
319             echo " -r: replace .in files"
320             echo " -b <branch_name>: if not used with -i or -j or -u create a new branch,"
321             echo "     replacing the svn:external to MapFish by a copy of MapFish"
322             echo " -t <tag_name>: if  not used with -i or -j or -u create a new tag"
323             echo
324             exit 1
325             ;;
326         esac
327     done
328
329     arg=
330     if [ $opt_b != "no" ]; then
331         arg="branches/$opt_b"
332     fi
333     if [ $opt_t != "no" ]; then
334         arg="tags/$opt_t"
335     fi
336
337     if [ $opt_i = "yes" ]; then
338         echo "Initializing everything"
339         init_all $arg
340     elif [ $opt_j = "yes" ]; then
341         echo "Initializing MapFish and project"
342         init_light $arg
343     elif [ $opt_u = "yes" ]; then
344         echo "Updating project"
345         fetch_project $arg
346     elif [ $opt_t != "no" ]; then
347         echo "Create tag from branch"
348         create_tag $opt_t
349     elif [ $opt_b != "no" ]; then
350         echo "Create branch from trunk (with a snapshot of MapFish)"
351         create_branch $opt_b
352     fi
353
354     echo "Done."
355 }
Note: See TracBrowser for help on using the browser.