This repository has been archived by the owner on May 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
executable file
·218 lines (178 loc) · 6.72 KB
/
install.sh
1
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/bash
# Copyright (c) 2016, RTE (http://www.rte-france.com)
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
sourceDir=$(dirname $(readlink -f $0))
## install default settings
###############################################################################
ipst_prefix=$HOME/itesla
ipst_package_version=` mvn -f "$sourceDir/pom.xml" org.apache.maven.plugins:maven-help-plugin:evaluate -Dexpression=project.version | grep -v "Download" | grep -v "\["`
ipst_package_name=ipst-entsoe-$ipst_package_version
ipst_package_type=zip
# Targets
ipst_clean=false
ipst_compile=false
ipst_docs=false
ipst_package=false
ipst_install=false
## read settings from configuration file
###############################################################################
settings="$sourceDir/install.cfg"
if [ -f "${settings}" ]; then
source "${settings}"
fi
## Usage/Help
###############################################################################
cmd=$0
usage() {
echo "usage: $cmd [options] [target...]"
echo ""
echo "Available targets:"
echo " clean Clean iPST modules"
echo " compile Compile iPST modules"
echo " package Compile iPST modules and create a distributable package"
echo " install Compile iPST modules and install it (default target)"
echo " help Display this help"
echo " docs Generate the documentation (Javadoc)"
echo ""
echo "iPST options:"
echo " --help Display this help"
echo " --prefix Set the installation directory (default is $HOME/itesla)"
echo " --package-type Set the package format. The supported formats are zip, tar, tar.gz and tar.bz2 (default is zip)"
echo ""
}
## Write Settings functions
###############################################################################
writeSetting() {
if [[ $# -lt 2 || $# -gt 3 ]]; then
echo "WARNING: writeSetting <setting> <value> [comment (true|false)]"
exit 1
fi
SETTING=$1
VALUE=$2
if [[ $# -eq 3 ]]; then
echo -ne "# "
fi
echo "${SETTING}=${VALUE}"
return 0
}
writeComment() {
echo "# $*"
return 0
}
writeEmptyLine() {
echo ""
return 0
}
writeSettings() {
writeComment " -- iPST global options --"
writeSetting "ipst_prefix" ${ipst_prefix}
writeSetting "ipst_package_type" ${ipst_package_type}
return 0
}
## Build Java Modules
###############################################################################
ipst_java()
{
if [[ $ipst_clean = true || $ipst_compile = true || $ipst_docs = true ]]; then
echo "** Building iPST Java modules"
mvn_options=""
[ $ipst_clean = true ] && mvn_options="$mvn_options clean"
[ $ipst_compile = true ] && mvn_options="$mvn_options install"
if [ ! -z "$mvn_options" ]; then
mvn -f "$sourceDir/pom.xml" $mvn_options || exit $?
fi
if [ $ipst_docs = true ]; then
echo "**** Generating Javadoc documentation"
mvn -f "$sourceDir/pom.xml" javadoc:javadoc || exit $?
mvn -f "$sourceDir/distribution-entsoe/pom.xml" install || exit $?
fi
fi
}
## Package iPST
###############################################################################
ipst_package()
{
if [ $ipst_package = true ]; then
echo "** Packaging iPST"
case "$ipst_package_type" in
zip)
[ -f "${ipst_package_name}.zip" ] && rm -f "${ipst_package_name}.zip"
$(cd "$sourceDir/distribution-entsoe/target/distribution-entsoe-${ipst_package_version}-full" && zip -rq "$sourceDir/${ipst_package_name}.zip" "itesla")
zip -qT "${ipst_package_name}.zip" > /dev/null 2>&1 || exit $?
;;
tar)
[ -f "${ipst_package_name}.tar" ] && rm -f "${ipst_package_name}.tar"
tar -cf "${ipst_package_name}.tar" -C "$sourceDir/distribution-entsoe/target/distribution-entsoe-${ipst_package_version}-full" . || exit $?
;;
tar.gz | tgz)
[ -f "${ipst_package_name}.tar.gz" ] && rm -f "${ipst_package_name}.tar.gz"
[ -f "${ipst_package_name}.tgz" ] && rm -f "${ipst_package_name}.tgz"
tar -czf "${ipst_package_name}.tar.gz" -C "$sourceDir/distribution-entsoe/target/distribution-entsoe-${ipst_package_version}-full" . || exit $?
;;
tar.bz2 | tbz)
[ -f "${ipst_package_name}.tar.bz2" ] && rm -f "${ipst_package_name}.tar.bz2"
[ -f "${ipst_package_name}.tbz" ] && rm -f "${ipst_package_name}.tbz"
tar -cjf "${ipst_package_name}.tar.bz2" -C "$sourceDir/distribution-entsoe/target/distribution-entsoe-${ipst_package_version}-full" . || exit $?
;;
*)
echo "Invalid package format: zip, tar, tar.gz, tar.bz2 are supported."
exit 1;
;;
esac
fi
}
## Install iPST
###############################################################################
ipst_install()
{
if [ $ipst_install = true ]; then
echo "** Installing iPST"
echo "**** Copying files"
mkdir -p "$ipst_prefix" || exit $?
cp -Rp "$sourceDir/distribution-entsoe/target/distribution-entsoe-${ipst_package_version}-full/itesla"/* "$ipst_prefix" || exit $?
fi
}
## Parse command line
###############################################################################
ipst_options="prefix:,package-type:"
opts=`getopt -o '' --long "help,$ipst_options" -n 'install.sh' -- "$@"`
eval set -- "$opts"
while true; do
case "$1" in
# iPST options
--prefix) ipst_prefix=$2 ; shift 2 ;;
--package-type) ipst_package_type=$2 ; shift 2 ;;
# Help
--help) usage ; exit 0 ;;
--) shift ; break ;;
*) usage ; exit 1 ;;
esac
done
if [ $# -ne 0 ]; then
for command in $*; do
case "$command" in
clean) ipst_clean=true ;;
compile) ipst_compile=true ;;
docs) ipst_docs=true ;;
package) ipst_package=true ; ipst_compile=true ;;
install) ipst_install=true ; ipst_compile=true ;;
help) usage; exit 0 ;;
*) usage ; exit 1 ;;
esac
done
else
ipst_compile=true
ipst_install=true
fi
## Build iPST platform
###############################################################################
# Build Java modules
ipst_java
# Package iPST
ipst_package
# Install iPST
ipst_install
# Save settings
writeSettings > "${settings}"