This repository has been archived by the owner on Jan 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
package_pmwatch.sh
executable file
·308 lines (276 loc) · 7.97 KB
/
package_pmwatch.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!/bin/bash
# MIT License
#
# Copyright (C) 2017 - 2019 Intel Corporation. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
PWD="pwd"
CWD=`${PWD}`
print_usage_and_exit()
{
echo "Usage: ./package_pmwatch.sh M=<major_number> m=<minor_number> u=<update_num> os=<linux|esxi> [-r]"
echo "Option:"
echo " -r removes the package directory after tarball creation"
echo
echo "Always run this script at the base directory."
exit $1
}
if [ $# = 0 ] ; then
print_usage_and_exit 0
fi
OS=
remove_package_dir=
while [ $# -gt 0 ] ; do
case "$1" in
--help | -h)
print_usage_and_exit 0
;;
M=*)
MAJOR_VERSION=`echo $1 | sed s?^M=??g`
if [[ ! ${MAJOR_VERSION} =~ ^-?[0-9]+$ ]] ; then
echo "Invalid argument $1! Use integer"
exit
fi
;;
m=*)
MINOR_VERSION=`echo $1 | sed s?^m=??g`
if [[ ! ${MINOR_VERSION} =~ ^-?[0-9]+$ ]] ; then
echo "Invalid argument $1! Use integer"
exit
fi
;;
u=*)
UPDATE_NUM=`echo $1 | sed s?^u=??g`
if [[ ! ${UPDATE_NUM} =~ ^-?[0-9]+$ ]] ; then
echo "Invalid argument $1! Use integer"
exit
fi
;;
os=*)
OS=`echo $1 | sed s?^os=??g`
if [[ ${OS} != "esxi" && ${OS} != "linux" ]] ; then
echo ""
echo "Invalid OS!"
print_usage_and_exit
fi
;;
-r)
remove_package_dir=1
;;
*)
echo ""
echo "Invalid option: \"$1\""
print_usage_and_exit 1
;;
esac
shift
done
TOOL_NAME="pmwatch"
PACKAGE_NAME="${TOOL_NAME}_${MAJOR_VERSION}.${MINOR_VERSION}.${UPDATE_NUM}"
PKG="package"
OUTER_PACKAGE_NAME="${PACKAGE_NAME}_${OS}_${PKG}"
PACKAGE_DIR="${CWD}/${PACKAGE_NAME}"
OUTER_PACKAGE_DIR="${CWD}/${OUTER_PACKAGE_NAME}"
if [[ ${OS} == "esxi" ]] ; then
DIR_EXT="esxi"
fi
# setting up path
PMW_SCRIPTS_DIR="scripts"
PMW_DOCS_DIR="docs"
PMW_SCRIPTS_PATH="${CWD}/${PMW_SCRIPTS_DIR}"
PMW_DOCS_PATH="${CWD}/${PMW_DOCS_DIR}"
BIN_DIR="${CWD}/bin64"
LIB_DIR="${CWD}/lib64"
INCLUDE_DIR="${CWD}/include"
# scripts
# pmw_vars
PMW_VARS="pmw_vars.sh"
if [[ ${OS} == "esxi" ]] ; then
PMW_VARS="${DIR_EXT}/pmw_vars.sh"
fi
PMW_VARS_PATH="${PMW_SCRIPTS_PATH}/${PMW_VARS}"
# installer
INSTALL_SCRIPT="install-pmw"
if [[ ${OS} == "esxi" ]] ; then
INSTALL_SCRIPT="${DIR_EXT}/install-pmw"
fi
INSTALL_SCRIPT_PATH="${PMW_SCRIPTS_PATH}/${INSTALL_SCRIPT}"
# docs
README="README"
if [[ ${OS} == "esxi" ]] ; then
README="${DIR_EXT}/README"
fi
PMW_USER_GUIDE="PMWatch_User_Guide.pdf"
README_INSTALL="README_INSTALL"
if [[ ${OS} == "esxi" ]] ; then
README_INSTALL="${DIR_EXT}/README_INSTALL"
fi
README_PATH="${PMW_DOCS_PATH}/${README}"
README_INSTALL_PATH="${PMW_DOCS_PATH}/${README_INSTALL}"
PMW_USER_GUIDE_PATH="${PMW_DOCS_PATH}/${PMW_USER_GUIDE}"
# bin
PMW_BIN1_PATH="${CWD}/pmwatch"
PMW_BIN2_PATH="${CWD}/src/pmwatch-stop"
# libs
PMW_LIB_BASE_PATH="${CWD}/.libs"
PMW_LIB1_NAME="libpmwapi.so*"
PMW_LIB2_NAME="libpmwcollect.so*"
PMW_LIB1_PATH="${PMW_LIB_BASE_PATH}/${PMW_LIB1_NAME}"
PMW_LIB2_PATH="${PMW_LIB_BASE_PATH}/${PMW_LIB2_NAME}"
# header files
PMW_INCLUDE_BASE_PATH="${CWD}/src/inc"
PMW_HEADER_FILE1="pmw_api.h"
PMW_HEADER_FILE2="pmw_struct.h"
PMW_INCLUDE1_PATH="${PMW_INCLUDE_BASE_PATH}/${PMW_HEADER_FILE1}"
PMW_INCLUDE2_PATH="${PMW_INCLUDE_BASE_PATH}/${PMW_HEADER_FILE2}"
# tar_name
TAR_EXT=".tar.bz2"
TAR_NAME="${PACKAGE_NAME}${TAR_EXT}"
TAR_PATH="${CWD}/${TAR_NAME}"
OUTER_TAR_NAME="${OUTER_PACKAGE_NAME}${TAR_EXT}"
OUTER_TAR_PATH="${CWD}/${OUTER_TAR_NAME}"
mkdir ${PACKAGE_DIR}
if [ $? -ne 0 ] ; then
echo "Package directory not successfully created!"
exit
fi
if [[ ! -d ${BIN_DIR} ]]; then
mkdir ${BIN_DIR}
if [[ $? -ne 0 ]] ; then
echo "Package creation not successful; mkdir ${BIN_DIR}!"
echo
exit 1
fi
fi
cp -a {${PMW_BIN1_PATH},${PMW_BIN2_PATH}} ${BIN_DIR}
if [ $? -ne 0 ] ; then
echo "Package creation not successful; ${BIN_DIR} copy!"
echo
exit 1
fi
if [[ ! -d ${LIB_DIR} ]]; then
mkdir ${LIB_DIR}
if [[ $? -ne 0 ]] ; then
echo "Package creation not successful; mkdir ${LIB_DIR}!"
echo
exit 1
fi
fi
cp -a ${PMW_LIB1_PATH} ${LIB_DIR}
if [ $? -ne 0 ] ; then
echo "Package creation not successful; ${LIB_DIR} copy!"
echo
exit 1
fi
cp -a ${PMW_LIB2_PATH} ${LIB_DIR}
if [ $? -ne 0 ] ; then
echo "Package creation not successful; ${LIB_DIR} copy!"
echo
exit 1
fi
if [[ ! -d ${INCLUDE_DIR} ]]; then
mkdir ${INCLUDE_DIR}
if [[ $? -ne 0 ]] ; then
echo "Package creation not successful; mkdir ${LIB_DIR}!"
echo
exit 1
fi
fi
cp -a ${PMW_INCLUDE1_PATH} ${INCLUDE_DIR}
if [ $? -ne 0 ] ; then
echo "Package creation not successful; ${INCLUDE_DIR} copy!"
echo
exit 1
fi
cp -a ${PMW_INCLUDE2_PATH} ${INCLUDE_DIR}
if [ $? -ne 0 ] ; then
echo "Package creation not successful; ${INCLUDE_DIR} copy!"
echo
exit 1
fi
mv {${BIN_DIR},${LIB_DIR},${INCLUDE_DIR}} ${PACKAGE_DIR}
if [ $? -ne 0 ] ; then
echo "Package creation not successful; intial copy!"
echo
if [ -d ${PACKAGE_DIR} ] ; then
rm -rf ${PACKAGE_DIR}
fi
exit 1
fi
cp -r {${PMW_VARS_PATH},${README_PATH},${PMW_USER_GUIDE_PATH}} ${PACKAGE_DIR}
if [ $? -ne 0 ] ; then
echo "Package creation not successful; intial copy!"
echo
if [ -d ${PACKAGE_DIR} ] ; then
rm -rf ${PACKAGE_DIR}
fi
exit 1
fi
echo "Package directory created successfully."
res=`tar cvfj ${TAR_PATH} ${PACKAGE_NAME}`
if [ $? -ne 0 ] ; then
echo "Core package tar ball cannot be created successfully."
echo
if [ -d ${PACKAGE_DIR} ] ; then
rm -rf ${PACKAGE_DIR}
fi
exit 1
else
echo "Core package tar ball created successfully."
fi
mkdir ${OUTER_PACKAGE_DIR}
if [ $? -ne 0 ] ; then
echo "Unable to create ${OUTER_PACKAGE_DIR}! Exiting..."
echo
rm -rf ${PACKAGE_DIR} ${TAR_PATH}
if [ -d ${OUTER_PACKAGE_DIR} ] ; then
rm -rf ${OUTER_PACKAGE_DIR}
fi
exit 1
fi
cp {${TAR_PATH},${README_INSTALL_PATH},${INSTALL_SCRIPT_PATH}} ${OUTER_PACKAGE_DIR}
if [ $? -ne 0 ] ; then
echo "Unable to package ${OUTER_PACKAGE_NAME}; copy failed! Exiting..."
echo
rm -rf ${PACKAGE_DIR} ${TAR_PATH}
if [ -d ${OUTER_PACKAGE_DIR} ] ; then
rm -rf ${OUTER_PACKAGE_DIR}
fi
exit 1
fi
res=`tar cvfj ${OUTER_TAR_PATH} ${OUTER_PACKAGE_NAME}`
if [ $? -ne 0 ] ; then
echo "Final package tar ball cannot be created successfully."
echo
rm -rf ${PACKAGE_DIR} ${TAR_PATH} ${OUTER_PACKAGE_DIR}
exit 1
else
echo "Final package tar ball created successfully."
fi
if [[ -n "${remove_package_dir}" ]] ; then
rm -rf ${PACKAGE_DIR} ${OUTER_PACKAGE_DIR} ${TAR_PATH}
if [ $? -ne 0 ] ; then
echo "${PACKAGE_NAME}, ${OUTER_PACKAGE_NAME} and ${TAR_NAME} were not removed."
echo
exit 1
else
echo "${PACKAGE_NAME}, ${OUTER_PACKAGE_NAME} and ${TAR_NAME} were removed."
echo
fi
fi