root/sandbox/camptocamp/MapFishUnhcr/deploy/deploy.sh @ 1055

Revision 1055, 7.3 kB (checked in by elemoine, 5 years ago)

commit hack for Python 2.4 that was mistakenly removed in a previous commit ([1031])

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
25UPSTREAM_COMPAT_VERSION=1
26
27if [ "$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
32fi
33
34# Default variable definitions, these can be overridden in the deploy file.
35# See deploy-sample.sh for explanation
36
37HAS_MAPFISH=1
38
39# Internal definitions, shouldn't be overridden
40
41BASE=$(cd $(dirname $0); pwd)
42SVN="svn -q"
43PYTHON_ENV=$BASE/env
44SETUPTOOLS_SVN="http://svn.python.org/projects/sandbox/branches/setuptools-0.6"
45
46#
47# Global and Initialization functions
48#
49
50run_hook() {
51    if [ "$(type -t $1)" = "function" ]; then
52        echo "Running $1 hook"
53        $1
54    fi
55}
56
57create_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    # don't ask me why but the installation of Pylons is broken through setup.py
71    # with Python 2.4, as a workaround Pylons is installed upfront using easy_install
72    # I hate that...
73    $PYTHON_ENV/bin/easy_install 'Pylons<=0.9.6.99'
74
75    # because of a bug in setuptools we need to check it out
76    # from svn and setup.py-install it
77    # see https://trac.mapfish.org/trac/mapfish/ticket/226
78    # for an explanation
79    echo "Installing setuptools in $PYTHON_ENV"
80
81    rm -rf $PYTHON_ENV/setuptools
82    (cd $PYTHON_ENV && \
83     $SVN co $SETUPTOOLS_SVN setuptools && \
84     cd setuptools && \
85     $PYTHON_ENV/bin/python setup.py install)
86}
87
88init_light() {
89    run_hook pre_init_light
90
91    if [ -d $PROJECT ]; then
92        rm -rf $PROJECT
93    fi
94    fetch_project
95
96    run_hook post_init_light
97}
98
99init_all() {
100    run_hook pre_init_all
101
102    create_python_env
103    init_light
104
105    run_hook post_init_all
106}
107
108#
109# Project functions
110#
111
112subst_in_files() {
113    run_hook pre_subst_in_files
114
115    export PROJECT_DIR=$BASE/$PROJECT
116    echo "PROJECT_DIR: $PROJECT_DIR"
117
118    for f in \
119        $BASE/deploy/config-defaults \
120        $PROJECT_DIR/configs/defaults \
121        $PROJECT_DIR/configs/$(hostname -f) \
122        $PROJECT_DIR/configs/$(hostname -f)$(echo $PROJECT_DIR | sed s@/@-@g)\
123        ; do
124        if [ -f $f ]; then
125            echo "Importing $f"
126            . $f
127        else
128            echo "Tried to import $f"
129        fi
130    done
131
132    run_hook after_import_subst_in_files
133
134    if [ -d "$PROJECT_DIR/$PROJECT/$PROJECT/public" ]; then
135        PROCESSED_HTML=$(find $PROJECT_DIR/$PROJECT/$PROJECT/public -name "*.html.in" \
136                         -exec grep -l PROD_COMMENT_START {} \;)
137    else
138        PROCESSED_HTML=""
139    fi
140
141    if [ "$DEBUG" = "true" ]; then
142        export PROD_COMMENT_START="<!--"
143        export PROD_COMMENT_END="-->"
144    else
145        export DEBUG_COMMENT_START="<!--"
146        export DEBUG_COMMENT_END="-->"
147    fi
148
149    for f in $PROCESSED_HTML; do
150        # Create map_debug.html and map_prod.html files
151        perl -pne 's/DEBUG_COMMENT/__/g; s/%PROD_COMMENT_START%/<!--/g; s/%PROD_COMMENT_END%/-->/g' \
152                $f > ${f%%.html.in}_debug.html.in
153        perl -pne 's/PROD_COMMENT/__/g; s/%DEBUG_COMMENT_START%/<!--/g; s/%DEBUG_COMMENT_END%/-->/g' \
154                $f > ${f%%.html.in}_prod.html.in
155    done
156
157    echo "Substituting config variables"
158
159    find $PROJECT_DIR -name '*.in' | while read i; do
160        echo "Replacing $i"
161        perl -pne 's/%(?!\\)([\w]+)%/$ENV{$1}/ge; s/%\\([\w]+)%/%$1%/g' $i > ${i%%.in};
162    done
163
164    # This script may be generated from a .in, so we need to chmod it afterwards
165    if [ -f $PROJECT/run_standalone.sh ]; then
166        chmod +x $PROJECT/run_standalone.sh
167    fi
168
169    run_hook post_subst_in_files
170
171    for f in $PROCESSED_HTML; do
172        python $BASE/deploy/merge_js.py ${f%%.in} ${f%%.html.in}_merged.js
173    done
174}
175
176init_mapfish() {
177    run_hook pre_fetch_mapfish
178
179    if [ "$HAS_MAPFISH" != "1" -o "$SKIP_INIT_MAPFISH" = "1" ]; then
180        return
181    fi
182
183    if [ -z $PROJECT_MAPFISH_DIR ]; then
184        PROJECT_MAPFISH_DIR=$PROJECT/MapFish
185    fi
186
187    if [ ! -d $PROJECT_MAPFISH_DIR ]; then
188        echo "Error: no MapFish directory in project, but HAS_MAPFISH is set to 1"
189        exit 1
190    fi
191
192    CFG_FILE=""
193    if [ -f "$PROJECT/mapfish.cfg" ]; then
194        # This is relative to the build.sh file
195        CFG_FILE="../../../mapfish.cfg"
196    fi
197
198    (cd $PROJECT_MAPFISH_DIR/client/build/ && sh ./build.sh $CFG_FILE)
199
200    # Install MapFish in env if fetched
201    if [ "$FETCH_PYTHON_ENV" = "1" ]; then
202        (cd $PROJECT_MAPFISH_DIR/server/python && $PYTHON_ENV/bin/python setup.py develop)
203    fi
204
205    run_hook post_fetch_mapfish
206}
207
208fetch_project() {
209    run_hook pre_fetch_project
210
211    echo "Fetching/updating project"
212    if [ -d "project_source/$PROJECT" ]; then
213        echo "Detected directory project_source/$PROJECT, using it instead of SVN"
214        rsync -av project_source/$PROJECT .
215    else
216        $SVN co $SVN_CO_OPTIONS ${PROJECT_SVN_BASE}
217    fi
218    init_mapfish
219
220    # Launch project setup.py to install project dependencies if needed
221    if [ -f $PROJECT/$PROJECT/setup.py -a "$HAS_MAPFISH" = "1" \
222         -a "$SKIP_INIT_MAPFISH" != "1" -a "$FETCH_PYTHON_ENV" = "1" ]; then
223        (cd $PROJECT/$PROJECT && $PYTHON_ENV/bin/python setup.py develop)
224    fi
225
226    subst_in_files
227
228    run_hook post_fetch_project
229}
230
231#
232# Main function
233#
234
235main() {
236
237    # sanity checks
238    if [ -z "$PROJECT" ]; then
239        echo "You must declare a PROJECT variable"
240        exit 1
241    fi
242
243    while getopts ijurh OPT; do
244        case $OPT in
245        i)
246            echo "Initializing everything"
247            init_all
248            ;;
249        j)
250            echo "Initializing MapFish and project"
251            init_light
252            ;;
253        u)
254            echo "Updating project"
255            fetch_project
256            ;;
257        r)
258            echo "Replace .in files"
259            subst_in_files
260            ;;
261        \?|h)
262            echo "Usage: $0 OPTION"
263            echo " -h: help"
264            echo -n " -i: initialize everything "
265            echo "(WARNING: this deletes existing directories)"
266            echo -n " -j: initialize MapFish and project "
267            echo "(WARNING: this deletes existing project and MapFish)"
268            echo " -u: update project"
269            echo " -r: replace .in files"
270            exit 1
271            ;;
272        esac
273    done
274    echo "Done."
275}
Note: See TracBrowser for help on using the browser.