BUG#:8593
[tpot/pegasus.git.bak/pegasus.git] / mak / CreateDmtfSchema
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 ## Pegasus depends on a particular file structure for the schema to
18 ## build the CIM schemas that are compiled in the build and test
19 ## scripts.
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
28 ##      maintained.
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
32 ##      CIM_Schema.mof
33 ##      CIM_Event.mof
34 ##      CIM_Core.mof
35 ##      Core_Qualifiers.mof
36 ##      CIM_Interop.mof
37 ##
38 ##      CIM_Physical.mof
39 ##      CIM_Schema.mof
40 ##
41 ## The original DMTF CIM schema files are installed in Schemas/CIMxxx/DMTF
42 ##
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 
57 ##
58 ##   NOTE: If the Schema directory already exists the user is offered
59 ##         the option to replace the enitre directory.
60 ##
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.
69 ##
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"
76 ##         
77 ##########################################################################
78
79 ##########################################################################
80 ##
81 ## FUNCTION DEFINITIONS
82 ##
83 ##########################################################################
84
85 function usage {
86     echo $0
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
93     printf "                  DMTF.\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
98 }
99
100 ## INSERT_LICENSE ()
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.
104 ##
105 function INSERT_LICENSE {
106     FILE=$1 ;
107     cat "${PEGASUS_ROOT}/doc/license.txt" > ${FILE} ;
108 }
109
110 ## INSERT_BLANK_LINE ()
111 ## $1 filename w/o extensions
112 function INSERT_BLANK_LINE {
113     FILE=$1 ;
114     echo " " >> ${FILE}.mof ;
115 }
116
117 ## INSERT_LINE ()
118 ## Parameter 1 File to target w/o extension
119 ## Parameter 2 Text for line to insert
120 ##
121 function INSERT_LINE {
122     FILE=$1 ;
123     echo "$2" >> ${FILE}.mof ;
124 }
125
126 ## INSERT_EXTRACTED_INCLUDES ()
127 ##
128 ## copy all include lines for this file from $CIMSCHEMAVERSION.mof
129 ## changing them to add the DMTF directory.
130 ##
131 ## IE: The following line for the CIM_Core.mof file
132 ##
133 ##    #pragma include ("Core\CIM_ManagedElement.mof")
134 ##
135 ##     gets changed to the following:
136 ##
137 ##    #pragma include ("DMTF/Core\CIM_ManagedElement.mof")
138 ## Parameters
139 ##  $1   CIM version number for DMTF schema File to grep
140 ##  $2   Output to build w/o extension
141 ##
142 function INSERT_EXTRACTED_INCLUDES
143 {
144     FILE=$1 ;
145     NAME=$2 ;
146
147     grep "(\"${NAME}" DMTF/${SCHEMA_FILE_NAME}.mof | \
148         sed 's/include ("/include ("DMTF\//' >> ${FILE}.mof ;
149     return 0 ;
150 }
151
152 ## CREATE_MOF_FILE
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 {
157     NAME=$1 ;
158     FILE=${NAME}.mof
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" \
167          >> ${FILE}
168     echo "//              create DMTF CIM Schema Version ${CIM_SCHEMA_VER} " \
169          >> ${FILE}
170     echo "//              interface filesfiles compatible with OpenPegasus " \
171          >> ${FILE}
172     echo "//              build enviroment." >> ${FILE}
173     echo "//" >> ${FILE}
174     echo "//=====================================================" >> ${FILE}
175
176 INSERT_BLANK_LINE ${NAME} ;
177 }
178
179 ## Let user make choice.
180 ## called like: chice <prompt>
181 ## Returns: global variable choice with y / n or answer
182 function choice {
183     CHOICE=''
184     local prompt="$*"
185     local answer
186
187     read -p "$prompt" answer
188     case "$answer" in
189         [yY1] ) CHOICE='y';;
190         [nN0] ) CHOICE='n';;
191         *     ) CHOICE="$answer";;
192     esac
193 }  # end of choice function
194
195 #######################################################################
196 ##
197 ## Execute the script
198 ##
199 #######################################################################
200
201
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
211     usage
212     exit 1
213 fi
214
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"}
218
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"
222     echo 1
223 fi
224
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."
228     exit 1
229 fi
230
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."
235     exit 1
236 fi
237
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
244         rm -rf "$SCHEMA_DIR"
245     else
246         echo Terminating without changing Directory $SCHEMA_DIR MOF.
247         exit 1
248     fi
249 fi
250
251 mkdir "$SCHEMA_DIR" || { echo Unable to create $SCHEMA_DIR ; exit 4; }
252 cd $SCHEMA_DIR
253
254 ## Create DMTF directory and unzip the CIM release into this directory
255 mkdir DMTF
256
257 ## Put the original fileName into a file as a reference in the directory
258 echo "Source File: ${ZIP_FILE##*/}" >DMTFSchemaInfo.txt
259
260 ## unzip because DMTF files zipped with pkzip or equivalent
261 unzip $ZIP_FILE -d DMTF
262
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."
266     exit 1
267 fi
268
269 ##########################################################################
270 ##
271 ## Create the mof files
272 ##
273 ##########################################################################
274
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 ;
280
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 ;
285
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 ;
293
294
295 #### create CIM_Event.mof
296 CREATE_MOF_FILE CIM_Event
297 INSERT_EXTRACTED_INCLUDES CIM_Event Event ;
298 INSERT_BLANK_LINE CIM_Event ;
299
300
301 #### create CIM_Interop.mof
302 CREATE_MOF_FILE CIM_Interop
303 INSERT_EXTRACTED_INCLUDES CIM_Interop Interop ;
304 INSERT_BLANK_LINE CIM_Interop ;
305
306 ############################################################
307 #### The following are required for the make testrepository
308
309 #### create CIM_Physical.mof
310 CREATE_MOF_FILE CIM_Physical
311 INSERT_EXTRACTED_INCLUDES CIM_Physical Physical ;
312 INSERT_BLANK_LINE CIM_Physical ;
313
314
315 #### create CIM_System.mof
316 CREATE_MOF_FILE CIM_System
317 INSERT_EXTRACTED_INCLUDES CIM_System System ;
318 INSERT_BLANK_LINE CIM_System ;
319