setup.sh 7.64 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
#
#
# 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
41
42
# Making sure we are in the directory where the script resides
cd `dirname $0`
43
44
45
46
installation_dir=`pwd`

metro_dir=metro

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

# '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
66
    echo "Usage: $progname [OPTION] destination_path"
67
68
    echo ""
    echo "-c  : Will compile the METRo physic model instead of using"
François Fortin's avatar
François Fortin committed
69
    echo "      the provided binary. Need gfortran compiler."
70
71
    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
72
73
    echo ""
    echo "-v  : Verbose"
74
75
76
77
78
79
    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
80
fi
81
82


François Fortin's avatar
François Fortin committed
83
while getopts "cv" Option
84
85
86
do
  case $Option in
    c     ) bCompile=1;;
François Fortin's avatar
François Fortin committed
87
    v     ) sVerbose=-v;;
88
    *     ) echo ""
François Fortin's avatar
François Fortin committed
89
            echo "Usage: $progname [OPTION] destination_path"
90
91
            echo ""
            echo "-c  : Will compile the METRo physic model instead of using"
92
            echo "      the provided binary. Need gfortran compiler."
93
94
            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
95
96
 	    echo ""
	    echo "-v  : Verbose"
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
124
125
126
            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

127
128
129
130
131
132
133
134
135
136
# 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
137
echo ""
138

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

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

195
mkdir -p $destination_path/usr/share/doc/metro/
François Fortin's avatar
François Fortin committed
196
echo "* Copying METRo doc files to: "$destination_path/usr/share/doc/metro/
197
cp $sVerbose INSTALL LICENSE README.md README.devel $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

205
mkdir -p $destination_path/usr/bin
François Fortin's avatar
François Fortin committed
206
207
echo "* Make link to METRo executable:"
echo "  $destination_path/usr/bin/metro -> $destination_path/usr/share/metro/metro.py"
208
ln -sf ../share/metro/metro.py $destination_path/usr/bin/metro
209
210
211
212
213
214
215

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