2
0

udbToAny.ksh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. #!/bin/ksh
  2. # -------------------------------------------------------------
  3. # udbToAny.ksh
  4. #
  5. # This script was leveraged from "databaseConversionTool.ksh"
  6. # it should provide a superset of the functionality of that script;
  7. # however the primary motivation was to get away from the use of
  8. # multiple divergent parsers for the ".udb" style database. The
  9. # parser has been moved into an awk "library" file: udbParseLib.awk.
  10. # this parser can and should be used by all scripts wishing to parse
  11. # the ".udb" data bases.
  12. #
  13. # ----------------------------
  14. # new features:
  15. #
  16. # -toDB to convert to old mksubmit-style ".db" format
  17. # -toLst to convert to old domain-port-style ".lst" files
  18. # -toCustom <prt> to specify a print routine for a custom format
  19. # -custom <awklib> to specify a library containing custom print routines.
  20. # -udbParseLib <awkLib> to specify a library containing an alternate parser.
  21. # -mailTo <user> to specify an administrator who will receive mail
  22. # concerning parsing errors.
  23. #
  24. # -Database is now obsolete (although it will still work)
  25. # <udbfile> ... ... The script can now take multiple udb files (Only the
  26. # defaults specified in the first udb file will apply).
  27. #
  28. # ----------------------------
  29. #
  30. # This script converts a universal database to an
  31. # HP OSF style System Definition Database (SDD) file,
  32. # or a set of args suitable to supply to the Chelmsford deliver
  33. # tool, or a set of commands to build a delivery tree.
  34. # For more details, please refer to the "X11 and VUE for HP_OSF/1.0"
  35. # document.
  36. #
  37. # This script was leveraged (read hacked extensively) from
  38. # the "udbToDb" script by Jim Andreas. Ron Voll authored the
  39. # original "udbToDb" script.
  40. #
  41. # -------------------------------------------------------------
  42. # usage: databaseToSDD.ksh Option udbFile
  43. #
  44. # where Option is one of the following:
  45. #
  46. # -toDB convert a .udb to ".db" format
  47. # -toLst convert a .udb to ".lst" format
  48. # -toSDD convert a .udb to SDD format
  49. # -toDeliverArgs convert a .udb to args that the deliver tool likes
  50. # -toReleaseTree convert a .udb to a script to build a delivery tree
  51. # -toCheckBuild convert a .udb to a script to check the items in a build
  52. # -toFileList convert a .udb to a list of files for carbon units
  53. # -Machine specifies 3,7,8 for hp-ux releases
  54. # -ReleaseStream {hp-ux, osf, whatever}
  55. # -NoDefaults do not convert any records labeled default
  56. # -toTargetList convert a .udb to a list of target files in product tree
  57. # the leading path is stripped and just the target
  58. # file is left - for easy diffing with some other
  59. # version of a release
  60. # -custom <awkFile> Supply a custom "awk" print library
  61. # -toCustom <prt routine>
  62. # -udbParseLib <awkFile> Supply an alternate "awk" parser library
  63. # -------------------------------------------------------------
  64. # ConvertRoutine
  65. #
  66. # This ksh function invokes awk to do all of the dirty
  67. # work. The DoAction variable is consulted only in the
  68. # final stages of printing the desired info after the
  69. # .udb "phrases" are parsed.
  70. #
  71. # -------------------------------------------------------------
  72. ConvertRoutine()
  73. {
  74. #
  75. # set what we are going to do
  76. #
  77. typeset DoAction=$1
  78. #
  79. # set the "release stream" or token in a block in the .udb
  80. # file for which we will scan.
  81. #
  82. typeset BlockToken=$2
  83. #
  84. # and for HP-UX releases, the particular machine 68k/Snake/S800 3/7/8
  85. #
  86. typeset machine=$3
  87. #
  88. # set flag if default blocks are to be processed
  89. #
  90. typeset UseDefaultBlocks=$4
  91. shift
  92. shift
  93. shift
  94. shift
  95. AWK=/usr/bin/awk
  96. if [ -x /usr/bin/nawk ]; then
  97. AWK=/usr/bin/nawk
  98. fi
  99. #
  100. # Custom print routines may use the following parser variables:
  101. # defOrder[] --- An array containing the names of the fields in
  102. # a data base record (in the correct order).
  103. # NumEntries --- One MORE than the number of entries in the
  104. # "defOrder" array. This is the number of fields
  105. # in a data base record.
  106. # rec[] --- An associative array indexed by data base record
  107. # field name containing the value of the field.
  108. #
  109. # Assign custom print routines to be used for output. The default is to
  110. # use the "printDb" function associated with the library.
  111. #
  112. typeset PRT=printDb
  113. case "$DoAction" in
  114. toDB)
  115. PRT=printDb
  116. ;;
  117. toLst)
  118. PRT=printLst
  119. ;;
  120. toFileList|toTargetList|toCheckBuild|toReleaseTree|toDeliverArgs|toSDD)
  121. PRT=printGather;
  122. ;;
  123. toCustom)
  124. CUSTOM_PRINT="-f $CUSTOM_PRINT_LIB"
  125. PRT=$CUS_PRT
  126. ;;
  127. *) # Unknown Action
  128. echo "$0: Unknown Action>> \"$doAction\""
  129. exit 1;
  130. ;;
  131. esac
  132. cat > $TMPFILE <<EOF
  133. #
  134. # The function name "PRTREC" is used by the parsing routines
  135. # to do the output. By providing a custom output function you
  136. # can print the database any way you want. The default is to
  137. # use the "printRecord" function built defined in the awk file
  138. # containing the awk parser.
  139. #
  140. function PRTREC(rec) {
  141. $PRT(rec)
  142. }
  143. BEGIN {
  144. parseUdb()
  145. }
  146. {
  147. print "Getting New Line AWK style -- Problem?"
  148. exit 1
  149. }
  150. EOF
  151. #
  152. # Create a single awk file for use with the "-f" parameter.
  153. # IBM's awk only allows one "-f"
  154. #
  155. cat "$UDB_PARSE_LIB" >> $TMPFILE
  156. [ -z "$CUSTOM_PRINT" ] || cat "$CUSTOM_PRINT_LIB" >> $TMPFILE
  157. $AWK -v mailTo="$Administrator" \
  158. -v action="$DoAction" \
  159. -v BlockToken="$BlockToken" \
  160. -v Machine="$machine" \
  161. -v UseDefaultBlocks="$UseDefaultBlocks" \
  162. -v DeBugFile="$DEBUGFILE" \
  163. -v DeBug="$DEBUGLEVEL" \
  164. -f $TMPFILE $*
  165. #
  166. # Removed from parameter list because IBM's awk only allows one "-f"
  167. # $CUSTOM_PRINT \
  168. # -f "$UDB_PARSE_LIB" \
  169. #
  170. rm $TMPFILE
  171. }
  172. #
  173. # print a handy usage message to stderr (file descriptor 2 )
  174. #
  175. #
  176. usage()
  177. {
  178. exec >&2
  179. echo "$ScriptName: usage:"
  180. echo ""
  181. echo " $ScriptName [Options] <UdbFile> ..."
  182. echo ""
  183. echo " -toDB convert a .udb to \".db\" format"
  184. echo " -toLst convert a .udb to \".lst\" format"
  185. echo " -toSDD convert a .udb to SDD format"
  186. echo " -toDeliverArgs convert a .udb to args that the deliver tool likes"
  187. echo " -toReleaseTree convert a .udb to a script to build a delivery tree"
  188. echo " -toCheckBuild convert a .udb to a script to check a build"
  189. echo " -toFileList convert a .udb to a list of files"
  190. echo " -toTargetList convert a .udb to a list of product files"
  191. echo " -ReleaseStream {hp-ux, osf, whatever}"
  192. echo " -Machine specifies machine 3,7,8 for hp-ux"
  193. echo " -NoDefaults do not convert any records labeled \"default\""
  194. echo " -Database path (obsolete) specifies full path to the .udb file to convert"
  195. echo " -mailTo <user> Specify a user to receive mail on errors."
  196. echo " -toCustom <prt> Specify the name of a custom print routine."
  197. echo " -custom <awkFile> Supply a custom "awk" print library."
  198. echo " -udbParseLib <awkFile> Supply an alternate 'awk' parser library"
  199. exit 1
  200. }
  201. # OK, here is where we really start execution.
  202. # Check that the first argument defines what this script is
  203. # supposed to do:
  204. # Obscurity footprint-in-the-sand: "${1##*/}" is equivalent
  205. # to basename(1)
  206. #
  207. ScriptName=${0##*/}
  208. # -toSDD convert a .udb to SDD format
  209. # -toDeliverArgs convert a .udb to args that the deliver tool likes
  210. # -toReleaseTree convert a .udb to a script to build a delivery tree
  211. # -toCheckBuild convert a .udb to a script to check the items in a build
  212. if [ $# -le 3 ]; then
  213. usage $0
  214. fi
  215. typeset TakeDefaultBlocks="Y"
  216. typeset Administrator=""
  217. #typeset DBTOOLSRC=/x/toolsrc/dbTools
  218. typeset DBTOOLSRC=`dirname $0`
  219. typeset UDB_PARSE_LIB="$DBTOOLSRC/udbParseLib.awk"
  220. typeset CUSTOM_PRINT_LIB=""
  221. typeset DEBUGFILE="/dev/tty"
  222. typeset DEBUGLEVEL=0
  223. typeset TMPFILE=`mktemp /tmp/awkXXXXXXXXXXXXXXXXXXXXX`
  224. if [ $# -gt 2 ]; then
  225. while [ $# -gt 0 ]
  226. do
  227. case $1 in
  228. -NoDefaults)
  229. TakeDefaultBlocks=N
  230. shift
  231. continue
  232. ;;
  233. -toDB)
  234. Action=toDB
  235. shift;
  236. continue;
  237. ;;
  238. -toLst)
  239. Action=toLst
  240. shift;
  241. continue;
  242. ;;
  243. -toSDD)
  244. Action=toSDD
  245. shift
  246. continue
  247. ;;
  248. -toDeliverArgs)
  249. Action=toDeliverArgs
  250. shift
  251. continue
  252. ;;
  253. -toReleaseTree)
  254. Action=toReleaseTree
  255. shift
  256. continue
  257. ;;
  258. -toCheckBuild)
  259. Action=toCheckBuild
  260. shift
  261. continue
  262. ;;
  263. -toTargetList)
  264. Action=toTargetList
  265. shift
  266. continue
  267. ;;
  268. -toFileList)
  269. Action=toFileList
  270. shift
  271. continue
  272. ;;
  273. -Machine)
  274. if [ "x$2" = "x" ]; then
  275. usage
  276. fi
  277. Machine=$2
  278. shift
  279. shift
  280. continue
  281. ;;
  282. -ReleaseStream)
  283. if [ "x$2" = "x" ]; then
  284. usage
  285. fi
  286. ReleaseStream=$2
  287. shift
  288. shift
  289. continue
  290. ;;
  291. -Database)
  292. if [ "x$2" = "x" ]; then
  293. usage
  294. fi
  295. if [ ! -r "$2" ]; then
  296. usage
  297. fi
  298. Database="$Database $2"
  299. shift
  300. shift
  301. continue
  302. ;;
  303. -udbParseLib) # specify alternate "awk" parser location
  304. if [ "x$2" = "x" ]; then
  305. usage
  306. fi
  307. if [ ! -r "$2" ]; then
  308. usage
  309. fi
  310. UDB_PARSE_LIB=$2
  311. shift
  312. shift
  313. continue
  314. ;;
  315. -toCustom) # specify custom "awk" print routines
  316. if [ "x$2" = "x" ]; then
  317. usage
  318. fi
  319. Action=toCustom
  320. CUS_PRT=$2
  321. shift
  322. shift
  323. continue
  324. ;;
  325. -custom) # specify custom "awk" print routines
  326. if [ "x$2" = "x" ]; then
  327. usage
  328. fi
  329. if [ ! -r "$2" ]; then
  330. usage
  331. fi
  332. CUSTOM_PRINT_LIB=$2
  333. shift
  334. shift
  335. continue
  336. ;;
  337. -mailTo) # specify an administrator who receives mail about errors.
  338. if [ "x$2" = "x" ]; then
  339. usage
  340. fi
  341. Administrator=$2
  342. shift
  343. shift
  344. continue
  345. ;;
  346. -DeBugFile) # specify a debug file and debug level for parser debug info
  347. if [ "x$2" = "x" ]; then
  348. usage
  349. fi
  350. if [ "x$3" = "x" ]; then
  351. usage
  352. fi
  353. DEBUGFILE=$2
  354. shift 2
  355. continue
  356. ;;
  357. -DeBugLevel) # specify a debug level for parser debug info
  358. if [ "x$2" = "x" ]; then
  359. usage
  360. fi
  361. if [ "x$3" = "x" ]; then
  362. usage
  363. fi
  364. DEBUGLEVEL=$2
  365. shift 2
  366. continue
  367. ;;
  368. -*)
  369. echo "unknown option: $1"
  370. echo ""
  371. usage
  372. exit 1;
  373. ;;
  374. *) if [ ! -r $1 ]; then
  375. usage
  376. fi
  377. Database="$Database $1"
  378. shift;
  379. ;;
  380. esac
  381. done
  382. fi
  383. if [ "$Action" = "toCustom" ]; then
  384. if [ -z "$CUSTOM_PRINT_LIB" ]; then
  385. echo "You Must specify an awk file containing the custom print routine \"$CUS_PRT\""
  386. exit 1;
  387. fi
  388. fi
  389. if [ "$Machine" = "" ]; then
  390. Machine=NA
  391. elif [ "$Machine" = "300" ]; then
  392. Machine="3"
  393. elif [ "$Machine" = "700" ]; then
  394. Machine="7"
  395. elif [ "$Machine" = "800" ]; then
  396. Machine="8"
  397. fi
  398. if [ "$ReleaseStream" = "" ]; then
  399. echo "$ScriptName: need to specify a -ReleaseStream" >&2
  400. exit 1
  401. fi
  402. if [ "$Database" = "" ]; then
  403. echo "$ScriptName: need to specify a -Database" >&2
  404. exit 1
  405. fi
  406. ConvertRoutine $Action $ReleaseStream $Machine $TakeDefaultBlocks $Database