-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.sh
executable file
·206 lines (173 loc) · 5.46 KB
/
build.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
#!/bin/sh
_curDir=`pwd`
_build_script=$(basename "$0")
_repoTopDir=$(cd "$(dirname "$0")";pwd)
_num_of_opts="$#"
_cmd_opt_str="$@"
RC_JAVA_PLUGINS="aws azure cyclecloud google"
RC_SCRIPT_PLUGINS="ibmcloudgen2 openstack"
ALL_RC_PLUGSIN="$RC_JAVA_PLUGINS $RC_SCRIPT_PLUGINS"
#RC_TARGET_FILE="brel_root.rc_plugin.tar.gz"
RC_TARGET_FILE="brel_root.hf_providers_java_plugin.tar.gz"
__JAVA_TOOL="mvn"
__DO_BUILD=""
__DO_CLEAN=""
#--------------------------------------------------------
# Name: build_rc_usage
# Synopsis: build_rc_usage
# Description:
# Usage of build.sh
#--------------------------------------------------------
build_rc_usage ()
{
cat << BUILD_RC_USAGE
Usage: ${_build_script} [-b|--build] [--tool=mvn|ant]
${_build_script} -c|--clean [--tool=mvn|ant]
${_build_script} -h|--help
-b|--build: [Default] Build all Resource Connector plugins.
Create ${RC_TARGET_FILE}
You are required to specify JAVA_HOME and MAVEN_HOME(or ANT_HOME),
and add java and mvn(or ant) into your PATH env.
-c|--clean: Clean generated java class and jar files.
--tool: Specify the tool to compile java plugins, maven(default) or ant
-h: Print command usage and exit
BUILD_RC_USAGE
} # build_rc_usage
#--------------------------------------------------------
# Name: do_clean
# Synopsis: do_clean
# Description:
# Do cleanup of complied java class and jar files
#--------------------------------------------------------
do_clean()
{
cd $_repoTopDir
cd hostProviders
# clean java class and jar files
for PDIR in $RC_JAVA_PLUGINS; do
cd $PDIR
${__JAVA_TOOL} clean
rm -rf lib
cd -
done
cd $_repoTopDir
rm -rf resource_connector
rm -f $RC_TARGET_FILE
cd $_curDir
} # do_clean
#--------------------------------------------------------
# Name: build_rc_usage
# Synopsis: build_rc_usage
# Description:
# This function displays the usage of build.sh
#--------------------------------------------------------
build_rc ()
{
cd $_repoTopDir
cd hostProviders
# build jar files
for PDIR in $RC_JAVA_PLUGINS; do
cd $PDIR
if [[ "$__JAVA_TOOL" = "ant" ]]; then
ant clean
ant jar
else
mvn clean
mvn package
rm -rf lib
mv target/lib .
fi
cd -
done
cd $_repoTopDir
mkdir $_repoTopDir/resource_connector
# copy files
for PDIR in $ALL_RC_PLUGSIN; do
mkdir $_repoTopDir/resource_connector/$PDIR
# copy lib
if [[ -d $_repoTopDir/hostProviders/$PDIR/lib ]]; then
cp -rf $_repoTopDir/hostProviders/$PDIR/lib $_repoTopDir/resource_connector/$PDIR/lib
fi
# copy conf
cp -rf $_repoTopDir/hostProviders/$PDIR/conf/lsf $_repoTopDir/resource_connector/$PDIR/conf
# copy auentication file
_cred_file=$_repoTopDir/hostProviders/$PDIR/conf/credentials
if [[ -f $_cred_file ]]; then
cp $_cred_file $_repoTopDir/resource_connector/$PDIR/conf
fi
# copy scripts
cp -rf $_repoTopDir/hostProviders/$PDIR/scripts $_repoTopDir/resource_connector/$PDIR/scripts
# copy example_user_data.sh
_user_data_dir=$_repoTopDir/hostProviders/$PDIR/postprovision/lsf
if [[ -d $_user_data_dir ]]; then
cp $_user_data_dir/*.sh $_repoTopDir/resource_connector/$PDIR/scripts
fi
if [[ -d $_repoTopDir/resource_connector/$PDIR/lib/ ]]; then
chmod 755 $_repoTopDir/resource_connector/$PDIR/lib/*
fi
chmod 755 $_repoTopDir/resource_connector/$PDIR/scripts/*
chmod 644 $_repoTopDir/resource_connector/$PDIR/conf/*
done
cd $_repoTopDir
# copy specificial files
cp -rf $_repoTopDir/hostProviders/example_hostProviders.json $_repoTopDir/resource_connector/
cp -rf $_repoTopDir/policy $_repoTopDir/resource_connector/
mv $_repoTopDir/resource_connector/policy/example_policy_config.json $_repoTopDir/resource_connector
chmod 755 $_repoTopDir/resource_connector/policy/*.py
tar czvf $RC_TARGET_FILE resource_connector/
rm -rf resource_connector
cd $_curDir
} # build_rc()
################################################################################
################################################################################
#
# Main procedure begin from here
#
if [[ "$_num_of_opts" = "0" ]]; then
build_rc
exit 0
fi
for _opt in $_cmd_opt_str
do
case $_opt in
--tool=*)
__JAVA_TOOL=${_opt#*=}
if [[ "$__JAVA_TOOL" = "mvn" ]]; then
__JAVA_TOOL="mvn"
elif [[ "$__JAVA_TOOL" = "ant" ]]; then
__JAVA_TOOL="ant"
else
echo "The tool $__JAVA_TOOL is not supported. Use mvn as default."
__JAVA_TOOL="mvn"
fi
;;
--build|-b)
__DO_BUILD="Y"
;;
--clean|-c)
__DO_CLEAN="Y"
;;
--help|-h)
build_rc_usage
exit 0
;;
*)
echo " Command line option $_opt is not valid."
build_rc_usage
exit 1
;;
esac
done
# nothing specified but --tool, default do build
if [[ -z $__DO_CLEAN && -z $__DO_BUILD ]]; then
__DO_BUILD="Y"
fi
# Do cleanup
if [[ "$__DO_CLEAN" = "Y" ]]; then
do_clean
fi
# Do build
if [[ "$__DO_BUILD" = "Y" ]]; then
build_rc
fi
exit 0