setup.sh 5.41 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

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

# '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
65
    echo "Usage: $progname [OPTION] destination_path"
66
    echo ""
François Fortin's avatar
François Fortin committed
67
    echo "-v  : Verbose"
68
69
70
71
72
73
    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
74
fi
75
76


77
while getopts "v" Option
78
79
do
  case $Option in
François Fortin's avatar
François Fortin committed
80
    v     ) sVerbose=-v;;
81
    *     ) echo ""
François Fortin's avatar
François Fortin committed
82
            echo "Usage: $progname [OPTION] destination_path"
83
            echo ""
François Fortin's avatar
François Fortin committed
84
	    echo "-v  : Verbose"
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
            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

100
101
102
#remove unnecessary slashes
destination_path=$(echo ${destination_path} | sed s://*:/:g)

103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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

François Fortin's avatar
François Fortin committed
118
119
mkdir -p $destination_path/usr/share/metro/model/
mkdir -p $destination_path/usr/lib/metro/
120
121
122
123
124
125
126

echo "* Building physic model..."
cd src/model
../../scripts/do_macadam clean
../../scripts/do_macadam $destination_path
cd $installation_dir

127
echo ""
François Fortin's avatar
François Fortin committed
128

129
130
131
132
133
134
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
135
136
137
138
139
140
141
142
143
144
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

145
mkdir -p $destination_path/usr/share/doc/metro/
146
echo "* Copying METRo doc files to: "$destination_path/usr/share/doc/metro
147
cp $sVerbose INSTALL LICENSE README.md README.devel $destination_path/usr/share/doc/metro/
148

François Fortin's avatar
François Fortin committed
149
150
echo "* Creating METRo log directory: "$destination_path/var/log
mkdir -p $destination_path/var/log
151
152
153

cd $installation_dir

154
mkdir -p $destination_path/usr/bin
François Fortin's avatar
François Fortin committed
155
156
echo "* Make link to METRo executable:"
echo "  $destination_path/usr/bin/metro -> $destination_path/usr/share/metro/metro.py"
157
ln -sf ../share/metro/metro.py $destination_path/usr/bin/metro
158
159
160
161
162
163
164

echo ""
echo "---------------------------------------------------"
echo "METRo successfully installed in '$destination_path'"
echo "---------------------------------------------------"
echo ""
echo "* Installation done *"
François Fortin's avatar
François Fortin committed
165
echo ""
166
echo "To test the installation of METRo"
François Fortin's avatar
François Fortin committed
167
168
echo "---------------------------------"
echo "Go into the METRo directory:"
169
echo " 'cd $destination_path/usr/bin/'"
François Fortin's avatar
François Fortin committed
170
echo "Launch METRo selftest:"
171
echo " 'python3 metro --selftest'"
François Fortin's avatar
François Fortin committed
172
echo "Compare the files:"
173
174
echo " 'diff --ignore-matching-lines='.*<production-date>.*</production-date>' ../share/metro/data/selftest/roadcast.xml ../share/metro/data/selftest/roadcast_reference.xml'"
echo "There shouldn't be any difference" 
François Fortin's avatar
François Fortin committed
175