-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider-register.sh
executable file
·571 lines (529 loc) · 11.3 KB
/
provider-register.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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
#!/bin/sh
# $Id$
# ==================================================================
# (C) Copyright IBM Corp. 2005
#
# THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE
# ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
# CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
#
# You can obtain a current copy of the Common Public License from
# http://www.opensource.org/licenses/cpl1.0.php
#
# Author: Viktor Mihajlovski <mihajlov@de.ibm.com>
# Contributors:
# Description: Script to install class definitions (MOFs) and
# registration data for a variety of supported CIMOMs
# ==================================================================
function pegasus_path()
{
for p in /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin \
/opt/tog-pegasus/bin /opt/tog-pegasus/sbin $PEGASUS_HOME/bin
do
if test -x $p/$1
then
echo $p/$1
return 0
fi
done
return 1
}
function pegasus_transform()
{
OUTFILE=$1
shift
regfiles=$*
PROVIDERMODULES=`cat $regfiles 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 4 | sort | uniq`
if test x"$PROVIDERMODULES" == x
then
echo Failed to read registration files >&2
return 1
fi
PROVIDERS=`cat $regfiles 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 3-4 | sort | uniq`
# produce ProviderModules
echo > $OUTFILE
chatter "Processing provider modules:" $PROVIDERMODULES
for pm in $PROVIDERMODULES
do
cat >> $OUTFILE <<EOFPM
instance of PG_ProviderModule
{
Name = "$pm";
Location = "$pm";
Vendor = "SBLIM";
Version = "2.0.0";
InterfaceType = "CMPI";
InterfaceVersion = "2.0.0";
};
EOFPM
done
# produce Providers
set -- $PROVIDERS
while test x$1 != x
do
cat >> $OUTFILE <<EOFP
instance of PG_Provider
{
Name = "$1";
ProviderModuleName = "$2";
};
EOFP
shift 2
done
#produce Capabilities
for rf in $regfiles
do
cat $rf | grep -v '^[[:space:]]*#.*' | while read CLASSNAME NAMESPACE PROVIDERNAME PROVIDERMODULE CAPS
do
numcap=
for cap in $CAPS
do
case $cap in
instance)
if test x$numcap == x
then numcap=2
else numcap="$numcap, 2"
fi;;
association)
if test x$numcap == x
then numcap=3
else numcap="$numcap, 3"
fi;;
indication)
if test x$numcap == x
then numcap=4
else numcap="$numcap, 4"
fi;;
method)
if test x$numcap == x
then numcap=5
else numcap="$numcap, 5"
fi;;
**) echo unknown provider type $cap >&2
return 1;;
esac
done
cat >> $OUTFILE <<EOFC
instance of PG_ProviderCapabilities
{
ProviderModuleName = "$PROVIDERMODULE";
ProviderName = "$PROVIDERNAME";
ClassName = "$CLASSNAME";
ProviderType = { $numcap };
Namespaces = {"$NAMESPACE"};
SupportedProperties = NULL;
SupportedMethods = NULL;
CapabilityID = "1";
};
EOFC
done
done
}
function pegasus_install()
{
if ps -C cimserver > /dev/null 2>&1
then
CIMMOF=`pegasus_path cimmof`
if test $? != 0
then
echo "Error: cimmof not found" >&2
return 1
fi
state=active
else
CIMMOF=`pegasus_path cimmofl`
if test $? != 0
then
echo "Error: cimmof not found" >&2
return 1
fi
state=inactive
fi
mymofs=
mregs=
mofmode=1
while test x$1 != x
do
if test $1 == ":"
then
mofmode=0
shift
continue
fi
if test $mofmode == 1
then
mymofs="$mymofs $1"
else
myregs="$myregs $1"
fi
shift
done
for _TEMPDIR in /var/tmp /tmp
do
if test -w $_TEMPDIR
then
_REGFILENAME=$_TEMPDIR/$$.mof
break
fi
done
trap "rm -f $_REGFILENAME" EXIT
if pegasus_transform $_REGFILENAME $myregs
then
chatter Registering providers with $state cimserver
$CIMMOF -n root/cimv2 $mymofs &&
$CIMMOF -n root/PG_Interop $_REGFILENAME
else
echo "Failed to build pegasus registration MOF." >&2
return 1
fi
}
function pegasus_uninstall()
{
mymofs=
mregs=
mofmode=1
while test x$1 != x
do
if test $1 == ":"
then
mofmode=0
shift
continue
fi
if test $mofmode == 1
then
mymofs="$mymofs $1"
else
myregs="$myregs $1"
fi
shift
done
if ps -C cimserver > /dev/null 2>&1
then
PROVIDERMODULES=`cat $myregs 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 4 | sort | uniq`
if test x"$PROVIDERMODULES" == x
then
echo Failed to read registration files >&2
return 1
fi
CIMPROVIDER=`pegasus_path cimprovider`
if test $? != 0
then
echo "Error: cimprovider not found" >&2
return 1
fi
for pm in $PROVIDERMODULES
do
chatter "Remove provider module" $pm
$CIMPROVIDER -d -m $pm > /dev/null &&
$CIMPROVIDER -r -m $pm > /dev/null
done
WBEMEXEC=`pegasus_path wbemexec`
if test $? != 0
then
echo "Error: wbemexec not found" >&2
return 1
fi
CLASSES=`cat $myregs 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 1`
for cls in $CLASSES
do
chatter Delete CIM Class $cls
$WBEMEXEC > /dev/null <<EOFWX
<?xml version="1.0" encoding="utf-8" ?>
<CIM CIMVERSION="2.0" DTDVERSION="2.0">
<MESSAGE ID="4711" PROTOCOLVERSION="1.0">
<SIMPLEREQ>
<IMETHODCALL NAME="DeleteClass">
<LOCALNAMESPACEPATH>
<NAMESPACE NAME="root"></NAMESPACE>
<NAMESPACE NAME="cimv2"></NAMESPACE>
</LOCALNAMESPACEPATH>
<IPARAMVALUE NAME="ClassName">
<CLASSNAME NAME="$cls"/>
</IPARAMVALUE>
</IMETHODCALL>
</SIMPLEREQ>
</MESSAGE>
</CIM>
EOFWX
done
else
echo "Sorry, cimserver must be running to deregister the providers." >&2
return 1
fi
}
function sfcb_transform()
{
OUTFILE=$1
shift
regfiles=$*
#produce sfcb registraion
for rf in $regfiles
do
cat $rf | grep -v '^[[:space:]]*#.*' | while read CLASSNAME NAMESPACE PROVIDERNAME PROVIDERMODULE CAPS
do
chatter "Registering class" $CLASSNAME
cat >> $OUTFILE <<EOFC
[$CLASSNAME]
provider: $PROVIDERNAME
location: $PROVIDERMODULE
type: $CAPS
namespace: $NAMESPACE
#
EOFC
done
done
}
function sfcb_rebuild()
{
if ps -C sfcbd > /dev/null 2>&1
then
# sfcb is running -- need to restart
for INITSCRIPT in /etc/init.d/sfcb /usr/local/etc/init.d/sfcb none
do
if test -x $INITSCRIPT
then
break;
fi
done
chatter "Shutting down sfcb."
if test $INITSCRIPT == none
then
killall sfcbd
else
$INITSCRIPT stop
fi
t=0
while ps -C sfcbd > /dev/null 2>&1
do
sleep 1
t=`expr $t + 1`
if test $t > 10
then
echo "Timed out waiting for sfcb shutdown..." >&2
echo "Please stop sfcb manually and rebuild the repository using sfcbrepos." >&2
return 1
fi
done
chatter "Rebuilding repository."
sfcbrepos -f
if test $? != 0
then
echo "Repository rebuild failed." >&2
return 1
fi
if test $INITSCRIPT == none
then
echo "No init script found - you need to start sfcbd manually." >&2
return 1
else
chatter "Restarting sfcb."
$INITSCRIPT start
fi
else
# Not running - rebuild repository
chatter "Rebuilding repository."
sfcbrepos -f
fi
}
function sfcb_install()
{
mymofs=
mregs=
mofmode=1
while test x$1 != x
do
if test $1 == ":"
then
mofmode=0
shift
baseregname=`basename $1 .registration`
continue
fi
if test $mofmode == 1
then
mymofs="$mymofs $1"
else
myregs="$myregs $1"
fi
shift
done
for _TEMPDIR in /var/tmp /tmp
do
if test -w $_TEMPDIR
then
_REGFILENAME=$_TEMPDIR/$baseregname.reg
break
fi
done
trap "rm -f $_REGFILENAME" EXIT
if sfcb_transform $_REGFILENAME $myregs
then
chatter "Staging provider registration."
sfcbstage -r $_REGFILENAME $mymofs
if test $? != 0
then
echo "Failed to stage provider registration." >&2
return 1
fi
sfcb_rebuild
else
echo "Failed to build sfcb registration file." >&2
return 1
fi
}
function sfcb_uninstall()
{
mymofs=
while test x$1 != x
do
if test $1 == ":"
then
shift
baseregname=`basename $1 .registration`
break
fi
mymofs="$mymofs `basename $1`"
shift
done
# "Unstage" MOFs and the registration file
chatter "Unstaging provider regsiatrations."
sfcbunstage -r $baseregname.reg $mymofs
# Rebuild repository
sfcb_rebuild
}
function cim_server()
{
for exname in sfcbd cimserver owcimomd
do
if pegasus_path $exname > /dev/null
then
case $exname in
sfcbd) echo sfcb; return 0;;
cimserver) echo pegasus; return 0;;
owcimomd) echo openwbem; return 0;;
esac
break;
fi
done
echo unknown
return 1
}
function usage()
{
echo "usage: $0 [-h] [-v] [-d] [-t <cimserver>] -r regfile ... -m mof ..."
}
function chatter()
{
if test x$verbose != x
then
echo $*
fi
}
function gb_getopt()
{
rmode=0
mmode=0
options=
moffiles=
registrations=
while [ -n "$1" ]
do
case $1 in
-r) mmode=0;
rmode=1;
shift;;
-m) mmode=1;
rmode=0;
shift;;
-*) mmode=0;
rmode=0;
options="$options $1";
shift;;
**) if [ $mmode == 1 ]
then moffiles="$moffiles $1"
elif [ $rmode == 1 ]
then registrations="$registrations -r $1"
else options="$options $1";
fi;
shift;;
esac
done
echo $options $registrations $moffiles
}
prepargs=`gb_getopt $*`
args=`getopt dvht:r: $prepargs`
if [ $? != 0 ]
then
usage $0
exit 1
fi
set -- $args
while [ -n "$1" ]
do
case $1 in
-h) help=1;
shift;
break;;
-v) verbose=1;
shift;;
-d) deregister=1;
shift;;
-t) cimserver=$2;
shift 2;;
-r) regs="$regs $2";
shift 2;;
--) shift;
break;;
**) break;;
esac
done
mofs=$*
if [ "$help" == "1" ]
then
usage
echo -e "\t-h display help message"
echo -e "\t-v verbose mode"
echo -e "\t-d deregister provider and uninstall schema"
echo -e "\t-t specify cimserver type (pegasus|sfcb|openwbem|sniacimom)"
echo -e "\t-r specify registration files"
echo -e "\t-m specify schema mof files"
echo
echo Use this command to install schema mofs and register providers.
echo CIM Server Type is required as well as at least one registration file and one mof.
exit 0
fi
if test x"$mofs" == x || test x"$regs" == x
then
usage $0
exit 1
fi
if test x$cimserver == x
then
cimserver=`cim_server`
if test $? == 0
then
chatter "Autoselected CIM server type:" $cimserver
else
echo "CIM server type could not be determined, specify with -t." >&2
exit 1
fi
fi
if test x$deregister == x
then
case $cimserver in
pegasus) pegasus_install $mofs ":" $regs;;
sfcb) sfcb_install $mofs ":" $regs;;
openwbem) echo openwbem not yet supported && exit 1 ;;
sniacimom) echo sniacimom not yet supported && exit 1 ;;
**) echo "Invalid CIM Server Type " $cimserver && exit 1;;
esac
else
case $cimserver in
pegasus) pegasus_uninstall $mofs ":" $regs;;
sfcb) sfcb_uninstall $mofs ":" $regs;;
openwbem) echo openwbem not yet supported && exit 1 ;;
sniacimom) echo sniacimom not yet supported && exit 1 ;;
**) echo "Invalid CIM Server Type " $cimserver && exit 1;;
esac
fi