-
Notifications
You must be signed in to change notification settings - Fork 41
/
install.sh
executable file
·168 lines (138 loc) · 4.48 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
#!/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
###############################################################################
powsybl_prefix=$HOME/powsybl
powsybl_mvn=mvn
# Targets
powsybl_clean=false
powsybl_compile=false
powsybl_docs=false
powsybl_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 modules"
echo " compile Compile modules"
echo " install Compile modules and install it (default target)"
echo " help Display this help"
echo " docs Generate the documentation (Doxygen/Javadoc)"
echo ""
echo "Options:"
echo " --help Display this help"
echo " --prefix Set the installation directory (default is $HOME/powsybl)"
echo " --mvn Set the maven command to use (default is \"mvn\")"
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 " -- Global options --"
writeSetting "powsybl_prefix" ${powsybl_prefix}
writeSetting "powsybl_mvn" ${powsybl_mvn}
return 0
}
## Build Java Modules
###############################################################################
powsybl_java()
{
if [[ $powsybl_clean = true || $powsybl_compile = true || $powsybl_docs = true ]]; then
echo "** Building Java modules"
mvn_options=""
[ $powsybl_clean = true ] && mvn_options="$mvn_options clean"
[ $powsybl_compile = true ] && mvn_options="$mvn_options install"
if [ ! -z "$mvn_options" ]; then
"$powsybl_mvn" -f "$sourceDir/pom.xml" $mvn_options || exit $?
fi
if [ $powsybl_docs = true ]; then
echo "**** Generating Javadoc documentation"
"$powsybl_mvn" -f "$sourceDir/pom.xml" javadoc:aggregate || exit $?
"$powsybl_mvn" -f "$sourceDir/distribution-core/pom.xml" install || exit $?
fi
fi
}
## Install
###############################################################################
powsybl_install()
{
if [ $powsybl_install = true ]; then
echo "** Installing powsybl"
echo "**** Copying files"
mkdir -p "$powsybl_prefix" || exit $?
cp -Rp "$sourceDir/distribution-core/target/powsybl"/* "$powsybl_prefix" || exit $?
fi
}
## Parse command line
###############################################################################
powsybl_options="prefix:,mvn:"
opts=`getopt -o '' --long "help,$powsybl_options" -n 'install.sh' -- "$@"`
eval set -- "$opts"
while true; do
case "$1" in
# Options
--prefix) powsybl_prefix=$2 ; shift 2 ;;
--mvn) powsybl_mvn=$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) powsybl_clean=true ;;
compile) powsybl_compile=true ;;
docs) powsybl_docs=true ;;
install) powsybl_install=true ; powsybl_compile=true ;;
help) usage; exit 0 ;;
*) usage ; exit 1 ;;
esac
done
else
powsybl_compile=true
powsybl_install=true
fi
## Build platform
###############################################################################
# Build Java modules
powsybl_java
# Install
powsybl_install
# Save settings
writeSettings > "${settings}"