source: subversion/applications/utils/debian/make_install_files.sh @ 13581

Last change on this file since 13581 was 13581, checked in by joerg, 11 years ago

Improved Error Handling

  • Property svn:executable set to *
File size: 11.3 KB
Line 
1#!/bin/bash
2# This script replaces a make ; make install for creation of the debian package.
3# Maybe you can also use it to install the stuff on your system.
4# If you are successfull, please write how to do this here
5# PS.: Any improvements/additions to this installer are welcome.
6
7dst_path=$1
8
9if [ ! -n "$dst_path" ] ; then
10    echo "Please specify a Directory to use as Basedirectory"
11    echo "Usage:"
12    echo "     $0 <working-dir>"
13    exit -1
14fi
15
16# define Colors
17ESC=`echo -e "\033"`
18RED="${ESC}[91m"
19GREEN="${ESC}[92m"
20YELLOW="${ESC}[93m"
21BLUE="${ESC}[94m"
22MAGENTA="${ESC}[95m"
23CYAN="${ESC}[96m"
24WHITE="${ESC}[97m"
25BG_RED="${ESC}[41m"
26BG_GREEN="${ESC}[42m"
27BG_YELLOW="${ESC}[43m"
28BG_BLUE="${ESC}[44m"
29BG_MAGENTA="${ESC}[45m"
30BG_CYAN="${ESC}[46m"
31BG_WHITE="${ESC}[47m"
32BRIGHT="${ESC}[01m"
33UNDERLINE="${ESC}[04m"
34BLINK="${ESC}[05m"
35REVERSE="${ESC}[07m"
36NORMAL="${ESC}[0m"
37
38echo "copying Files to '$dst_path'"
39package_name=openstreetmap
40dst_path=${dst_path%/}
41platform=`uname -m`
42
43perl_path="$dst_path/usr/share/perl5"
44bin_path="$dst_path/usr/bin"
45lib_path="$dst_path/usr/lib"
46share_path="$dst_path/usr/share/$package_name"
47man1_path="$dst_path/usr/man/man1"
48mkdir -p "$perl_path"
49mkdir -p "$bin_path"
50mkdir -p "$lib_path"
51mkdir -p "$share_path"
52mkdir -p "$man1_path"
53
54
55
56# #######################################################
57# Osmosis
58# #######################################################
59if true; then
60    echo "${BLUE}----------> applications/utils/osmosis/trunk Osmosis${NORMAL}"
61
62    cd osmosis
63
64    # Osmosis moves it's Binary arround, so to be sure we do not catch old Versions and don't
65    # recognize it we remove all osmosis.jar Files first
66    find . -name "osmosis*.jar" -print0 | xargs -0 rm
67
68    cd trunk
69
70    ant clean >build.log 2>build.err
71    ant dist >>build.log 2>>build.err
72    if [ "$?" -ne "0" ] ; then
73        echo "${RED}!!!!!! ERROR compiling  Osmosis ${NORMAL}"
74        exit -1
75    fi
76    cd ../..
77
78    osmosis_dir="$dst_path/usr/local/share/osmosis/"
79    mkdir -p $osmosis_dir
80    cp osmosis/trunk/build/binary/osmosis.jar $osmosis_dir
81    if [ "$?" -ne "0" ] ; then
82        echo "${RED}!!!!!! ERROR cannot find resulting osmosis.jar ${NORMAL}"
83        exit -1
84    fi
85
86    # copy needed libs
87    mkdir -p $osmosis_dir/lib/
88    cp osmosis/trunk/lib/default/*.jar $osmosis_dir/lib/
89    if [ "$?" -ne "0" ] ; then
90        echo "${RED}!!!!!! ERROR cannot copy needed libs for osmosis${NORMAL}"
91        exit -1
92    fi
93
94    # Osmosis script
95    src_fn="osmosis/trunk/bin/osmosis"
96    man1_fn="$man1_path/osmosis.1"
97    if grep -q -e "--help" "$src_fn"; then
98        echo "Create Man Page from Help '$man1_fn'"
99        perl $src_fn --help >"$man1_fn"
100    else
101        echo "!!!! No idea how to create Man Page for $src_fn"
102    fi
103    mkdir -p $osmosis_dir/bin
104    cp $src_fn "$osmosis_dir/bin/osmosis"
105    if [ "$?" -ne "0" ] ; then
106        echo "${RED}!!!!!! ERROR cannot find resulting osmosis script ${NORMAL}"
107        exit -1
108    fi
109
110    ln -sf /usr/local/share/osmosis/bin/osmosis $bin_path/osmosis
111fi
112
113# ------------------------------------------------------------------
114# Utilities written in C
115
116# ------------------------------------------------------------------
117# Various libs
118for lib in ccoord libosm libimg  ; do 
119    allow_error=false
120    if [ "$platform" == "x86_64" ] ; then
121        if echo $lib | grep -q -e libosm -e ccoord -e libimg ; then
122            allow_error=true
123        fi
124    fi
125
126    echo "${BLUE}----------> applications/lib/$lib${NORMAL}"
127    cd ../lib/$lib
128
129    # for a in *.cpp ; do perl -p -i -e 's,libshp/shapefil.h,shapefil.h,g' $a; done
130    make clean >build.log 2>build.err
131
132    make >>build.log 2>>build.err
133    if [ "$?" -ne "0" ] ; then
134        if $allow_error ; then
135            echo "Ignored Errors in 'applications/lib/$lib' because it does not compile on my debian $platform machine"
136            cd ..
137            continue
138        fi
139        echo "${RED}!!!!!! ERROR compiling $lib ${NORMAL}"
140        echo "Logfile is at `pwd`/build.log build.err"
141        exit -1
142    fi
143    cd ..
144    result_lib=$lib/lib${lib}.a
145    result_lib=`find . -name "*${lib}*.a"`
146    test -s "$result_lib" || result_lib="$lib/${lib}.a"
147    if [ ! -s "$result_lib"  ] ; then
148        echo "${RED}!!!!!! ERROR compiling $lib no Resulting '$result_lib'${NORMAL}"
149        exit -1
150    fi
151    cp "$result_lib" "../utils/${lib_path}" || exit -1
152done
153cd ../utils/
154
155# Perl-libs
156for lib in Geo-OSM-MapFeatures ; do 
157    echo "${BLUE}----------> applications/lib/$lib${NORMAL} (Compile only)"
158    cd ../lib/$lib
159
160    # for a in *.cpp ; do perl -p -i -e 's,libshp/shapefil.h,shapefil.h,g' $a; done
161    make clean >build.log 2>build.err
162
163    if [ -s "Makefile.PL" ] ; then
164        perl Makefile.PL >>build.log 2>>build.err
165        if [ "$?" -ne "0" ] ; then
166            echo "${RED}!!!!!! ERROR compiling $lib ${NORMAL}"
167            echo "Logfile is at `pwd`/build.log build.err"
168            exit -1
169        fi
170
171    fi
172
173    make >>build.log 2>>build.err
174    if [ "$?" -ne "0" ] ; then
175        echo "${RED}!!!!!! ERROR compiling $lib ${NORMAL}"
176        echo "Logfile is at `pwd`/build.log build.err"
177        exit -1
178    fi
179
180    cd ..
181
182    #!!!!!!!!!!!!!!!!
183    # TODO: Copy resulting *.pm and ManPages
184    #
185done
186cd ../utils/
187
188
189# ------------------------------------------------------------------
190# Importer
191for import in `ls import/*/Makefile| sed 's,/Makefile,,;s,import/,,'` ; do 
192    allow_error=false
193    if echo $import | grep -q  and_import ; then
194        allow_error=true
195    fi
196
197    echo "${BLUE}----------> applications/utils/import/$import${NORMAL}"
198    cd import/$import/
199    make clean >build.log 2>build.err
200    make >>build.log 2>>build.err
201    if [ "$?" -ne "0" ] ; then
202        if $allow_error ; then
203            echo "Ignored 'applications/import/$import' because it does not compile on my debian machine"
204            cd ../..
205            continue
206        fi
207        echo "${RED}!!!!!! ERROR compiling  import/${import} ${NORMAL}"
208        exit -1
209    fi
210    cd ../..
211    cp import/$import/2AND  ${bin_path}/osm2AND
212done
213
214# ------------------------------------------------------------------
215# Filter
216# As soon it compiles here on my debian machine
217# i will remove the excludes
218for filter in `ls filter/*/Makefile| sed 's,/Makefile,,;s,filter/,,'` ; do 
219    allow_error=false
220    if echo $filter | grep -q wayclean ; then
221        allow_error=true
222    fi
223
224    echo "${BLUE}----------> applications/utils/filter/${filter}${NORMAL}"
225    cd filter/${filter}  || exit -1
226    make clean >build.log 2>build.err
227    make >>build.log 2>>build.err
228    if [ "$?" -ne "0" ] ; then
229        if $allow_error ; then
230            echo "Ignored 'applications/filter/$filter' because it does not compile on my debian machine"
231            cd ../..
232            continue
233        fi
234        echo "${RED}!!!!!! ERROR compiling  filter/${filter} ${NORMAL}"
235        exit -1
236    fi
237    cd ../..
238    cp filter/${filter}/${filter} ${bin_path}
239done
240
241# ------------------------------------------------------------------
242# Export
243# As soon it compiles here on my debian machine
244# i will remove the excludes
245for export in `ls export/*/Makefile| sed 's,/Makefile,,;s,export/,,'` ; do 
246    allow_error=false
247    if echo $export | grep -q -e osmgarminmap -e osm2shp -e osmgoogleearth; then
248        allow_error=true
249    fi
250
251    echo "${BLUE}----------> applications/utils/export/${export}${NORMAL}"
252    cd export/${export}  || exit -1
253
254    if [ -s "Makefile.$export" ] ;then
255        custom_makefile=" -f Makefile.$export"
256    else
257        custom_makefile=''
258    fi
259
260    make $custom_makefile clean >build.log 2>build.err
261    make $custom_makefile >>build.log 2>>build.err
262    if [ "$?" -ne "0" ] ; then
263        if $allow_error ; then
264            echo "Ignored 'applications/export/$export' because it does not compile on my debian machine"
265            cd ../..
266            continue
267        fi
268        echo "${RED}!!!!!! ERROR compiling  export/${export} ${NORMAL}"
269        exit -1
270    fi
271    cd ../..
272    cp export/${export}/${export} ${bin_path}
273
274    case ${export} in
275        osm2pgsql) 
276            cp export/osm2pgsql/default.style ${share_path}/default.style
277            if [ "$?" -ne "0" ] ; then
278                echo "${RED}!!!!!! ERROR osm2pgsql/default.style no copied ${NORMAL}"
279                exit -1
280            fi
281            ;;
282    esac
283done
284
285# ------------------------------------------------------------------
286if true ; then
287    echo "${BLUE}----------> applications/utils/color255${NORMAL}"
288    cd color255 || exit -1
289    make clean >build.log 2>build.err
290    make >>build.log 2>>build.err
291    if [ "$?" -ne "0" ] ; then
292        echo "${RED}!!!!!! ERROR compiling color255 ${NORMAL}"
293        exit -1
294    fi
295    cd ..
296    cp color255/color255 ${bin_path}
297fi
298
299
300# ------------------------------------------------------------------
301if true; then
302    echo "${BLUE}----------> applications/planet.osm/C/UTF8Sanitizer${NORMAL}${NORMAL}"
303    cd planet.osm/C/  || exit -1
304    make clean >build.log 2>build.err
305    make >>build.log 2>>build.err
306    if [ "$?" -ne "0" ] ; then
307        echo "${RED}!!!!!! ERROR compiling color255 ${NORMAL}"
308        exit -1
309    fi
310    cd ../..
311    cp planet.osm/C/UTF8Sanitizer ${bin_path} || exit -1
312fi
313
314# ------------------------------------------------------------------
315echo "${BLUE}----------> applications/utils/perl_lib Copy Perl libraries${NORMAL}${NORMAL}"
316find perl_lib/ -name "*.pm" | while read src_fn ; do 
317    dst_fn="$perl_path/${src_fn#perl_lib/}"
318    dst_dir=`dirname "$dst_fn"`
319    test -d "$dst_dir" || mkdir -p "$dst_dir"
320    cp "$src_fn" "$dst_fn"
321done
322
323echo "${BLUE}----------> applications/utils Copy Perl Binaries${NORMAL}${NORMAL}"
324find ./ -name "*.pl" | while read src_fn ; do 
325    dst_fn="$bin_path/${src_fn##*/}"
326    filename="`basename $src_fn`"
327    dst_fn="${dst_fn/.pl}"
328    if ! echo $dst_fn | grep -e osm ; then
329        dst_fn="`dirname ${dst_fn}`/osm-`basename ${dst_fn}`"
330    fi
331    man1_fn="$man1_path/${filename%.pl}.1"
332    if head -1 "$src_fn" | grep -q -e '^#! */usr/bin/perl' ; then
333        cp "$src_fn" "$dst_fn"
334    else
335        echo "${RED}WARNING!!! Perl Hash Bang is missing at File '$src_fn'${NORMAL}"
336        echo "           I'm not adding this File to the debian Package"
337        echo "First Line: `head -1 $src_fn`"
338    fi
339
340    # ----- Try to create man Pages
341    if perldoc "$src_fn" >/dev/null 2>&1 ; then
342        echo "Create Man Page from pod '$man1_fn'"
343        pod2man $src_fn >"$man1_fn"
344    else
345        if grep -q -e "--man" "$src_fn"; then
346            echo "Create Man Page '$man1_fn'"
347            perl $src_fn --man >"$man1_fn"
348        else
349            if grep -q -e "--help" "$src_fn"; then
350                echo "Create Man Page from Help '$man1_fn'"
351                perl $src_fn --help >"$man1_fn"
352            else
353                echo "!!!! No idea how to create Man Page for $src_fn"
354            fi
355        fi
356    fi
357done
358
359# --------------------------------------------
360echo "${BLUE}----------> applications/utils Copy Python Binaries${NORMAL}"
361find ./ -name "*.py" | while read src_fn ; do 
362    dst_fn="$bin_path/${src_fn##*/}"
363    dst_fn="${dst_fn/.py}"
364    if head -1 "$src_fn" | grep -q -e '^#! */usr/bin/python' -e '^#!/opt/python-2_5/bin/python' -e '^#!/usr/bin/env python'; then
365        cp "$src_fn" "$dst_fn"
366    else
367        if head -1 "$src_fn" | grep -q -e '^#!/opt/python-2_5/bin/python' -e '^#!/usr/bin/env python'; then
368            (echo '#!/usr/bin/python2.5'; cat "$src_fn") >"$dst_fn"
369        else
370            echo "${RED}WARNING!!! Python Hash Bang is missing at File '$src_fn'${NORMAL}"
371            echo "           I'm not adding this File to the debian Package"
372            echo "           First Line: `head -1 $src_fn`"
373        fi
374    fi
375done
376
377
378#########################################################
379# Mapnik installation tool
380#########################################################
381echo "${BLUE}----------> Mapnik${NORMAL}"
382cp export/osm2pgsql/mapnik-osm-updater.sh "$bin_path"
383cp export/osm2pgsql/900913.sql "$bin_path"
384cp export/osm2pgsql/default.style  "$bin_path"
385
386
387##################################################################
388# XXX
389# For later:
390# Add java tools, but for these a build.xml with a target jar or similar would be best
Note: See TracBrowser for help on using the repository browser.