setup.sh 7.54 KB
Newer Older
1
#!/bin/bash
2
3
4
#
# METRo : Model of the Environment and Temperature of Roads
# METRo is Free and is proudly provided by the Government of Canada
Miguel Tremblay's avatar
Miguel Tremblay committed
5
# Copyright (C) Her Majesty The Queen in Right of Canada, Environment Canada, 2006
6
7

#  Questions or bugs report: metro@ec.gc.ca
8
#  METRo repository: https://framagit.org/metroprojects/metro
9
#  Documentation: https://framagit.org/metroprojects/metro/wikis/home
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
#
#
# 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
installation_dir=`pwd`

metro_dir=metro

48
bCompile=1
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
    echo "      the provided binary. Need gfortran compiler."
71
72
    echo "      DEPRECATED, no longer do anything, setup.sh will"
    echo "      always compile the METRo physic model."
François Fortin's avatar
François Fortin committed
73
74
    echo ""
    echo "-v  : Verbose"
75
76
77
78
79
80
81
82
83
    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
84
while getopts "cv" Option
85
86
87
do
  case $Option in
    c     ) bCompile=1;;
François Fortin's avatar
François Fortin committed
88
    v     ) sVerbose=-v;;
89
    *     ) echo ""
François Fortin's avatar
François Fortin committed
90
            echo "Usage: $progname [OPTION] destination_path"
91
92
            echo ""
            echo "-c  : Will compile the METRo physic model instead of using"
François Fortin's avatar
François Fortin committed
93
            echo "      the provided binary. Need gfortran compiler." 
94
95
            echo "      DEPRECATED, no longer do anything, setup.sh will"
            echo "      always compile the METRo physic model."
François Fortin's avatar
François Fortin committed
96
97
 	    echo ""
	    echo "-v  : Verbose"
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
124
125
126
127
            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

128
129
130
131
132
133
134
135
136
137
# 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
138
echo ""
139
    
François Fortin's avatar
François Fortin committed
140
141
mkdir -p $destination_path/usr/share/metro/model/
mkdir -p $destination_path/usr/lib/metro/
142
if [ $bCompile == 1 ]; then
François Fortin's avatar
François Fortin committed
143
    echo "* Building physic model..."
144
145
146
147
    if [ ! -n "$PYTHON_INCLUDE" ] ; then
        echo "----------------------------------------------------------"
        echo "WARNING!"
        echo "No python path defined. setup.sh may not be able"
148
        echo "to properly install METRo."
149
150
151
152
        echo "Please set environment variable PYTHON_INCLUDE to your"
        echo "python include directory."
        echo "Ex: export PYTHON_INCLUDE=\"/usr/local/include/python2.3\""
        echo "----------------------------------------------------------"
153
	echo ""
154
155
156
157
158
    fi
    cd src/model
    ../../scripts/do_macadam clean
    ../../scripts/do_macadam
    cd $installation_dir
159
160
161
162
#else
#    echo "* Use provided binary for physic model"
#    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
163
164
fi
echo ""
François Fortin's avatar
François Fortin committed
165

166
167
168
169
170
171
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
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/
198

François Fortin's avatar
François Fortin committed
199
200
echo "* Creating METRo log directory: "$destination_path/var/log
mkdir -p $destination_path/var/log
201
202
203
204


cd $installation_dir

François Fortin's avatar
François Fortin committed
205
206
207
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  
208
209
210
211
212
213
214

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