os-cmpi-xen

view provider-register.sh @ 28:6137ddada5ca

Updated postinstall target to install necessary XenCIM schema in Interop and host instrumentation namespaces. Updated README.

Signed-off-by: Jim Fehlig <jfehlig@novell.com>
author jfehlig@jfehlig1.provo.novell.com
date Mon Oct 16 15:31:13 2006 -0600 (2006-10-16)
parents bdf24cd56bed
children
line source
1 #!/bin/sh
2 # $Id: provider-register.sh,v 1.7 2006/01/04 06:49:46 bestor Exp $
3 # ==================================================================
4 # (C) Copyright IBM Corp. 2006
5 #
6 # THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE
7 # ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
8 # CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
9 #
10 # You can obtain a current copy of the Common Public License from
11 # http://www.opensource.org/licenses/cpl1.0.php
12 #
13 # Author: Viktor Mihajlovski <mihajlov@de.ibm.com>
14 # Contributors:
15 # Description: Script to install class definitions (MOFs) and
16 # registration data for a variety of supported CIMOMs
17 # ==================================================================
19 pegasus_repository()
20 {
21 for p in $PEGASUS_HOME /var/lib/Pegasus /var/lib/pegasus /usr/local/var/lib/pegasus \
22 /var/local/lib/pegasus /var/opt/tog-pegasus
23 do
24 if test -d $p/repository
25 then
26 echo $p/$1
27 return 0
28 fi
29 done
30 return 1
31 }
33 pegasus_path()
34 {
35 for p in $PEGASUS_HOME/bin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin \
36 /opt/tog-pegasus/bin /opt/tog-pegasus/sbin
37 do
38 if test -x $p/$1
39 then
40 echo $p/$1
41 return 0
42 fi
43 done
44 return 1
45 }
47 pegasus_transform()
48 {
49 OUTFILE=$1
50 shift
51 regfiles=$*
52 PROVIDERMODULES=`cat $regfiles 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 4 | sort | uniq`
53 if test x"$PROVIDERMODULES" = x
54 then
55 echo Failed to read registration files >&2
56 return 1
57 fi
58 PROVIDERS=`cat $regfiles 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 3-4 | sort | uniq`
60 # produce ProviderModules
61 echo > $OUTFILE
62 chatter "Processing provider modules:" $PROVIDERMODULES
63 for pm in $PROVIDERMODULES
64 do
65 cat >> $OUTFILE <<EOFPM
66 instance of PG_ProviderModule
67 {
68 Name = "$pm";
69 Location = "$pm";
70 Vendor = "SBLIM";
71 Version = "2.0.0";
72 InterfaceType = "CMPI";
73 InterfaceVersion = "2.0.0";
74 };
76 EOFPM
77 done
79 # produce Providers
80 set -- $PROVIDERS
81 while test x$1 != x
82 do
83 cat >> $OUTFILE <<EOFP
84 instance of PG_Provider
85 {
86 Name = "$1";
87 ProviderModuleName = "$2";
88 };
90 EOFP
91 shift 2
92 done
94 #produce Capabilities
95 let serial=0
96 for rf in $regfiles
97 do
98 cat $rf | grep -v '^[[:space:]]*#.*' | while read CLASSNAME NAMESPACE PROVIDERNAME PROVIDERMODULE CAPS
99 do
100 let serial=serial+1
101 numcap=
102 for cap in $CAPS
103 do
104 case $cap in
105 instance)
106 if test x$numcap = x
107 then numcap=2
108 else numcap="$numcap,2"
109 fi;;
110 association)
111 if test x$numcap = x
112 then numcap=3
113 else numcap="$numcap,3"
114 fi;;
115 indication)
116 if test x$numcap = x
117 then numcap=4
118 else numcap="$numcap,4"
119 fi;;
120 method)
121 if test x$numcap = x
122 then numcap=5
123 else numcap="$numcap,5"
124 fi;;
125 **) echo unknown provider type $cap >&2
126 return 1;;
127 esac
128 done
129 cat >> $OUTFILE <<EOFC
130 instance of PG_ProviderCapabilities
131 {
132 ProviderModuleName = "$PROVIDERMODULE";
133 ProviderName = "$PROVIDERNAME";
134 ClassName = "$CLASSNAME";
135 ProviderType = { $numcap };
136 Namespaces = {"$NAMESPACE"};
137 SupportedProperties = NULL;
138 SupportedMethods = NULL;
139 CapabilityID = "$CLASSNAME-$serial";
140 };
142 EOFC
143 done
144 done
145 }
147 pegasus_install()
148 {
149 if ps -C cimserver > /dev/null 2>&1
150 then
151 CIMMOF=`pegasus_path cimmof`
152 if test $? != 0
153 then
154 echo "Error: cimmof not found" >&2
155 return 1
156 fi
157 state=active
158 else
159 CIMMOF=`pegasus_path cimmofl`
160 if test $? != 0
161 then
162 echo "Error: cimmofl not found" >&2
163 return 1
164 fi
165 PEGASUSREPOSITORY=`pegasus_repository`
166 if test $? != 0
167 then
168 echo "Error: pegasus repository not found" >&2
169 return 1
170 fi
171 CIMMOF="$CIMMOF -R $PEGASUSREPOSITORY"
172 state=inactive
173 fi
175 if test x$namespace != x
176 then
177 CIMMOF="$CIMMOF -n $namespace"
178 fi
180 mofpath=
181 mymofs=
182 mregs=
183 mofmode=1
184 while test x$1 != x
185 do
186 if test $1 = ":"
187 then
188 mofmode=0
189 shift
190 continue
191 fi
192 if test $mofmode = 1
193 then
194 if test x$mofpath = x
195 then
196 mofpath=`dirname $1`
197 fi
198 mymofs="$mymofs $1"
199 else
200 myregs="$myregs $1"
201 fi
202 shift
203 done
205 for _TEMPDIR in /var/tmp /tmp
206 do
207 if test -w $_TEMPDIR
208 then
209 _REGFILENAME=$_TEMPDIR/$$.mof
210 break
211 fi
212 done
215 trap "rm -f $_REGFILENAME" EXIT
217 if pegasus_transform $_REGFILENAME $myregs
218 then
219 chatter Registering providers with $state cimserver
220 $CIMMOF -uc -I $mofpath $mymofs &&
221 $CIMMOF -uc -n root/PG_Interop $_REGFILENAME
222 else
223 echo "Failed to build pegasus registration MOF." >&2
224 return 1
225 fi
226 }
228 pegasus_uninstall()
229 {
230 mymofs=
231 mregs=
232 mofmode=1
233 while test x$1 != x
234 do
235 if test $1 = ":"
236 then
237 mofmode=0
238 shift
239 continue
240 fi
241 if test $mofmode = 1
242 then
243 mymofs="$mymofs $1"
244 else
245 myregs="$myregs $1"
246 fi
247 shift
248 done
250 if ps -C cimserver > /dev/null 2>&1
251 then
252 PROVIDERMODULES=`cat $myregs 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 4 | sort | uniq`
253 if test x"$PROVIDERMODULES" = x
254 then
255 echo Failed to read registration files >&2
256 return 1
257 fi
258 CIMPROVIDER=`pegasus_path cimprovider`
259 if test $? != 0
260 then
261 echo "Error: cimprovider not found" >&2
262 return 1
263 fi
264 for pm in $PROVIDERMODULES
265 do
266 chatter "Remove provider module" $pm
267 $CIMPROVIDER -d -m $pm > /dev/null &&
268 $CIMPROVIDER -r -m $pm > /dev/null
269 done
270 WBEMEXEC=`pegasus_path wbemexec`
271 if test $? != 0
272 then
273 echo "Error: wbemexec not found" >&2
274 return 1
275 fi
276 CLASSES=`cat $myregs 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 1 | grep -v '^CIM_'`
277 for cls in $CLASSES
278 do
279 chatter Delete CIM Class $cls
280 $WBEMEXEC > /dev/null <<EOFWX
281 <?xml version="1.0" encoding="utf-8" ?>
282 <CIM CIMVERSION="2.0" DTDVERSION="2.0">
283 <MESSAGE ID="4711" PROTOCOLVERSION="1.0">
284 <SIMPLEREQ>
285 <IMETHODCALL NAME="DeleteClass">
286 <LOCALNAMESPACEPATH>
287 <NAMESPACE NAME="root"></NAMESPACE>
288 <NAMESPACE NAME="cimv2"></NAMESPACE>
289 </LOCALNAMESPACEPATH>
290 <IPARAMVALUE NAME="ClassName">
291 <CLASSNAME NAME="$cls"/>
292 </IPARAMVALUE>
293 </IMETHODCALL>
294 </SIMPLEREQ>
295 </MESSAGE>
296 </CIM>
297 EOFWX
298 done
299 else
300 echo "Sorry, cimserver must be running to deregister the providers." >&2
301 return 1
302 fi
303 }
305 sfcb_transform()
306 {
307 OUTFILE=$1
308 shift
309 regfiles=$*
311 #produce sfcb registraion
312 for rf in $regfiles
313 do
314 cat $rf | grep -v '^[[:space:]]*#.*' | while read CLASSNAME NAMESPACE PROVIDERNAME PROVIDERMODULE CAPS
315 do
316 chatter "Registering class" $CLASSNAME
317 cat >> $OUTFILE <<EOFC
318 [$CLASSNAME]
319 provider: $PROVIDERNAME
320 location: $PROVIDERMODULE
321 type: $CAPS
322 namespace: $NAMESPACE
323 #
324 EOFC
325 done
326 done
327 }
329 sfcb_rebuild()
330 {
331 if ps -C sfcbd > /dev/null 2>&1
332 then
333 # sfcb is running -- need to restart
334 for INITSCRIPT in /etc/init.d/sfcb /usr/local/etc/init.d/sfcb none
335 do
336 if test -x $INITSCRIPT
337 then
338 break;
339 fi
340 done
341 chatter "Shutting down sfcb."
342 if test $INITSCRIPT = none
343 then
344 killall sfcbd
345 else
346 $INITSCRIPT stop
347 fi
348 t=0
349 while ps -C sfcbd > /dev/null 2>&1
350 do
351 sleep 1
352 t=`expr $t + 1`
353 if test $t -gt 10
354 then
355 echo "Timed out waiting for sfcb shutdown..." >&2
356 echo "Please stop sfcb manually and rebuild the repository using sfcbrepos." >&2
357 return 1
358 fi
359 done
360 chatter "Rebuilding repository."
361 sfcbrepos -f
362 if test $? != 0
363 then
364 echo "Repository rebuild failed." >&2
365 return 1
366 fi
368 if test $INITSCRIPT = none
369 then
370 echo "No init script found - you need to start sfcbd manually." >&2
371 return 1
372 else
373 chatter "Restarting sfcb."
374 $INITSCRIPT start
375 fi
376 else
377 # Not running - rebuild repository
378 chatter "Rebuilding repository."
379 sfcbrepos -f
380 fi
381 }
383 sfcb_install()
384 {
385 mymofs=
386 mregs=
387 mofmode=1
388 while test x$1 != x
389 do
390 if test $1 = ":"
391 then
392 mofmode=0
393 shift
394 baseregname=`basename $1 .registration`
395 continue
396 fi
397 if test $mofmode = 1
398 then
399 mymofs="$mymofs $1"
400 else
401 myregs="$myregs $1"
402 fi
403 shift
404 done
406 for _TEMPDIR in /var/tmp /tmp
407 do
408 if test -w $_TEMPDIR
409 then
410 _REGFILENAME=$_TEMPDIR/$baseregname.reg
411 break
412 fi
413 done
415 trap "rm -f $_REGFILENAME" EXIT
417 if sfcb_transform $_REGFILENAME $myregs
418 then
419 chatter "Staging provider registration."
420 sfcbstage -r $_REGFILENAME $mymofs
421 if test $? != 0
422 then
423 echo "Failed to stage provider registration." >&2
424 return 1
425 fi
426 sfcb_rebuild
427 else
428 echo "Failed to build sfcb registration file." >&2
429 return 1
430 fi
431 }
433 sfcb_uninstall()
434 {
435 mymofs=
436 while test x$1 != x
437 do
438 if test $1 = ":"
439 then
440 shift
441 baseregname=`basename $1 .registration`
442 break
443 fi
444 mymofs="$mymofs `basename $1`"
445 shift
446 done
448 # "Unstage" MOFs and the registration file
449 chatter "Unstaging provider registrations."
450 sfcbunstage -r $baseregname.reg $mymofs
452 # Rebuild repository
453 sfcb_rebuild
454 }
456 openwbem_transform()
457 {
458 OUTFILE=$1
459 shift
460 moffiles=$*
462 if rm -f $OUTFILE
463 then
464 for _f in $moffiles
465 do
466 sed "s/Provider *( *\"cmpi:/Provider(\"cmpi::/g" < $_f >> $OUTFILE
467 done
468 fi
469 }
471 openwbem_repository()
472 {
473 for p in /var/lib/openwbem /usr/local/var/openwbem
474 do
475 if test -f $p/schema.dat
476 then
477 echo $p
478 return 0
479 fi
480 done
481 return 1
482 }
484 openwbem_install()
485 {
486 CIMMOF=`which owmofc 2> /dev/null`
487 if test $? != 0
488 then
489 echo "Error: cimmof not found" >&2
490 return 1
491 fi
493 if ps -C owcimomd > /dev/null 2>&1
494 then
495 state=active
496 else
497 CIMMOF="$CIMMOF -d `openwbem_repository`"
498 if test $? != 0
499 then
500 echo "Error: OpenWBEM repository not found" >&2
501 return 1
502 fi
503 state=inactive
504 fi
506 if test -d /usr/share/mof/cim-current
507 then
508 CIMMOF="$CIMMOF -s /usr/share/mof/cim-current"
509 fi
511 if test x$namespace != x
512 then
513 CIMMOF="$CIMMOF -n $namespace"
514 fi
516 for _TEMPDIR in /var/tmp /tmp
517 do
518 if test -w $_TEMPDIR
519 then
520 _REGFILENAME=$_TEMPDIR/$$.mof
521 break
522 fi
523 done
525 trap "rm -f $_REGFILENAME" EXIT
527 if openwbem_transform $_REGFILENAME $*
528 then
529 chatter Registering providers with $state owcimomd
530 $CIMMOF $_REGFILENAME > /dev/null
531 else
532 echo "Failed to build OpenWBEM registration MOF." >&2
533 return 1
534 fi
535 }
537 openwbem_uninstall()
538 {
539 CIMMOF=`which owmofc 2> /dev/null`
540 if test $? != 0
541 then
542 echo "Error: cimmof not found" >&2
543 return 1
544 fi
546 if ps -C owcimomd > /dev/null 2>&1
547 then
548 state=active
549 else
550 CIMMOF="$CIMMOF -d `openwbem_repository`"
551 if test $? != 0
552 then
553 echo "Error: OpenWBEM repository not found" >&2
554 return 1
555 fi
556 state=inactive
557 fi
559 for _TEMPDIR in /var/tmp /tmp
560 do
561 if test -w $_TEMPDIR
562 then
563 _REGFILENAME=$_TEMPDIR/$$.mof
564 break
565 fi
566 done
568 trap "rm -f $_REGFILENAME" EXIT
570 if openwbem_transform $_REGFILENAME $*
571 then
572 chatter Deregistering providers with $state owcimomd
573 $CIMMOF -r $_REGFILENAME > /dev/null
574 else
575 echo "Failed to build OpenWBEM registration MOF." >&2
576 return 1
577 fi
578 }
580 cim_server()
581 {
582 for exname in sfcbd cimserver owcimomd
583 do
584 if pegasus_path $exname > /dev/null
585 then
586 case $exname in
587 sfcbd) echo sfcb; return 0;;
588 cimserver) echo pegasus; return 0;;
589 owcimomd) echo openwbem; return 0;;
590 esac
591 break;
592 fi
593 done
594 echo unknown
595 return 1
596 }
598 usage()
599 {
600 echo "usage: $0 [-h] [-v] [-d] [-t <cimserver>] [-n <namespace>] -r regfile ... -m mof ..."
601 }
603 chatter()
604 {
605 if test x$verbose != x
606 then
607 echo $*
608 fi
609 }
611 gb_getopt()
612 {
613 rmode=0
614 mmode=0
615 options=
616 moffiles=
617 registrations=
618 while [ -n "$1" ]
619 do
620 case $1 in
621 -r) mmode=0;
622 rmode=1;
623 shift;;
624 -m) mmode=1;
625 rmode=0;
626 shift;;
627 -*) mmode=0;
628 rmode=0;
629 options="$options $1";
630 shift;;
631 **) if [ $mmode = 1 ]
632 then moffiles="$moffiles $1"
633 elif [ $rmode = 1 ]
634 then registrations="$registrations -r $1"
635 else options="$options $1";
636 fi;
637 shift;;
638 esac
639 done
640 echo $options $registrations $moffiles
641 }
643 prepargs=`gb_getopt $*`
644 args=`getopt dvht:n:r: $prepargs`
645 rc=$?
647 if [ $rc = 127 ]
648 then
649 echo "warning: getopt not found ...continue without syntax check"
650 args=$prepargs
651 elif [ $rc != 0 ]
652 then
653 usage $0
654 exit 1
655 fi
657 set -- $args
659 while [ -n "$1" ]
660 do
661 case $1 in
662 -h) help=1;
663 shift;
664 break;;
665 -v) verbose=1;
666 shift;;
667 -d) deregister=1;
668 shift;;
669 -t) cimserver=$2;
670 shift 2;;
671 -n) namespace=$2;
672 shift 2;;
673 -r) regs="$regs $2";
674 shift 2;;
675 --) shift;
676 break;;
677 **) break;;
678 esac
679 done
681 mofs=$*
683 if [ "$help" = "1" ]
684 then
685 usage
686 echo -e "\t-h display help message"
687 echo -e "\t-v verbose mode"
688 echo -e "\t-d deregister provider and uninstall schema"
689 echo -e "\t-t specify cimserver type (pegasus|sfcb|openwbem|sniacimom)"
690 echo -e "\t-n specify namespace"
691 echo -e "\t-r specify registration files"
692 echo -e "\t-m specify schema mof files"
693 echo
694 echo Use this command to install schema mofs and register providers.
695 echo CIM Server Type is required as well as at least one registration file and one mof.
696 exit 0
697 fi
699 if test x"$mofs" = x || test x"$regs" = x
700 then
701 usage $0
702 exit 1
703 fi
705 if test x$cimserver = x
706 then
707 cimserver=`cim_server`
708 if test $? = 0
709 then
710 chatter "Autoselected CIM server type:" $cimserver
711 else
712 echo "CIM server type could not be determined, specify with -t." >&2
713 exit 1
714 fi
715 fi
717 if test x$deregister = x
718 then
719 case $cimserver in
720 pegasus) pegasus_install $mofs ":" $regs;;
721 sfcb) sfcb_install $mofs ":" $regs;;
722 openwbem) openwbem_install $mofs ;;
723 sniacimom) echo sniacimom not yet supported && exit 1 ;;
724 **) echo "Invalid CIM Server Type " $cimserver && exit 1;;
725 esac
726 else
727 case $cimserver in
728 pegasus) pegasus_uninstall $mofs ":" $regs;;
729 sfcb) sfcb_uninstall $mofs ":" $regs;;
730 openwbem) openwbem_uninstall $mofs ;;
731 sniacimom) echo sniacimom not yet supported && exit 1 ;;
732 **) echo "Invalid CIM Server Type " $cimserver && exit 1;;
733 esac
734 fi