os-cmpi-xen

view provider-register.sh @ 0:72b83cde6b72

Initial checkin
author jbulpin@ubuntu.eng.hq.xensource.com
date Wed Mar 22 14:05:14 2006 -0700 (2006-03-22)
parents
children bdf24cd56bed
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 mofpath=
176 mymofs=
177 mregs=
178 mofmode=1
179 while test x$1 != x
180 do
181 if test $1 = ":"
182 then
183 mofmode=0
184 shift
185 continue
186 fi
187 if test $mofmode = 1
188 then
189 if test x$mofpath = x
190 then
191 mofpath=`dirname $1`
192 fi
193 mymofs="$mymofs $1"
194 else
195 myregs="$myregs $1"
196 fi
197 shift
198 done
200 for _TEMPDIR in /var/tmp /tmp
201 do
202 if test -w $_TEMPDIR
203 then
204 _REGFILENAME=$_TEMPDIR/$$.mof
205 break
206 fi
207 done
210 trap "rm -f $_REGFILENAME" EXIT
212 if pegasus_transform $_REGFILENAME $myregs
213 then
214 chatter Registering providers with $state cimserver
215 $CIMMOF -uc -I $mofpath -n root/cimv2 $mymofs &&
216 $CIMMOF -uc -n root/PG_Interop $_REGFILENAME
217 else
218 echo "Failed to build pegasus registration MOF." >&2
219 return 1
220 fi
221 }
223 pegasus_uninstall()
224 {
225 mymofs=
226 mregs=
227 mofmode=1
228 while test x$1 != x
229 do
230 if test $1 = ":"
231 then
232 mofmode=0
233 shift
234 continue
235 fi
236 if test $mofmode = 1
237 then
238 mymofs="$mymofs $1"
239 else
240 myregs="$myregs $1"
241 fi
242 shift
243 done
245 if ps -C cimserver > /dev/null 2>&1
246 then
247 PROVIDERMODULES=`cat $myregs 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 4 | sort | uniq`
248 if test x"$PROVIDERMODULES" = x
249 then
250 echo Failed to read registration files >&2
251 return 1
252 fi
253 CIMPROVIDER=`pegasus_path cimprovider`
254 if test $? != 0
255 then
256 echo "Error: cimprovider not found" >&2
257 return 1
258 fi
259 for pm in $PROVIDERMODULES
260 do
261 chatter "Remove provider module" $pm
262 $CIMPROVIDER -d -m $pm > /dev/null &&
263 $CIMPROVIDER -r -m $pm > /dev/null
264 done
265 WBEMEXEC=`pegasus_path wbemexec`
266 if test $? != 0
267 then
268 echo "Error: wbemexec not found" >&2
269 return 1
270 fi
271 CLASSES=`cat $myregs 2> /dev/null | grep -v '^[[:space:]]*#.*' | cut -d ' ' -f 1 | grep -v '^CIM_'`
272 for cls in $CLASSES
273 do
274 chatter Delete CIM Class $cls
275 $WBEMEXEC > /dev/null <<EOFWX
276 <?xml version="1.0" encoding="utf-8" ?>
277 <CIM CIMVERSION="2.0" DTDVERSION="2.0">
278 <MESSAGE ID="4711" PROTOCOLVERSION="1.0">
279 <SIMPLEREQ>
280 <IMETHODCALL NAME="DeleteClass">
281 <LOCALNAMESPACEPATH>
282 <NAMESPACE NAME="root"></NAMESPACE>
283 <NAMESPACE NAME="cimv2"></NAMESPACE>
284 </LOCALNAMESPACEPATH>
285 <IPARAMVALUE NAME="ClassName">
286 <CLASSNAME NAME="$cls"/>
287 </IPARAMVALUE>
288 </IMETHODCALL>
289 </SIMPLEREQ>
290 </MESSAGE>
291 </CIM>
292 EOFWX
293 done
294 else
295 echo "Sorry, cimserver must be running to deregister the providers." >&2
296 return 1
297 fi
298 }
300 sfcb_transform()
301 {
302 OUTFILE=$1
303 shift
304 regfiles=$*
306 #produce sfcb registraion
307 for rf in $regfiles
308 do
309 cat $rf | grep -v '^[[:space:]]*#.*' | while read CLASSNAME NAMESPACE PROVIDERNAME PROVIDERMODULE CAPS
310 do
311 chatter "Registering class" $CLASSNAME
312 cat >> $OUTFILE <<EOFC
313 [$CLASSNAME]
314 provider: $PROVIDERNAME
315 location: $PROVIDERMODULE
316 type: $CAPS
317 namespace: $NAMESPACE
318 #
319 EOFC
320 done
321 done
322 }
324 sfcb_rebuild()
325 {
326 if ps -C sfcbd > /dev/null 2>&1
327 then
328 # sfcb is running -- need to restart
329 for INITSCRIPT in /etc/init.d/sfcb /usr/local/etc/init.d/sfcb none
330 do
331 if test -x $INITSCRIPT
332 then
333 break;
334 fi
335 done
336 chatter "Shutting down sfcb."
337 if test $INITSCRIPT = none
338 then
339 killall sfcbd
340 else
341 $INITSCRIPT stop
342 fi
343 t=0
344 while ps -C sfcbd > /dev/null 2>&1
345 do
346 sleep 1
347 t=`expr $t + 1`
348 if test $t -gt 10
349 then
350 echo "Timed out waiting for sfcb shutdown..." >&2
351 echo "Please stop sfcb manually and rebuild the repository using sfcbrepos." >&2
352 return 1
353 fi
354 done
355 chatter "Rebuilding repository."
356 sfcbrepos -f
357 if test $? != 0
358 then
359 echo "Repository rebuild failed." >&2
360 return 1
361 fi
363 if test $INITSCRIPT = none
364 then
365 echo "No init script found - you need to start sfcbd manually." >&2
366 return 1
367 else
368 chatter "Restarting sfcb."
369 $INITSCRIPT start
370 fi
371 else
372 # Not running - rebuild repository
373 chatter "Rebuilding repository."
374 sfcbrepos -f
375 fi
376 }
378 sfcb_install()
379 {
380 mymofs=
381 mregs=
382 mofmode=1
383 while test x$1 != x
384 do
385 if test $1 = ":"
386 then
387 mofmode=0
388 shift
389 baseregname=`basename $1 .registration`
390 continue
391 fi
392 if test $mofmode = 1
393 then
394 mymofs="$mymofs $1"
395 else
396 myregs="$myregs $1"
397 fi
398 shift
399 done
401 for _TEMPDIR in /var/tmp /tmp
402 do
403 if test -w $_TEMPDIR
404 then
405 _REGFILENAME=$_TEMPDIR/$baseregname.reg
406 break
407 fi
408 done
410 trap "rm -f $_REGFILENAME" EXIT
412 if sfcb_transform $_REGFILENAME $myregs
413 then
414 chatter "Staging provider registration."
415 sfcbstage -r $_REGFILENAME $mymofs
416 if test $? != 0
417 then
418 echo "Failed to stage provider registration." >&2
419 return 1
420 fi
421 sfcb_rebuild
422 else
423 echo "Failed to build sfcb registration file." >&2
424 return 1
425 fi
426 }
428 sfcb_uninstall()
429 {
430 mymofs=
431 while test x$1 != x
432 do
433 if test $1 = ":"
434 then
435 shift
436 baseregname=`basename $1 .registration`
437 break
438 fi
439 mymofs="$mymofs `basename $1`"
440 shift
441 done
443 # "Unstage" MOFs and the registration file
444 chatter "Unstaging provider registrations."
445 sfcbunstage -r $baseregname.reg $mymofs
447 # Rebuild repository
448 sfcb_rebuild
449 }
451 openwbem_transform()
452 {
453 OUTFILE=$1
454 shift
455 moffiles=$*
457 if rm -f $OUTFILE
458 then
459 for _f in $moffiles
460 do
461 sed "s/Provider *( *\"cmpi:/Provider(\"cmpi::/g" < $_f >> $OUTFILE
462 done
463 fi
464 }
466 openwbem_repository()
467 {
468 for p in /var/lib/openwbem /usr/local/var/openwbem
469 do
470 if test -f $p/schema.dat
471 then
472 echo $p
473 return 0
474 fi
475 done
476 return 1
477 }
479 openwbem_install()
480 {
481 CIMMOF=`which owmofc 2> /dev/null`
482 if test $? != 0
483 then
484 echo "Error: cimmof not found" >&2
485 return 1
486 fi
488 if ps -C owcimomd > /dev/null 2>&1
489 then
490 state=active
491 else
492 CIMMOF="$CIMMOF -d `openwbem_repository`"
493 if test $? != 0
494 then
495 echo "Error: OpenWBEM repository not found" >&2
496 return 1
497 fi
498 state=inactive
499 fi
501 for _TEMPDIR in /var/tmp /tmp
502 do
503 if test -w $_TEMPDIR
504 then
505 _REGFILENAME=$_TEMPDIR/$$.mof
506 break
507 fi
508 done
510 trap "rm -f $_REGFILENAME" EXIT
512 if openwbem_transform $_REGFILENAME $*
513 then
514 chatter Registering providers with $state owcimomd
515 $CIMMOF $_REGFILENAME > /dev/null
516 else
517 echo "Failed to build OpenWBEM registration MOF." >&2
518 return 1
519 fi
520 }
522 openwbem_uninstall()
523 {
524 CIMMOF=`which owmofc 2> /dev/null`
525 if test $? != 0
526 then
527 echo "Error: cimmof not found" >&2
528 return 1
529 fi
531 if ps -C owcimomd > /dev/null 2>&1
532 then
533 state=active
534 else
535 CIMMOF="$CIMMOF -d `openwbem_repository`"
536 if test $? != 0
537 then
538 echo "Error: OpenWBEM repository not found" >&2
539 return 1
540 fi
541 state=inactive
542 fi
544 for _TEMPDIR in /var/tmp /tmp
545 do
546 if test -w $_TEMPDIR
547 then
548 _REGFILENAME=$_TEMPDIR/$$.mof
549 break
550 fi
551 done
553 trap "rm -f $_REGFILENAME" EXIT
555 if openwbem_transform $_REGFILENAME $*
556 then
557 chatter Deregistering providers with $state owcimomd
558 $CIMMOF -r $_REGFILENAME > /dev/null
559 else
560 echo "Failed to build OpenWBEM registration MOF." >&2
561 return 1
562 fi
563 }
565 cim_server()
566 {
567 for exname in sfcbd cimserver owcimomd
568 do
569 if pegasus_path $exname > /dev/null
570 then
571 case $exname in
572 sfcbd) echo sfcb; return 0;;
573 cimserver) echo pegasus; return 0;;
574 owcimomd) echo openwbem; return 0;;
575 esac
576 break;
577 fi
578 done
579 echo unknown
580 return 1
581 }
583 usage()
584 {
585 echo "usage: $0 [-h] [-v] [-d] [-t <cimserver>] -r regfile ... -m mof ..."
586 }
588 chatter()
589 {
590 if test x$verbose != x
591 then
592 echo $*
593 fi
594 }
596 gb_getopt()
597 {
598 rmode=0
599 mmode=0
600 options=
601 moffiles=
602 registrations=
603 while [ -n "$1" ]
604 do
605 case $1 in
606 -r) mmode=0;
607 rmode=1;
608 shift;;
609 -m) mmode=1;
610 rmode=0;
611 shift;;
612 -*) mmode=0;
613 rmode=0;
614 options="$options $1";
615 shift;;
616 **) if [ $mmode = 1 ]
617 then moffiles="$moffiles $1"
618 elif [ $rmode = 1 ]
619 then registrations="$registrations -r $1"
620 else options="$options $1";
621 fi;
622 shift;;
623 esac
624 done
625 echo $options $registrations $moffiles
626 }
628 prepargs=`gb_getopt $*`
629 args=`getopt dvht:r: $prepargs`
630 rc=$?
632 if [ $rc = 127 ]
633 then
634 echo "warning: getopt not found ...continue without syntax check"
635 args=$prepargs
636 elif [ $rc != 0 ]
637 then
638 usage $0
639 exit 1
640 fi
642 set -- $args
644 while [ -n "$1" ]
645 do
646 case $1 in
647 -h) help=1;
648 shift;
649 break;;
650 -v) verbose=1;
651 shift;;
652 -d) deregister=1;
653 shift;;
654 -t) cimserver=$2;
655 shift 2;;
656 -r) regs="$regs $2";
657 shift 2;;
658 --) shift;
659 break;;
660 **) break;;
661 esac
662 done
664 mofs=$*
666 if [ "$help" = "1" ]
667 then
668 usage
669 echo -e "\t-h display help message"
670 echo -e "\t-v verbose mode"
671 echo -e "\t-d deregister provider and uninstall schema"
672 echo -e "\t-t specify cimserver type (pegasus|sfcb|openwbem|sniacimom)"
673 echo -e "\t-r specify registration files"
674 echo -e "\t-m specify schema mof files"
675 echo
676 echo Use this command to install schema mofs and register providers.
677 echo CIM Server Type is required as well as at least one registration file and one mof.
678 exit 0
679 fi
681 if test x"$mofs" = x || test x"$regs" = x
682 then
683 usage $0
684 exit 1
685 fi
687 if test x$cimserver = x
688 then
689 cimserver=`cim_server`
690 if test $? = 0
691 then
692 chatter "Autoselected CIM server type:" $cimserver
693 else
694 echo "CIM server type could not be determined, specify with -t." >&2
695 exit 1
696 fi
697 fi
699 if test x$deregister = x
700 then
701 case $cimserver in
702 pegasus) pegasus_install $mofs ":" $regs;;
703 sfcb) sfcb_install $mofs ":" $regs;;
704 openwbem) openwbem_install $mofs ;;
705 sniacimom) echo sniacimom not yet supported && exit 1 ;;
706 **) echo "Invalid CIM Server Type " $cimserver && exit 1;;
707 esac
708 else
709 case $cimserver in
710 pegasus) pegasus_uninstall $mofs ":" $regs;;
711 sfcb) sfcb_uninstall $mofs ":" $regs;;
712 openwbem) openwbem_uninstall $mofs ;;
713 sniacimom) echo sniacimom not yet supported && exit 1 ;;
714 **) echo "Invalid CIM Server Type " $cimserver && exit 1;;
715 esac
716 fi