setup.sh 7.24 KB
Newer Older
1
#!/bin/bash
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#
# METRo : Model of the Environment and Temperature of Roads
# METRo is Free and is proudly provided by the Government of Canada
# Copyright (C) 2006 Environment Canada

#  Questions or bugs report: metro@ec.gc.ca
#  METRo repository: https://gna.org/projects/metro/
#  Documentation: http://documentation.wikia.com/wiki/METRo
#
#
# Code contributed by:
#  Francois Fortin - Canadian meteorological center
#
#  $LastChangedDate$
#  $LastChangedRevision$
#
########################################################################
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

# SETUP TRAP
ERRMSG="\nERR - METRo Install - $progname : Script terminated due to
error.  Correct error and restart.\n\n"

trap 'echo -e $ERRMSG; exit 1' ERR

progname=`basename $0`

François Fortin's avatar
François Fortin committed
42
43
# Making sure we are in the directory where the script resides
cd `dirname $0`
44
45
46
47
48
installation_dir=`pwd`

metro_dir=metro

bCompile=0
François Fortin's avatar
François Fortin committed
49
sVerbose=""
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

# 'getopts' processes command line args to script.

# Usage: scriptname -options
# Note: dash (-) necessary

# Try invoking this script with
# 'scriptname -mn'
# 'scriptname -oq qOption'
# (qOption can be some arbitrary string.)

OPTERROR=33

if [ -z $1 ]
# Exit and complain if no argument(s) given.
then
    echo ""
François Fortin's avatar
François Fortin committed
67
    echo "Usage: $progname [OPTION] destination_path"
68
69
    echo ""
    echo "-c  : Will compile the METRo physic model instead of using"
François Fortin's avatar
François Fortin committed
70
71
72
    echo "      the provided binary. Need gfortran compiler."
    echo ""
    echo "-v  : Verbose"
73
74
75
76
77
78
79
80
81
    echo ""
    echo "The metro directory will be created in the destination_path"
    echo ""
    echo "Ex: ./setup.sh /usr/local/"
    echo "    ./setup.sh /home/user/program/"
    exit 0
fi  


François Fortin's avatar
François Fortin committed
82
while getopts "cv" Option
83
84
85
do
  case $Option in
    c     ) bCompile=1;;
François Fortin's avatar
François Fortin committed
86
    v     ) sVerbose=-v;;
87
    *     ) echo ""
François Fortin's avatar
François Fortin committed
88
            echo "Usage: $progname [OPTION] destination_path"
89
90
            echo ""
            echo "-c  : Will compile the METRo physic model instead of using"
François Fortin's avatar
François Fortin committed
91
92
93
            echo "      the provided binary. Need gfortran compiler." 
 	    echo ""
	    echo "-v  : Verbose"
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
            echo ""
            echo "The metro directory will be created in the destination_path"
            echo ""
            echo "Ex: ./setup.sh /usr/local/"
            echo "    ./setup.sh /home/user/program/"
            exit $OPTERROR;;
  esac
done

shift $(($OPTIND - 1))
# Decrements the argument pointer
# so it points to next argument.

destination_path=$1/$metro_dir

echo "* Starting METRo Installation *"
echo ""

if [ -d $destination_path ]; then
    echo "Warning target directory: $destination_path already exist."
    echo "Installing a different version of METRo over an existing one"
    echo "is not recommanded."
    echo "Do you want to continue? [y|n]"
    read answer
    if [ ! "$answer" = y ]; then
        echo "Exiting..."
        exit 0
    fi
fi

124
125
126
127
128
129
130
131
132
133
# check if gfortran library exist on the target system
echo "* Checking for libgfortran.so.1"
if ! locate libgfortran.so.1; then
    echo "----------------------------------------------------------"
    echo "WARNING!"
    echo "Could not find gfortran library on your system."
    echo "METRo model will be recompiled."
    echo "----------------------------------------------------------"
    bCompile=1
fi
François Fortin's avatar
François Fortin committed
134
echo ""
135
    
François Fortin's avatar
François Fortin committed
136
137
mkdir -p $destination_path/usr/share/metro/model/
mkdir -p $destination_path/usr/lib/metro/
138
if [ $bCompile == 1 ]; then
François Fortin's avatar
François Fortin committed
139
    echo "* Building physic model..."
140
141
142
143
    if [ ! -n "$PYTHON_INCLUDE" ] ; then
        echo "----------------------------------------------------------"
        echo "WARNING!"
        echo "No python path defined. setup.sh may not be able"
144
        echo "to properly install METRo."
145
146
147
148
        echo "Please set environment variable PYTHON_INCLUDE to your"
        echo "python include directory."
        echo "Ex: export PYTHON_INCLUDE=\"/usr/local/include/python2.3\""
        echo "----------------------------------------------------------"
149
	echo ""
150
151
152
153
154
155
156
    fi
    cd src/model
    ../../scripts/do_macadam clean
    ../../scripts/do_macadam
    cd $installation_dir
else
    echo "* Use provided binary for physic model"
François Fortin's avatar
François Fortin committed
157
158
    cp $sVerbose src/model/macadam.py.prebuilt $destination_path/usr/share/metro/model/macadam.py
    cp $sVerbose src/model/_macadam.so.prebuilt $destination_path/usr/lib/metro/_macadam.so
159
160
fi
echo ""
François Fortin's avatar
François Fortin committed
161

162
163
164
165
166
167
echo "* Creating destination directory: "$destination_path
mkdir -p $destination_path
echo ""
echo "* Copying METRo files..."
echo ""

François Fortin's avatar
François Fortin committed
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
echo  "* Copying METRo data files to: "$destination_path/usr
find usr -not -regex ".*\.po" | cpio -pmud --quiet $sVerbose $destination_path/

echo "* Copying METRo programs files to: "$destination_path/usr/share/metro
cp $sVerbose src/frontend/*.py $destination_path/usr/share/metro
cp $sVerbose -r src/frontend/data_module $destination_path/usr/share/metro
cp $sVerbose -r src/frontend/executable_module $destination_path/usr/share/metro
cp $sVerbose -r src/frontend/external_lib $destination_path/usr/share/metro
cp $sVerbose -r src/frontend/toolbox $destination_path/usr/share/metro

#echo "* Copying METRo model python file to: "$destination_path/usr/share/metro/model
#if [ $bCompile == 1 ]; then
#    cp $sVerbose src/model/macadam.py          $destination_path/usr/share/metro/model/
#else
#    cp $sVerbose src/model/macadam.py.prebuilt $destination_path/usr/share/metro/model/macadam.py
#fi

#echo "* Copying METRo model to: "$destination_path/usr/lib/metro
#if [ $bCompile == 1 ]; then
#    cp $sVerbose src/model/_macadam.so $destination_path/usr/lib/metro/
#else
#    cp $sVerbose src/model/_macadam.so.prebuilt $destination_path/usr/lib/metro/_macadam.so
#fi

echo "* Copying METRo doc files to: "$destination_path/usr/share/doc/metro/
cp $sVerbose INSTALL LICENSE README $destination_path/usr/share/doc/metro/
194

François Fortin's avatar
François Fortin committed
195
196
echo "* Creating METRo log directory: "$destination_path/var/log
mkdir -p $destination_path/var/log
197
198
199
200


cd $installation_dir

François Fortin's avatar
François Fortin committed
201
202
203
echo "* Make link to METRo executable:"
echo "  $destination_path/usr/bin/metro -> $destination_path/usr/share/metro/metro.py"
ln -sf ../share/metro/metro.py $destination_path/usr/bin/metro  
204
205
206
207
208
209
210

echo ""
echo "---------------------------------------------------"
echo "METRo successfully installed in '$destination_path'"
echo "---------------------------------------------------"
echo ""
echo "* Installation done *"
François Fortin's avatar
François Fortin committed
211
echo ""
212
echo "To test the installation of METRo"
François Fortin's avatar
François Fortin committed
213
214
echo "---------------------------------"
echo "Go into the METRo directory:"
François Fortin's avatar
François Fortin committed
215
echo " 'cd $destination_path/usr/bin/'" 
François Fortin's avatar
François Fortin committed
216
217
218
echo "Launch METRo selftest:"
echo " 'python metro --selftest'"
echo "Compare the files:"
François Fortin's avatar
François Fortin committed
219
echo " 'diff ../share/metro/data/roadcast/roadcast_selftest.xml ../share/metro/data/roadcast/roadcast_selftest_reference.xml'"
François Fortin's avatar
François Fortin committed
220
221
echo "They should be identical except for the production-date."