1 #!/bin/bash 2 #==================================================================================================== 3 # 4 # Script Name: generateDMT 5 # 6 # General Description: This script controls the building/generation of all DMT data files. It takes 7 # care of unzipping the Dmt.zip file, running the DMTValidator, and then running 8 # the DMT Generation tool. 9 # 10 #==================================================================================================== 11 # Copyright (C) 2014 The Android Open Source Project 12 # 13 # Licensed under the Apache License, Version 2.0 (the "License"); 14 # you may not use this file except in compliance with the License. 15 # You may obtain a copy of the License at 16 # 17 # http://www.apache.org/licenses/LICENSE-2.0 18 # 19 # Unless required by applicable law or agreed to in writing, software 20 # distributed under the License is distributed on an "AS IS" BASIS, 21 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 22 # See the License for the specific language governing permissions and 23 # limitations under the License. 24 #==================================================================================================== 25 26 #set variables for the Flex 27 FLEX_SETTING_FILE="FlexEnvSetting" 28 if [ -f $FLEX_SETTING_FILE ] 29 then 30 source $FLEX_SETTING_FILE 31 fi 32 33 usage () { 34 echo "" 35 echo "=========================================================================================" 36 echo "" 37 echo "Usage of the new version: " 38 echo "" 39 echo " generateDMT [-output <dir path>]" 40 echo " [-fstab <file path>]" 41 echo " [-inipath <ini file(dir) path (P2K only)>]" 42 echo " [-debug]" 43 echo " [-ddfext]" 44 echo " [-dmt <path to Dmt directory>]" 45 echo " or" 46 echo " <file>.zip or <file>.dmts [<file1>.zip, <file2>.zip, ...]" 47 echo "" 48 echo "Where options are including:" 49 echo "" 50 echo " -output path to output 'treedata' directory" 51 echo " using current ('./treedata') if not set" 52 echo " -fstab path to fstab file" 53 echo " looking in the current ('.') directory" 54 echo " if not set" 55 echo " -inipath path to sysplugins.ini file(s) for P2K only." 56 echo " The required files will be converted to .c and .h" 57 echo " files if this parameter is presenting" 58 echo " -debug option to add output debug info from Gen java into" 59 echo " /tmp/java.run.out.<ProcessID>" 60 echo " -ddfext option to generate Extended DDF with values and" 61 echo " file DDFValues.txt with all possible values" 62 echo " -dmt path to Dmt directory." 63 echo " Use this option instead of Dmt.zip (not together)" 64 echo "" 65 echo "New version support as a data input both <file>.zip and <file>.dmts formats" 66 echo "" 67 echo "Samples:" 68 echo " ./generateDMT -fstab ../../settings/fstab -output abcd -dmt ../../settings/Dmt" 69 echo " ./generateDMT -fstab ../../settings/fstab -output abcd ../../settings/Dmt.zip (or more then one)" 70 echo " ./generateDMT -fstab ../../settings/fstab -output abcd ../../settings/Dmt.dmts (or more then one)" 71 echo "" 72 echo "Usage of the old version: " 73 echo " generateDMT <file>.zip [<dir path>]" 74 echo "" 75 echo "Option '-novalidation' use for developing only!!!" 76 echo "" 77 echo "==========================================================================================" 78 echo "" 79 } 80 81 #print out messages 82 printOut () { 83 if [ "$DEBUG" == "yes" ] 84 then 85 echo "$1" 86 fi 87 } 88 89 export LANG=en_US 90 export LANGVAR=en_US 91 unset LC_ALL 92 export LC_CTYPE="en_US.UTF-8" 93 94 # validate parameters 95 if [ "$#" -eq 0 ] 96 then 97 echo "" 98 echo "Error: Missing path to Dmt.zip file !!! " 99 echo "Use flag -h or --help for the help" 100 echo "" 101 exit 1 102 fi 103 104 # Do some checking on our environment - we need java & unzip present 105 if [ -z "$JAVA_HOME" ] 106 then 107 echo "Error: Environment variable JAVA_HOME must be set to jdk 1.4 and latest!" 108 exit 1 109 fi 110 111 JAVA_VERSION=`$JAVA_HOME/bin/java -version 2> /dev/stdout | grep ver | sed -e 's/.*\"\([1-9]\.[0-9][0-9]*\)\..*/\1/'` 112 if [ "$JAVA_VERSION" \< "1.4" ] 113 then 114 echo "Error: Java vesion is not correct" 115 echo "The tool supports java version from 1.4 and latest" 116 echo "Please set environment variable JAVA_HOME to the correct java version" 117 exit 1 118 fi 119 120 unzip > /dev/null 121 122 if [ "$?" -ne 0 ] 123 then 124 echo "Error: Couldn't find unzip - please install it, or put it on your PATH." 125 exit 1 126 fi 127 128 # Remove temporary ./Dmt if exists 129 if [ -d Dmt ] 130 then 131 rm -rf Dmt 132 fi 133 134 135 # Set default values for the required variables 136 FSTAB_FILE=fstab 137 OUTPUTDIR=./treedata 138 NOVALIDATION=no 139 DEBUG=no 140 OUT=null 141 DEBUG_INFO_DIR=/dev/null 142 #Provide Dmt directory instead of Dmt.zip 143 DMTDIR=Dmt 144 #Flag fo Gen tool to generate DDF 145 GENDDF=genddf 146 147 # Parse parameters 148 while [ $# -gt 1 ]; do 149 case "$1" in 150 -novalidation ) NOVALIDATION=yes; 151 printOut "No validation option has been set" 152 shift ;; 153 -debug ) DEBUG=yes 154 shift ;; 155 -ddfext ) GENDDF=genextddf 156 shift ;; 157 -output ) OUTPUTDIR=$2/treedata ; 158 printOut "OUTPUTDIR: $OUTPUTDIR" 159 shift 2 ;; 160 -fstab ) FSTAB_FILE=$2 ; 161 printOut "FSTAB_FILE: $FSTAB_FILE" 162 shift 2 ;; 163 -dmt ) DMTDIR=$2 ; 164 printOut "Dmt directiry has been provided: $DMTDIR" 165 shift 2 ;; 166 -inipath ) INI_PATH="-i $2" ; 167 printOut "INI_PATH: $INI_PATH" 168 shift 2 ;; 169 *.zip ) printOut "Unzipping file $1 ..."; 170 unzip -o $1 > /dev/null; 171 shift ;; 172 *.dmts ) printOut "Convert file $1 to dir Dmt ..."; 173 $JAVA_HOME/bin/java -classpath lib/GenTool.jar com.mot.dm.tool.DMTSTool -conversion "$1" . 174 shift ;; 175 esac 176 done 177 178 # parse the last argument, can be .zip or output directory( for old versions ) 179 case "$1" in 180 -h|--help ) usage 181 exit 1;; 182 -debug ) DEBUG=yes 183 shift ;; 184 -ddfext ) GENDDF=genextddf 185 shift ;; 186 *.zip ) printOut "Unzipping file $1 ..."; 187 unzip -o $1 > /dev/null; 188 shift ;; 189 *.dmts ) printOut "Convert file $1 to dir Dmt ..."; 190 $JAVA_HOME/bin/java -classpath lib/GenTool.jar com.mot.dm.tool.DMTSTool -conversion "$1" . 191 shift ;; 192 * ) 193 if [ "$DMTDIR" == "Dmt" ] 194 then 195 OUTPUTDIR=$1/treedata ; 196 printOut "OUTPUTDIR: $OUTPUTDIR" 197 fi 198 shift ;; 199 esac 200 201 # set output directory for Gen debug and for mv 202 if [ "$DEBUG" == "yes" ] 203 then 204 DEBUG_INFO_DIR=/tmp/java.run.out.$$ 205 printOut "Debug info can be found in the $DEBUG_INFO_DIR" 206 OUT=stdout 207 fi 208 209 # fstab is reduered file, test if fstab exists and readable 210 if [ ! -r $FSTAB_FILE ] 211 then 212 echo "Cannot find fstab file with path: $FSTAB_FILE" 213 echo "Cleaning up on abort..." 214 if [ -d Dmt ] 215 then 216 rm -rf Dmt 217 fi 218 rm -rf $OUTPUTDIR 219 exit 1 220 fi 221 222 # Remove output directory if exists 223 if [ -d "$OUTPUTDIR" ] 224 then 225 printOut "Removing output directory ..." 226 rm -rf $OUTPUTDIR 227 fi 228 229 mkdir -p $OUTPUTDIR/docs 230 231 #add support for the relative Dmt path 232 cd .. 233 if [ -d $DMTDIR ] 234 then 235 cd - 236 else 237 cd - 238 DMTDIR=`pwd`/$DMTDIR 239 if [ ! -d $DMTDIR ] 240 then 241 echo "Cannot find $DMTDIR" 242 exit 1 243 fi 244 fi 245 246 #file for the error messages 247 ERR_FILE=err_`whoami` 248 249 if [ "$NOVALIDATION" == "yes" ] 250 then 251 printOut "Attantion!!! DMT will be generated without validation!!!" 252 else 253 # Call the DMT Validator 254 printOut "Validating DMT structure..." 255 256 $JAVA_HOME/bin/java -classpath lib/GenTool.jar:lib/joda-time-1.1.jar:lib/jakarta-regexp-1.4.jar com.mot.dm.core.DMTValidator -d $DMTDIR 2> $ERR_FILE > $DEBUG_INFO_DIR 257 258 if [ $? -eq 1 ] 259 then 260 cat $ERR_FILE 2> /dev/null 261 262 printOut "Validation failed!!! Please fix the errors above before continuing..." 263 printOut "Cleaning up on abort..." 264 rm -f $ERR_FILE 2> /dev/null 265 rm -rf Dmt 2> /dev/null 266 rm -rf $OUTPUTDIR 2> /dev/null 267 exit 1 268 else 269 printOut "DMT validation passed..." 270 fi 271 fi 272 273 # Now call the Gen tool to build the tree data 274 printOut "Calling Gen tool to build tree data..." 275 276 $JAVA_HOME/bin/java -classpath lib/GenTool.jar:lib/joda-time-1.1.jar:lib/jakarta-regexp-1.4.jar com.mot.dm.core.Gen -d $DMTDIR -f $FSTAB_FILE $INI_PATH -gendoc -$GENDDF -sv 1.0 2> $ERR_FILE > $DEBUG_INFO_DIR 277 278 if [ $? -eq 1 ] 279 then 280 cat $ERR_FILE 2> /dev/null 281 282 printOut "Please fix the errors above before continuing..." 283 printOut "Cleaning up on abort..." 284 rm -f $ERR_FILE 2> /dev/null 285 rm -rf Dmt 2> /dev/null 286 rm -rf $OUTPUTDIR 2> /dev/null 287 rm -f *.*xml 2> /dev/null 288 rm -f *.html 2> /dev/null 289 rm -f acl.* 2> /dev/null 290 rm -f event.* 2> /dev/null 291 rm -f *.ddf 2> /dev/null 292 rm -f *.*mdf 2> /dev/null 293 rm -f ddfvalues.txt 2> /dev/null 294 if [ "$INI_PATH" != "" ] 295 then 296 rm -f *.c 2> /dev/null 297 rm -f *.h 2> /dev/null 298 fi 299 exit 1 300 fi 301 302 rm -f $ERR_FILE 2> /dev/null 303 304 # Cleanup our Dmt directory and move files to the output dir 305 printOut "Cleaning up..." 306 307 if [ -d Dmt ] 308 then 309 rm -rf Dmt 310 fi 311 312 mv -f *.xml $OUTPUTDIR 2> /dev/$OUT 313 mv -f *.wbxml $OUTPUTDIR 2> /dev/$OUT 314 mv -f *.html $OUTPUTDIR/docs 2> /dev/$OUT 315 mv -f acl.* $OUTPUTDIR 2> /dev/$OUT 316 mv -f event.* $OUTPUTDIR 2> /dev/$OUT 317 mv -f *.ddf $OUTPUTDIR 2> /dev/$OUT 318 mv -f *.*mdf* $OUTPUTDIR 2> /dev/$OUT 319 mv -f ddfvalues.txt $OUTPUTDIR 2> /dev/$OUT 320 cp -f $FSTAB_FILE $OUTPUTDIR 2> /dev/$OUT 321 if [ "$INI_PATH" != "" ] 322 then 323 mv -f *.c $OUTPUTDIR 324 mv -f *.h $OUTPUTDIR 325 fi 326 327 328