1 karl 1.1 #!/bin/bash
2 ###########################################################################
3 ##
4 ## createschema script to create CIM Schema "interface" files:
5 ##
6 ## This script was used starting when CIM Schema Version 2.11 was
7 ## installed because the new DMTF distribution is different that
8 ## the file structure used by the Pegasus repository build functions.
9 ## It is not intended for general use. It is available here as
10 ## further documentation of the CIM Schema install process and for
11 ## future reference when new CIM Schema versions are installed.
12 ##
13 ## This bash shell script file creates "interface" files for the new
14 ## DMTF CIM Schema Version 2.11 and later to make them compatible with the
15 ## OpenPegasus build enviroment that has been used for previous versions.
16 ##
17 ##
18 ## The following files are needed and will each include the appropriate
19 ## DMTF files.
20 ## In Schemas/CIMxxx where xxx is the schema directory
21 ## CIM_Schema.mof
22 karl 1.1 ## CIM_Event.mof
23 ## CIM_Core.mof
24 ## Core_Qualifiers.mof
25 ## CIM_Interop.mof
26 ##
27 ## CIM_Physical.mof
28 ## CIM_Schema.mof
29 ##
30 ## The original DMTF CIM schema files are installed in Schemas/CIMxxx/DMTF
31 ##
32 ## To use this script:
33 ## 1. Download the CIM schema MOF zip file from the DMTF web site
34 ## 2. Insure that $PEGASUS_ROOT is set
35 ## 3. run the script with the following options
36 ## a. parameter 1 the schema version (ex. 214)
37 ## b. parameter 2 is the location of the downloaded zip file.
38 ##
39 ## NOTE: If the Schema directory already exists the user is offered
40 ## the option to replace the enitre directory.
41 ##
42 ## CURRENT ISSUES AND LIMITATIONS
43 karl 1.1 ## 1. Intended for use with FINAL mof files. It does not make any
44 ## provisions for the experimental mof.
45 ## 2. This is a bash script and intended to be used only on systems
46 ## with the bash shell.
47 ## 3. Does not test to determne if the input schema version is valid
48 ##########################################################################
49
50 ##########################################################################
51 ##
52 ## FUNCTION DEFINITIONS
53 ##
54 ##########################################################################
55
56 function usage {
57 printf "\nUsage: %s <cim version> <DMTF CIM mof zip file>\n" $0 >&2
58 printf " Example: %s 214 ~/cimv214Final-MOFs.zip\n" $0 >&2
59 }
60
61 ## INSERT_LICENSE ()
62 ## Insert the current Pegasus License into a new file
63 ## used for the new files we create to link the schema
64 karl 1.1 ## This function creates the file.
65 ##
66 function INSERT_LICENSE {
67 FILE=$1 ;
68 cat "${PEGASUS_ROOT}/doc/license.txt" > ${FILE} ;
69 }
70
71 ## INSERT_BLANK_LINE ()
72 ## $1 filename w/o extensions
73 function INSERT_BLANK_LINE {
74 FILE=$1 ;
75 echo " " >> ${FILE}.mof ;
76 }
77
78 ## INSERT_LINE ()
79 ## Parameter 1 File to target w/o extension
80 ## Parameter 2 Text for line to insert
81 ##
82 function INSERT_LINE {
83 FILE=$1 ;
84 echo "$2" >> ${FILE}.mof ;
85 karl 1.1 }
86
87 ## INSERT_EXTRACTED_INCLUDES ()
88 ##
89 ## copy all include lines for this file from $CIMSCHEMAVERSION.mof
90 ## changing them to add the DMTF directory.
91 ##
92 ## IE: The following line for the CIM_Core.mof file
93 ##
94 ## #pragma include ("Core\CIM_ManagedElement.mof")
95 ##
96 ## gets changed to the following:
97 ##
98 ## #pragma include ("DMTF/Core\CIM_ManagedElement.mof")
99 ## Parameters
100 ## $1 CIM version number for DMTF schema File to grep
101 ## $2 Output to build w/o extension
102 ##
103 function INSERT_EXTRACTED_INCLUDES
104 {
105 FILE=$1 ;
106 karl 1.1 NAME=$2 ;
107
108 grep "(\"${NAME}" DMTF/cimv${CIM_SCHEMA_VER}.mof | \
109 sed 's/include ("/include ("DMTF\//' >> ${FILE}.mof ;
110 return 0 ;
111 }
112
113 ## CREATE_MOF_FILE
114 ## Creates the new mof file with name and filename
115 ## and inserts license and descriptive material
116 ## $1 = Name for mof file to create (without extension)
117 function CREATE_MOF_FILE {
118 NAME=$1 ;
119 FILE=${NAME}.mof
120 local TODAY=$(date '+%m/%d/%Y')
121 INSERT_LICENSE ${FILE}
122 echo "// ====================================================" >> ${FILE}
123 echo "// Title : ${NAME} MOF" >> ${FILE}
124 echo "// Filename : ${NAME}.mof" >> ${FILE}
125 echo "// Version :" >> ${FILE}
126 echo "// Date : ${TODAY}" >> ${FILE}
127 karl 1.1 echo "// Description: This file was created by The OpenPegasus Group to" \
128 >> ${FILE}
129 echo "// create DMTF CIM Schema Version ${CIM_SCHEMA_VER} " \
130 >> ${FILE}
131 echo "// interface filesfiles compatible with OpenPegasus " \
132 >> ${FILE}
133 echo "// build enviroment." >> ${FILE}
134 echo "//" >> ${FILE}
135 echo "//=====================================================" >> ${FILE}
136
137 INSERT_BLANK_LINE ${NAME} ;
138 }
139
140 ## Let user make choice.
141 ## called like: chice <prompt>
142 ## Returns: global variable choice with y / n or answer
143 function choice {
144 CHOICE=''
145 local prompt="$*"
146 local answer
147
148 karl 1.1 read -p "$prompt" answer
149 case "$answer" in
150 [yY1] ) CHOICE='y';;
151 [nN0] ) CHOICE='n';;
152 * ) CHOICE="$answer";;
153 esac
154 } # end of choice function
155
156 #######################################################################
157 ##
158 ## Execute the script
159 ##
160 #######################################################################
161
162
163 #######################################################################
164 ## Test and setup variables for this create
165 ## $1 - CIM Schema version to create in the #PEGASUS_ROOT/Schemas
166 ## directory (ex. 214)
167 ## $2 - Name of the DMTF CIM release zip file to install.
168 if (( $# < 2 )); then
169 karl 1.1 usage
170 exit 1
171 fi
172
173 CIM_SCHEMA_VER=${1:?"Error. CIM Version parameter required ex. 214"}
174 ZIP_FILE=${2:?"Error. Location of CIM MOF zip file required"}
175
176 SCHEMA_DIR=$PEGASUS_ROOT/Schemas/CIM${CIM_SCHEMA_VER}
177
178 ## confirm that the zip file exists. Error if not
179 if [ ! -e "$ZIP_FILE" ]; then
180 echo "The input MOF ZIP file $ZIP_FILE does not exist."
181 exit 1
182 fi
183
184 ## Check with user to be sure input was correct
185 choice "Create ${SCHEMA_DIR} from input file ${ZIP_FILE} [y/n]?"
186 if [ "$CHOICE" != "y" ]; then
187 echo "Terminating because user elected not to continue."
188 exit 1
189 fi
190 karl 1.1
191 ## if the schema directory exists, ask if we want to redo it.
192 ## Deletes the DMTF subdirectory and mof in the SCHEMA_DIR
193 if [ -a $SCHEMA_DIR ]; then
194 echo Schema directory $SCHEMA_DIR already exists.
195 choice "Replace existing Directory ${SCHEMA_DIR} [y/n]?"
196 if [ "$CHOICE" = "y" ]; then
197 rm -rf "$SCHEMA_DIR"
198 else
199 echo Terminating without changing Directory $SCHEMA_DIR MOF.
200 exit 1
201 fi
202 fi
203
204 mkdir "$SCHEMA_DIR" || { echo Unable to create $SCHEMA_DIR ; exit 4; }
205 cd $SCHEMA_DIR
206
207 ## Create DMTF directory and unzip the CIM release into this directory
208 mkdir DMTF
209
210 echo "Source $ZIP_FILE" >DMTFSchemaInfo.txt
211 karl 1.1
212 ## unzip because DMTF files zipped with pkzip or equivalent
213 unzip $ZIP_FILE -d DMTF
214
215 ##########################################################################
216 ##
217 ## Create the mof files
218 ##
219 ##########################################################################
220
221 #### create Core_Qualifiers.mof
222 CREATE_MOF_FILE Core_Qualifiers
223 INSERT_LINE Core_Qualifiers "#pragma include (\"DMTF/qualifiers.mof\")"
224 INSERT_LINE Core_Qualifiers "#pragma include (\"DMTF/qualifiers_optional.mof\")"
225 INSERT_BLANK_LINE Core_Qualifiers ;
226
227 #### create CIM_Schema.mof
228 CREATE_MOF_FILE CIM_Schema
229 INSERT_LINE CIM_Schema "#pragma include (\"DMTF/cimv${CIM_SCHEMA_VER}.mof\")"
230 INSERT_BLANK_LINE CIM_Schema ;
231
232 karl 1.1 #### create CIM_Core.mof
233 CREATE_MOF_FILE CIM_Core
234 INSERT_LINE CIM_Core "#pragma include (\"DMTF/qualifiers.mof\")" ;
235 INSERT_LINE CIM_Core "#pragma include (\"DMTF/qualifiers_optional.mof\")"
236 INSERT_BLANK_LINE CIM_Core ;
237 INSERT_EXTRACTED_INCLUDES CIM_Core Core ;
238 INSERT_BLANK_LINE CIM_Core ;
239
240
241 #### create CIM_Event.mof
242 CREATE_MOF_FILE CIM_Event
243 INSERT_EXTRACTED_INCLUDES CIM_Event Event ;
244 INSERT_BLANK_LINE CIM_Event ;
245
246
247 #### create CIM_Interop.mof
248 CREATE_MOF_FILE CIM_Interop
249 INSERT_EXTRACTED_INCLUDES CIM_Interop Interop ;
250 INSERT_BLANK_LINE CIM_Interop ;
251
252 ############################################################
253 karl 1.1 #### The following are required for the make testrepository
254
255 #### create CIM_Physical.mof
256 CREATE_MOF_FILE CIM_Physical
257 INSERT_EXTRACTED_INCLUDES CIM_Physical Physical ;
258 INSERT_BLANK_LINE CIM_Physical ;
259
260
261 #### create CIM_System.mof
262 CREATE_MOF_FILE CIM_System
263 INSERT_EXTRACTED_INCLUDES CIM_System System ;
264 INSERT_BLANK_LINE CIM_System ;
265
|