-
Notifications
You must be signed in to change notification settings - Fork 1
/
dmserver-bundles.sh
executable file
·303 lines (276 loc) · 7.8 KB
/
dmserver-bundles.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
#!/bin/bash
###########################################################
#
# CLI tool to manage SpringSource dm Server OSGi bundles
# Version: 1.0.1
#
# License: MIT (see http://choosealicense.com/licenses/mit/)
# Author: Vladimir Lyubitelev
#
VERSION=1.0.1
SDMSERVER_URL=http://localhost:8080
BUNDLE_FILE=
BUNDLE_NAME=
BUNDLE_VERSION=
BUNDLE_TYPE=bundle
VERBOSE=false
# First parameter is always a command
COMMAND=$1
shift
if [ -z "${COMMAND}" ]; then
COMMAND=help
fi
# Parse arguments
while (($# > 0)); do
case $1 in
-f)
BUNDLE_FILE=$2
shift;
;;
-n)
BUNDLE_NAME=$2
shift;
;;
-v)
BUNDLE_VERSION=$2
shift;
;;
-t)
BUNDLE_TYPE=$2
shift;
;;
-user)
SDMSERVER_USER=$2
shift;
;;
-url)
SDMSERVER_URL=$2
shift;
;;
-verbose)
VERBOSE=true
;;
*)
echo "Unknown parameter: $1"
;;
esac
shift
done
# Request user/password for relevant commands
case ${COMMAND} in
deploy|status|stop|start|uninstall|refresh|list)
if [ -z "$SDMSERVER_USER" ]; then
echo -n "Username [admin]: "
read USERNAME
if [ -z "$USERNAME" ]; then
USERNAME=admin
fi
echo -n "Password: "
read -s PASSWORD
echo # calling 'read' with -s doesn't issue a newline
SDMSERVER_USER=${USERNAME}:${PASSWORD}
fi
esac
SILENT="-s"
if [ "${VERBOSE}" = "true" ]; then
SILENT=""
fi
case ${COMMAND} in
############################################
# Upload and deploy bundle
deploy)
if [ -z "${BUNDLE_FILE}" ]; then
echo "Error: location of OSGi bundle is not specified, use option -f"
exit 1
fi
if [ "${VERBOSE}" = "true" ]; then
echo "Uploading and deploying bundle: ${BUNDLE_FILE}"
fi
# command
RESULT=`curl ${SILENT} -u ${SDMSERVER_USER} -F "application=@${BUNDLE_FILE}" ${SDMSERVER_URL}/admin/web/artifact/deploy.htm`
if [ "${VERBOSE}" = "true" ]; then
echo "-------------------------"
echo "dm Server response: ${RESULT}"
echo "-------------------------"
fi
# analyze result
MESSAGE=`echo "$RESULT" | grep -oEi "<h1>Artifact Console: '.+'</h1>" | cut -c 24- | rev | cut -c 7- | rev`
if [ -z "${RESULT}" ]; then
echo "Failure"
echo "Details: received empty result"
exit 2
elif [ -z "${MESSAGE}" ]; then
echo "Failure"
echo "Details: unexpected format of result: ${RESULT}"
exit 2
else
if [ -z "`echo ${MESSAGE} | grep "Artifact deployed"`" ]; then
echo "Failure"
echo "Details: ${MESSAGE}"
exit 2
else
echo "${MESSAGE}"
fi
fi
;;
############################################
# Check bundle status
status)
if [ -z "${BUNDLE_NAME}" ]; then
echo "Error: bundle symbolic name is not specified, use option -n"
exit 1
fi
if [ -z "${BUNDLE_VERSION}" ]; then
echo "Error: bundle version is not specified, use option -v"
exit 1
fi
if [ "${VERBOSE}" = "true" ]; then
echo "Checking status of bundle: ${BUNDLE_NAME} version: ${BUNDLE_VERSION}"
fi
# command
RESULT=`curl ${SILENT} -u ${SDMSERVER_USER} ${SDMSERVER_URL}/admin/web/artifact/data?parent=\&type=${BUNDLE_TYPE}\&name=${BUNDLE_NAME}\&version=${BUNDLE_VERSION}`
if [ "${VERBOSE}" = "true" ]; then
echo "-------------------------"
echo "dm Server response: ${RESULT}"
echo "-------------------------"
fi
# analyze result
BUNDLE_STATE=`echo "$RESULT" | grep -oEi ",label: '[A-Z]+',icon:" | cut -c 10- | rev | cut -c 8- | rev`
if [ -z "${RESULT}" ]; then
echo "Failure"
echo "Details: received empty result"
exit 2
elif [ -z "${BUNDLE_STATE}" ]; then
echo "Failure"
echo "Details: specified artefact is not found"
exit 2
else
echo "Bundle state: ${BUNDLE_STATE}"
fi
;;
############################################
# List bundles
list)
# command
RESULT=`curl ${SILENT} -u ${SDMSERVER_USER} ${SDMSERVER_URL}/admin/web/artifact/data?parent=${BUNDLE_TYPE}\&type=${BUNDLE_TYPE}\&start=0`
if [ "${VERBOSE}" = "true" ]; then
echo "-------------------------"
echo "dm Server response: ${RESULT}"
echo "-------------------------"
fi
# extract result
RESULT=`echo "$RESULT" | grep -oEi "items\: \[ \{.*\}\]\}" | cut -c 11- | rev | cut -c 4- | rev`
if [ -z "${RESULT}" ]; then
echo "Failure"
echo "Details: received empty result"
exit 2
else
# format, filter and print result
FILTER_NAME=""
if [ ! -z "${BUNDLE_NAME}" ]; then
FILTER_NAME="name=${BUNDLE_NAME},"
fi
FILTER_VERSION=""
if [ ! -z "${BUNDLE_VERSION}" ]; then
FILTER_VERSION="version=${BUNDLE_VERSION},"
fi
echo "$RESULT" | sed -e "s/},{/\'$\'\n/g" | awk -F"[:', ]" '{ print "name=" $20 ", version=" $25 ", type=" $15 }' | grep "${FILTER_NAME}" | grep "${FILTER_VERSION}"
fi
;;
############################################
# Execute command: stop, start, uninstall, refresh
stop|start|uninstall|refresh)
if [ -z "${BUNDLE_NAME}" ]; then
echo "Error: bundle symbolic name is not specified, use option -n"
exit 1
fi
if [ -z "${BUNDLE_VERSION}" ]; then
echo "Error: bundle version is not specified, use option -v"
exit 1
fi
if [ "${VERBOSE}" = "true" ]; then
echo "Executing command: ${COMMAND} for bundle: ${BUNDLE_NAME} version: ${BUNDLE_VERSION}"
fi
# command
RESULT=`curl ${SILENT} -u ${SDMSERVER_USER} ${SDMSERVER_URL}/admin/web/artifact/do/${COMMAND}?type=${BUNDLE_TYPE}\&name=${BUNDLE_NAME}\&version=${BUNDLE_VERSION}`
if [ "${VERBOSE}" = "true" ]; then
echo "-------------------------"
echo "dm Server response: ${RESULT}"
echo "-------------------------"
fi
# analyze result
MESSAGE=`echo "$RESULT" | grep -oEi "<h1>Artifact Console: '.+'</h1>" | cut -c 24- | rev | cut -c 7- | rev`
if [ -z "${RESULT}" ]; then
echo "Failure"
echo "Details: received empty result"
exit 2
elif [ -z "${MESSAGE}" ]; then
echo "Failure"
echo "Details: unexpected format of result: ${RESULT}"
exit 2
elif [ -z "`echo ${MESSAGE} | grep "successful"`" ]; then
echo "Failure"
echo "Details: ${MESSAGE}"
exit 2
else
case ${COMMAND} in
stop)
echo "Stopped"
;;
start)
echo "Started"
;;
uninstall)
echo "Uninstalled"
;;
refresh)
echo "Refreshed"
;;
*)
echo "Something new: ${COMMAND}"
;;
esac
echo "Details: ${MESSAGE}"
fi
;;
############################################
# Display help
*)
if [ "${COMMAND}" != "help" ]; then
echo "Error: unknown command '${COMMAND}'"
echo
fi
echo "SpringSource dm Server OSGi bundels management tool."
echo "Version ${VERSION}"
echo
echo "Usage:"
echo " $0 <command> [options]"
echo
echo "Commands:"
echo " deploy - upload and deploy OSGi bundle to dm Server, required options: -f"
echo " status - check status of bundle at dm Server, required options: -n, -v"
echo " stop - stop bundle at dm Server, required options: -n, -v"
echo " start - start bundle at dm Server, required options: -n, -v"
echo " refresh - refresh bundle at dm Server, required options: -n, -v"
echo " uninstall - uninstall bundle from dm Server, required options: -n, -v"
echo " list - list bundles deployed at Virgo server, optional filter options: -n, -v, -t"
echo " help - display this help"
echo
echo "Options:"
echo " -f <path> - location of OSGi bundle to upload, e.g. /opt/repo/org.slf4j.api-1.7.2.jar"
echo " -n <name> - bundle symbolic name, e.g. org.slf4j.api"
echo " -v <ver> - bundle version, e.g. 1.7.2"
echo " -t <type> - bundle type, possible types: bundle, plan, par"
echo " -user <*> - user name and password for basic auth, e.g. admin:passwd (will be prompted if not given)"
echo " -url <*> - SpringSource dm Server URL, e.g. http://dmserver.internal:7070"
echo " -verbose - enable verbose output"
echo
echo "Examples:"
echo " $0 deploy -f ~/dev/test-bundle-1.0.0-SNAPSHOT.jar"
echo " $0 status -n test-bundle -v 1.0.0.SNAPSHOT"
echo " $0 stop -n test-bundle -v 1.0.0.SNAPSHOT -url http://localhost:8081"
echo " $0 start -n test-bundle -v 1.0.0.SNAPSHOT -verbose"
echo " $0 uninstall -n test-bundle -v 1.0.0.SNAPSHOT"
echo " $0 status -n test-plan -v 2.0.0 -t plan"
;;
esac