2 ###########################################################################
4 ## createschema script to create CIM Schema "interface" files:
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.
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.
17 ## Pegasus depends on a particular file structure for the schema to
18 ## build the CIM schemas that are compiled in the build and test
20 ## The characteristics are:
21 ## Directory for each schema normally named CIM<schema ver> where the
22 ## schema ver is the version of the schema without the period separators
23 ## thus CIM 222 represents CIM 2.22.0 and CIM2221 represents CIM 2.22.1
24 ## mof files in this directory for the major components of CIM as shown
25 ## below including Event, Core, etc. These are built by this script for
26 ## each new version of CIM Schema installed
27 ## Subdirectory named DMTF where the released DMTF mof is unzipped and
29 ## The following files are needed by Pegasus and will each include the
30 ## appropriate DMTF files.
31 ## In Schemas/CIMxxx where xxx is the schema directory
35 ## Core_Qualifiers.mof
41 ## The original DMTF CIM schema files are installed in Schemas/CIMxxx/DMTF
43 ## To use this script:
44 ## 1. Download the CIM schema MOF zip file from the DMTF web site
45 ## 2. Insure that $PEGASUS_ROOT is set
46 ## 3. run the script with the following options
47 ## a. parameter 1 the schema version (ex. 214)
48 ## b. parameter 2 is the location/name of the downloaded zip file.
49 ## c. parameter 3 is the name of the top level schema file without
50 ## the extension (.mof)
51 ## The 2nd and 3rd parameters implemented because somewhere between
52 ## 2.17 and 2.22 the zip file name AND the schema mof name
53 ## changed to a more complex naming. The schema zipfile name
54 ## became something like cim_schem_2.22.0Final-MOFS.zip and
55 ## the schema top level mof file became something like
56 ## cim_schema_2.22.0.zip
58 ## NOTE: If the Schema directory already exists the user is offered
59 ## the option to replace the enitre directory.
61 ## CURRENT ISSUES AND LIMITATIONS
62 ## 1. Intended for use with FINAL mof files. It does not make any
63 ## provisions for the experimental mof.
64 ## 2. This is a bash script and intended to be used only on systems
65 ## with the bash shell.
66 ## 3. Does not test to determne if the input schema version is valid
67 ## 4. Two manual updates need to be made in the generated OpenPegasus mofs,
68 ## since version 2.22 of the DMTF CIM Schema after running this script.
70 ## In CIM_Core.mof add the line:
71 ## #pragma include ("DMTF/Interop/CIM_Error.mof")
72 ## at the top of all other includes.
73 ## In CIM_System.mof add the line:
74 ## #pragma include ("DMTF/User/CIM_Credential.mof")
75 ## before the include of "DMTF/System/CIM_BIOSService.mof"
77 ##########################################################################
79 ##########################################################################
81 ## FUNCTION DEFINITIONS
83 ##########################################################################
87 printf "\nUsage: <cim version> <DMTF CIM mof file> <schema file name>\n" >&2
88 printf " where:\n" >&2
89 printf " cim version - version of cim to be used as directory name\n" >&2
90 printf " without separators ( ex. 222 or 221 )\n" >&2
91 printf " DMTF mof file-The file name and location of the zip file\n" >&2
92 printf " containing the mof files as downloaded from\n" >&2
94 printf " schema file name - The base name of the top level file from\n" >&2
95 printf " the DMTF zip file that contains the includes\n" >&2
96 printf " for all theother mof files\n" >&2
97 printf " Example: %s 222 ~/Desktop/cim_schema_2.22.0Final-MOFs.zip cim_schema_2.22.0\n" >&2
101 ## Insert the current Pegasus License into a new file
102 ## used for the new files we create to link the schema
103 ## This function creates the file.
105 function INSERT_LICENSE {
107 cat "${PEGASUS_ROOT}/doc/license.txt" > ${FILE} ;
110 ## INSERT_BLANK_LINE ()
111 ## $1 filename w/o extensions
112 function INSERT_BLANK_LINE {
114 echo " " >> ${FILE}.mof ;
118 ## Parameter 1 File to target w/o extension
119 ## Parameter 2 Text for line to insert
121 function INSERT_LINE {
123 echo "$2" >> ${FILE}.mof ;
126 ## INSERT_EXTRACTED_INCLUDES ()
128 ## copy all include lines for this file from $CIMSCHEMAVERSION.mof
129 ## changing them to add the DMTF directory.
131 ## IE: The following line for the CIM_Core.mof file
133 ## #pragma include ("Core\CIM_ManagedElement.mof")
135 ## gets changed to the following:
137 ## #pragma include ("DMTF/Core\CIM_ManagedElement.mof")
139 ## $1 CIM version number for DMTF schema File to grep
140 ## $2 Output to build w/o extension
142 function INSERT_EXTRACTED_INCLUDES
147 grep "(\"${NAME}" DMTF/${SCHEMA_FILE_NAME}.mof | \
148 sed 's/include ("/include ("DMTF\//' >> ${FILE}.mof ;
153 ## Creates the new mof file with name and filename
154 ## and inserts license and descriptive material
155 ## $1 = Name for mof file to create (without extension)
156 function CREATE_MOF_FILE {
159 local TODAY=$(date '+%m/%d/%Y')
160 INSERT_LICENSE ${FILE}
161 echo "// ====================================================" >> ${FILE}
162 echo "// Title : ${NAME} MOF" >> ${FILE}
163 echo "// Filename : ${NAME}.mof" >> ${FILE}
164 echo "// Version : CIM ${CIM_SCHEMA_VER}" >> ${FILE}
165 echo "// Date : ${TODAY}" >> ${FILE}
166 echo "// Description: This file was created by The OpenPegasus Group to" \
168 echo "// create DMTF CIM Schema Version ${CIM_SCHEMA_VER} " \
170 echo "// interface filesfiles compatible with OpenPegasus " \
172 echo "// build enviroment." >> ${FILE}
174 echo "//=====================================================" >> ${FILE}
176 INSERT_BLANK_LINE ${NAME} ;
179 ## Let user make choice.
180 ## called like: chice <prompt>
181 ## Returns: global variable choice with y / n or answer
187 read -p "$prompt" answer
191 * ) CHOICE="$answer";;
193 } # end of choice function
195 #######################################################################
197 ## Execute the script
199 #######################################################################
202 #######################################################################
203 ## Test and setup variables for this create
204 ## $1 - CIM Schema version to create in the #PEGASUS_ROOT/Schemas
205 ## directory (ex. 214)
206 ## $2 - Name of the DMTF CIM release zip file to install.
207 ## $3 - Name of the DMTF top level Schema file being installed. This file
208 ## will appear in the DMTF directory when the release mof file
209 ## is installed. This is the name only without file name extension.
210 if (( $# < 3 )); then
215 CIM_SCHEMA_VER=${1:?"Error. CIM Version parameter required ex. 214"}
216 ZIP_FILE=${2:?"Error. Name of CIM MOF zip file required"}
217 SCHEMA_FILE_NAME=${3:?"Error. Name on Top Level Schema file required"}
219 SCHEMA_DIR=$PEGASUS_ROOT/Schemas/CIM${CIM_SCHEMA_VER}
220 if [ ! -d "$PEGASUS_ROOT" ]; then
221 echo "PEGASUS_ROOT required to execute this script"
225 ## confirm that the zip file exists. Error if not
226 if [ ! -e "$ZIP_FILE" ]; then
227 echo "The input MOF ZIP file $ZIP_FILE does not exist."
231 ## Check with user to be sure input was correct
232 choice "Create ${SCHEMA_DIR} from input file ${ZIP_FILE} [y/n]?"
233 if [ "$CHOICE" != "y" ]; then
234 echo "Terminating because user elected not to continue."
238 ## if the schema directory exists, ask if we want to redo it.
239 ## Deletes the DMTF subdirectory and mof in the SCHEMA_DIR
240 if [ -a $SCHEMA_DIR ]; then
241 echo Schema directory $SCHEMA_DIR already exists.
242 choice "Replace existing Directory ${SCHEMA_DIR} [y/n]?"
243 if [ "$CHOICE" = "y" ]; then
246 echo Terminating without changing Directory $SCHEMA_DIR MOF.
251 mkdir "$SCHEMA_DIR" || { echo Unable to create $SCHEMA_DIR ; exit 4; }
254 ## Create DMTF directory and unzip the CIM release into this directory
257 ## Put the original fileName into a file as a reference in the directory
258 echo "Source File: ${ZIP_FILE##*/}" >DMTFSchemaInfo.txt
260 ## unzip because DMTF files zipped with pkzip or equivalent
261 unzip $ZIP_FILE -d DMTF
263 ## confirm that the zip file exists. Error if not
264 if [ ! -e "DMTF/$SCHEMA_FILE_NAME.mof" ]; then
265 echo "The schema mof file $SCHEMA_FILE_NAME.mof does not exist."
269 ##########################################################################
271 ## Create the mof files
273 ##########################################################################
275 #### create Core_Qualifiers.mof
276 CREATE_MOF_FILE Core_Qualifiers
277 INSERT_LINE Core_Qualifiers "#pragma include (\"DMTF/qualifiers.mof\")"
278 INSERT_LINE Core_Qualifiers "#pragma include (\"DMTF/qualifiers_optional.mof\")"
279 INSERT_BLANK_LINE Core_Qualifiers ;
281 #### create CIM_Schema.mof
282 CREATE_MOF_FILE CIM_Schema
283 INSERT_LINE CIM_Schema "#pragma include (\"DMTF/$SCHEMA_FILE_NAME.mof\")"
284 INSERT_BLANK_LINE CIM_Schema ;
286 #### create CIM_Core.mof
287 CREATE_MOF_FILE CIM_Core
288 INSERT_LINE CIM_Core "#pragma include (\"DMTF/qualifiers.mof\")" ;
289 INSERT_LINE CIM_Core "#pragma include (\"DMTF/qualifiers_optional.mof\")"
290 INSERT_BLANK_LINE CIM_Core ;
291 INSERT_EXTRACTED_INCLUDES CIM_Core Core ;
292 INSERT_BLANK_LINE CIM_Core ;
295 #### create CIM_Event.mof
296 CREATE_MOF_FILE CIM_Event
297 INSERT_EXTRACTED_INCLUDES CIM_Event Event ;
298 INSERT_BLANK_LINE CIM_Event ;
301 #### create CIM_Interop.mof
302 CREATE_MOF_FILE CIM_Interop
303 INSERT_EXTRACTED_INCLUDES CIM_Interop Interop ;
304 INSERT_BLANK_LINE CIM_Interop ;
306 ############################################################
307 #### The following are required for the make testrepository
309 #### create CIM_Physical.mof
310 CREATE_MOF_FILE CIM_Physical
311 INSERT_EXTRACTED_INCLUDES CIM_Physical Physical ;
312 INSERT_BLANK_LINE CIM_Physical ;
315 #### create CIM_System.mof
316 CREATE_MOF_FILE CIM_System
317 INSERT_EXTRACTED_INCLUDES CIM_System System ;
318 INSERT_BLANK_LINE CIM_System ;