2
0

dtprintegrate.src 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. XCOMM!KORNSHELL
  2. XCOMM $XConsortium: dtprintegrate.src /main/5 1996/04/23 12:02:04 drk $
  3. XCOMM ####################################################################
  4. XCOMM ## File: dtprintegrate
  5. XCOMM ##
  6. XCOMM ## Default Location: /usr/dt/bin/dtprintegrate
  7. XCOMM ##
  8. XCOMM ## Purpose: Set up the desktop configuration files for
  9. XCOMM ## the desktop components.
  10. XCOMM ##
  11. XCOMM ## Description: This script is invoked as a means to create the
  12. XCOMM ## desktop configuration files for newly installed
  13. XCOMM ## printers on a given host.
  14. XCOMM ##
  15. XCOMM ## Invoked by: System administrators, either by hand or by means
  16. XCOMM ## of the printer installation script.
  17. XCOMM ##
  18. XCOMM ## Product: @(#)Common Desktop Environment 1.0
  19. XCOMM ##
  20. XCOMM ## (c) Copyright 1993, 1994 Hewlett-Packard Company
  21. XCOMM ## (c) Copyright 1993, 1994 International Business
  22. XCOMM ## Machines Corp.
  23. XCOMM ## (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  24. XCOMM ##
  25. XCOMM ##
  26. XCOMM ## Note: Please do not modify this file.
  27. XCOMM ## Later product updates will overwrite this file.
  28. XCOMM ##
  29. XCOMM ####################################################################
  30. #define HASH #
  31. XCOMM #################################################################
  32. XCOMM ## Internal Globals
  33. XCOMM ##
  34. XCOMM ## Set default values.
  35. XCOMM ##
  36. COMMAND_NAME=dtprintegrate
  37. ACTION_STUB_FILE=/usr/dt/appconfig/appmanager/C/Desktop_Apps/Dtcalc
  38. base_icon_name="Fpprnt"
  39. XCOMM
  40. XCOMM Return codes
  41. XCOMM
  42. USAGE_ERR=1
  43. CREATE_ERR=2
  44. XCOMM #################################################################
  45. XCOMM ## Initialize()
  46. XCOMM ##
  47. XCOMM ## Do upfront processing.
  48. XCOMM ##
  49. XCOMM #################################################################
  50. Initialize()
  51. {
  52. HASH
  53. HASH Location for Print action files...
  54. HASH
  55. DEFAULT_FOLDER=/etc/dt/appconfig/appmanager/C/Printers
  56. DTPRINTERFOLDER=${DTPRINTERFOLDER:-$DEFAULT_FOLDER}
  57. if (( ${#DTUSERPRINTERFOLDER} ))
  58. then
  59. DTPRINTERFOLDER="$DTUSERPRINTERFOLDER"
  60. fi
  61. if [ ! -d "$DTPRINTERFOLDER" ]
  62. then
  63. mkdir -p "$DTPRINTERFOLDER" > /dev/null 2>/dev/null
  64. fi
  65. HASH
  66. HASH Location for Print definition (*.dt) files...
  67. HASH
  68. DEFAULT_FOLDER=/etc/dt/appconfig/types/C
  69. DTPRINTACTIONFOLDER=${DTPRINTACTIONFOLDER:-$DEFAULT_FOLDER}
  70. if [ ! -d "$DTPRINTACTIONFOLDER" ]
  71. then
  72. mkdir -p "$DTPRINTACTIONFOLDER" > /dev/null 2>/dev/null
  73. fi
  74. HASH
  75. HASH Search path for printer icons...
  76. HASH
  77. DEFAULT_PATH=.,$HOME/.dt/icons,/usr/dt/appconfig/icons/C
  78. DTPRINTICONPATH=${DTPRINTICONPATH:-$DEFAULT_PATH}
  79. HASH
  80. HASH Location for printer icons...
  81. HASH
  82. DEFAULT_FOLDER=/etc/dt/appconfig/icons/C
  83. DTPRINTERICONFOLDER=${DTPRINTERICONFOLDER:-$DEFAULT_FOLDER}
  84. HASH
  85. HASH Other...
  86. HASH
  87. database_file=${printer_name}.dt
  88. databasefile_path=$DTPRINTACTIONFOLDER/$database_file
  89. action_file=${printer_name}_Print
  90. action_path=$DTPRINTERFOLDER/$action_file
  91. }
  92. XCOMM #################################################################
  93. XCOMM ## CheckOptions()
  94. XCOMM ##
  95. XCOMM ## Check the options supplied in the command line
  96. XCOMM ## interface
  97. XCOMM ##
  98. XCOMM #################################################################
  99. CheckOptions()
  100. {
  101. if (( printer_flag == "0" ))
  102. HASH
  103. HASH We require a printer specification
  104. HASH
  105. then
  106. PrintUsage
  107. Exit $USAGE_ERR
  108. fi
  109. }
  110. XCOMM #################################################################
  111. XCOMM ## AddHelpFileContents
  112. XCOMM ##
  113. XCOMM ## Add the contents of the help file to $1
  114. XCOMM ##
  115. XCOMM #################################################################
  116. AddHelpFileContents()
  117. {
  118. if [[ ! -r $help_file || ! -s $help_file ]]
  119. then
  120. print ""
  121. print " Sorry--Unable to read the help file: "
  122. print " \"$help_file\"."
  123. print ""
  124. failure_flag=1
  125. if (( verbose_flag ))
  126. then
  127. PrintEndLog
  128. fi
  129. Exit $CREATE_ERR
  130. fi
  131. echo " DESCRIPTION \\" >> "$databasefile_path"
  132. exec 8< "$help_file"
  133. while read -r -u8 this_line
  134. do
  135. print "$this_line" " \\" >> "$databasefile_path"
  136. done
  137. print "**" >> "$databasefile_path"
  138. exec 8<&-
  139. }
  140. XCOMM #################################################################
  141. XCOMM ## MakeDatabaseFile()
  142. XCOMM ##
  143. XCOMM ## Make the *.dt file for the printer
  144. XCOMM ##
  145. XCOMM #################################################################
  146. MakeDatabaseFile()
  147. {
  148. touch "$databasefile_path" > /dev/null 2>/dev/null
  149. chmod +w "$databasefile_path" > /dev/null 2>/dev/null
  150. if [[ ! -f $databasefile_path || ! -w $databasefile_path ]]
  151. then
  152. failure_flag=1
  153. PrintCreateError "$DTPRINTACTIONFOLDER" "$database_file"
  154. if (( verbose_flag ))
  155. then
  156. PrintEndLog
  157. fi
  158. Exit $CREATE_ERR
  159. fi
  160. HASH
  161. HASH First, write the preamble for this *.dt file
  162. HASH
  163. (
  164. echo "################################################################"
  165. echo "# "
  166. echo "# Actions and Datatypes for Printer \"$printer_name\""
  167. echo "# "
  168. echo "# Common Desktop Environment 1.0"
  169. echo "# "
  170. echo "# This file created by the \"dtprintegrate\" utility."
  171. echo "# "
  172. echo "# Date of integration: $(date). "
  173. echo "# "
  174. echo "################################################################"
  175. echo " "
  176. ) > "$databasefile_path"
  177. HASH
  178. HASH Now, create the Print action for the printer
  179. HASH
  180. (
  181. echo "ACTION ${printer_name}_Print"
  182. echo "{"
  183. echo " ARG_TYPE *"
  184. echo " LABEL $printer_name"
  185. echo " ICON ${base_icon_name}"
  186. echo " TYPE COMMAND"
  187. echo " WINDOW_TYPE NO_STDIO"
  188. if (( destination_flag ))
  189. then
  190. echo " EXEC_STRING env LPDEST=$destination \\"
  191. else
  192. echo " EXEC_STRING env LPDEST=$printer_name \\"
  193. fi
  194. echo " /usr/dt/bin/dtaction Print %(File)Arg_1%"
  195. ) >> "$databasefile_path"
  196. if (( help_flag ))
  197. then
  198. echo " DESCRIPTION $help_text" >> "$databasefile_path"
  199. elif (( helpfile_flag ))
  200. then
  201. AddHelpFileContents "$databasefile_path"
  202. fi
  203. echo "}" >> "$databasefile_path"
  204. HASH
  205. HASH Next, create the print manager action for the printer
  206. HASH
  207. (
  208. echo ""
  209. echo "ACTION ${printer_name}_Print"
  210. echo "{"
  211. echo " ARG_COUNT 0"
  212. echo " TYPE COMMAND"
  213. echo " WINDOW_TYPE NO_STDIO"
  214. if (( destination_flag ))
  215. then
  216. echo " EXEC_STRING env LPDEST=$destination \\"
  217. else
  218. echo " EXEC_STRING env LPDEST=$printer_name \\"
  219. fi
  220. echo " /usr/dt/bin/dtaction Dtqueueinfo"
  221. echo "}"
  222. ) >> "$databasefile_path"
  223. }
  224. XCOMM #################################################################
  225. XCOMM ##
  226. XCOMM ## TraversePath()
  227. XCOMM ##
  228. XCOMM ## Parse a given search path, using comma (,) and colon (:) as
  229. XCOMM ## delimiters. Pass each path element to another
  230. XCOMM ## function.
  231. XCOMM ##
  232. XCOMM #################################################################
  233. TraversePath ()
  234. {
  235. typeset -i path=0
  236. IFSsave=$IFS
  237. search_path=$1
  238. dir_function=$2
  239. if [[ -n "$search_path" && -n "$dir_function" ]]; then
  240. HASH
  241. HASH look for colon and comma delimiters
  242. HASH
  243. IFS=':,'
  244. set -A dir_array "$search_path"
  245. while ((path<=${#dir_array[*]}-1)) ;do
  246. $dir_function "${dir_array[$path]}"
  247. path=$((path+1))
  248. done
  249. else return
  250. fi
  251. IFS=$IFSsave
  252. }
  253. XCOMM #################################################################
  254. XCOMM ##
  255. XCOMM ## GetIconBaseName()
  256. XCOMM ##
  257. XCOMM ## Given a file name of the form "base.l.bm" where size
  258. XCOMM ## can be ".l", ".m", ".s.", or ".t" and visual type can be
  259. XCOMM ## ".bm" or ".pm", set $base_icon_name to just the base.
  260. XCOMM ##
  261. XCOMM #################################################################
  262. GetIconBaseName()
  263. {
  264. base_icon_name=$(basename "$1" .bm)
  265. base_icon_name=$(basename "$base_icon_name" .pm)
  266. base_icon_name=$(basename "$base_icon_name" .l)
  267. base_icon_name=$(basename "$base_icon_name" .m)
  268. base_icon_name=$(basename "$base_icon_name" .s)
  269. base_icon_name=$(basename "$base_icon_name" .t)
  270. }
  271. XCOMM #################################################################
  272. XCOMM ##
  273. XCOMM ## DoTheActualIconCopy()
  274. XCOMM ##
  275. XCOMM ## Once we've determined the base name, and we've got the
  276. XCOMM ## source icon directory ($1), then copy all the icons
  277. XCOMM ## with the same base name into the destination $DTPRINTERICONFOLDER.
  278. XCOMM ##
  279. XCOMM #################################################################
  280. DoTheActualIconCopy()
  281. {
  282. for i in $1/${base_icon_name}.*
  283. do
  284. if [ -f "$i" ]
  285. then
  286. simple_icon_name=${i##*/}
  287. if [ -f "$DTPRINTERICONFOLDER/$simple_icon_name" ]
  288. then
  289. mv -f "$DTPRINTERICONFOLDER/$simple_icon_name" "$DTPRINTERICONFOLDER/#$simple_icon_name"
  290. fi
  291. cp "$i" "$DTPRINTERICONFOLDER"
  292. if (( verbose_flag ))
  293. then
  294. print " Copied icon file $i "
  295. print " to $DTPRINTERICONFOLDER."
  296. fi
  297. fi
  298. done
  299. }
  300. XCOMM #################################################################
  301. XCOMM ## CopyIconFiles()
  302. XCOMM ##
  303. XCOMM ## Given $icon_name, get its base name, ensure that
  304. XCOMM ## the destination icon folder exists, and march down
  305. XCOMM ## the icon path, looking for matching icons, and copying
  306. XCOMM ## them to the destination folder.
  307. XCOMM ##
  308. XCOMM #################################################################
  309. CopyIconFiles()
  310. {
  311. GetIconBaseName "$icon_name"
  312. touch "$DTPRINTERICONFOLDER/$icon_name.install" > /dev/null 2>/dev/null
  313. if [[ ! -f $DTPRINTERICONFOLDER/$icon_name.install ]]
  314. then
  315. failure_flag=1
  316. PrintCreateError "$DTPRINTERICONFOLDER" "$DTPRINTERICONFOLDER/$icon_name.*"
  317. if (( verbose_flag ))
  318. then
  319. PrintEndLog
  320. fi
  321. Exit $CREATE_ERR
  322. fi
  323. rm -f "$DTPRINTERICONFOLDER/$icon_name.install"
  324. TraversePath "$DTPRINTICONPATH" DoTheActualIconCopy
  325. XCOMM ## install default icon if none found above. ###
  326. }
  327. XCOMM #################################################################
  328. XCOMM ## MakeActionFile()
  329. XCOMM ##
  330. XCOMM ## Make the Action file for the printer in the
  331. XCOMM ## $DTPRINTERFOLDER
  332. XCOMM ##
  333. XCOMM #################################################################
  334. MakeActionFile()
  335. {
  336. touch "$action_path" > /dev/null 2>/dev/null
  337. chmod +x "$action_path" > /dev/null 2>/dev/null
  338. if [[ ! -f $action_path || ! -x $action_path ]]
  339. then
  340. failure_flag=1
  341. PrintCreateError "$DTPRINTERFOLDER" "$action_file"
  342. if (( verbose_flag ))
  343. then
  344. PrintEndLog
  345. fi
  346. Exit $CREATE_ERR
  347. fi
  348. if [ -x $ACTION_STUB_FILE ]
  349. then
  350. cp $ACTION_STUB_FILE "$action_path"
  351. else
  352. failure_flag=1
  353. PrintCreateError "$DTPRINTERFOLDER" "$action_file"
  354. if (( verbose_flag ))
  355. then
  356. PrintEndLog
  357. fi
  358. Exit $CREATE_ERR
  359. fi
  360. }
  361. XCOMM #################################################################
  362. XCOMM ## PrintStartLog()
  363. XCOMM ##
  364. XCOMM ## Print the start of the log
  365. XCOMM ##
  366. XCOMM #################################################################
  367. PrintStartLog() {
  368. print "$COMMAND_NAME..."
  369. print ""
  370. }
  371. XCOMM #################################################################
  372. XCOMM ## PrintEndLog()
  373. XCOMM ##
  374. XCOMM ## Print the values of the variables.
  375. XCOMM ##
  376. XCOMM #################################################################
  377. PrintEndLog() {
  378. print " DTPRINTACTIONFOLDER == $DTPRINTACTIONFOLDER"
  379. print ""
  380. print " DTPRINTERFOLDER == $DTPRINTERFOLDER"
  381. print ""
  382. if (( failure_flag == 0 )) && (( unintegrate_flag == 0))
  383. then
  384. print " Created one database file,"
  385. print " \"$databasefile_path\","
  386. print " and one action file, "
  387. print " \"$action_path\"."
  388. print ""
  389. fi
  390. if (( failure_flag ==0 ))
  391. then
  392. print "...successfully completed."
  393. else
  394. print "...completed UNsuccessfully."
  395. fi
  396. print ""
  397. }
  398. XCOMM #################################################################
  399. XCOMM ## PrintCreateError()
  400. XCOMM ##
  401. XCOMM ## Print an error message
  402. XCOMM ##
  403. XCOMM #################################################################
  404. PrintCreateError() {
  405. print ""
  406. print " Sorry--Unable to create the file \"$2\" under subdirectory"
  407. print " \"$1\"."
  408. print ""
  409. failure_flag=1
  410. }
  411. XCOMM #################################################################
  412. XCOMM ## PrintUsage()
  413. XCOMM ##
  414. XCOMM ## Print a usage message.
  415. XCOMM ##
  416. XCOMM #################################################################
  417. PrintUsage() {
  418. print ""
  419. print "Usage: $COMMAND_NAME [-d <destination>] [-i <icon_name>]"
  420. print " [-h <help_text> | -f <help_file>]"
  421. print " [-r] [-u] [-v] printer_name"
  422. print " where:"
  423. print " <destination> specifies print destination known to the print"
  424. print " <icon_name> specifies the icon to use to represent the printer"
  425. print " <help_text> specifies the help text for the printer"
  426. print " <help_file> specifies the help file for the printer"
  427. print " -r forces reloading of the action database"
  428. print " -u unintegrates the printer"
  429. print " -v directs verbose messages to standard out"
  430. print " printer_name specifies the printer name"
  431. print ""
  432. print " All parameters except \"<printer_name>\" are optional."
  433. print ""
  434. }
  435. XCOMM #################################################################
  436. XCOMM ## ReloadActions()
  437. XCOMM ##
  438. XCOMM ##
  439. XCOMM #################################################################
  440. ReloadActions() {
  441. HASH
  442. HASH Shorten forms like "host:0.0" to "host"
  443. HASH
  444. display_host=${DISPLAY%:*}
  445. display_host=${display_host%%.*}
  446. HASH
  447. HASH Shorten forms like "host.dom.com" to "host"
  448. HASH
  449. session_host=$(uname -n)
  450. session_host=${session_host%%.*}
  451. if (( reloadactions_flag ))
  452. then
  453. HASH
  454. HASH User wants to force reloading actions
  455. HASH
  456. if [[ -x /usr/dt/bin/dtaction && -n "$DISPLAY" ]]
  457. then
  458. /usr/dt/bin/dtaction ReloadActions
  459. fi
  460. elif [[ "$display_host" = "$session_host" ]]
  461. HASH
  462. HASH Our session server is running on the desktop
  463. HASH
  464. then
  465. if [ -x /usr/dt/bin/dtaction ]
  466. then
  467. /usr/dt/bin/dtaction ReloadActions
  468. fi
  469. elif [[ -z "$display_host" && -n "$DISPLAY" ]]
  470. then
  471. HASH
  472. HASH Covers the case in which the simple value ":0.0" is our $DISPLAY
  473. HASH
  474. if [ -x /usr/dt/bin/dtaction ]
  475. then
  476. /usr/dt/bin/dtaction ReloadActions
  477. fi
  478. fi
  479. }
  480. XCOMM #################################################################
  481. XCOMM ## UnintegratePrinter()
  482. XCOMM ##
  483. XCOMM ##
  484. XCOMM #################################################################
  485. UnintegratePrinter() {
  486. if [[ -f $action_path ]]
  487. then
  488. rm -fr "$action_path"
  489. if (( verbose_flag ))
  490. then
  491. print " Removed one action file: "
  492. print " \"$action_path\"."
  493. fi
  494. fi
  495. if [[ -f $databasefile_path ]]
  496. then
  497. rm -fr "$databasefile_path"
  498. if (( verbose_flag ))
  499. then
  500. print " Removed one database file:"
  501. print " \"$databasefile_path\"."
  502. print ""
  503. fi
  504. fi
  505. }
  506. XCOMM #################################################################
  507. XCOMM ## Exit()
  508. XCOMM ##
  509. XCOMM ##
  510. XCOMM #################################################################
  511. Exit() {
  512. exit "$1"
  513. }
  514. XCOMM #################################################################
  515. XCOMM ## Main()
  516. XCOMM ##
  517. XCOMM ## Set up and call the routines
  518. XCOMM ##
  519. XCOMM #################################################################
  520. printer_name=""
  521. printer_flag=0
  522. help_flag=0
  523. helpfile_flag=0
  524. icon_flag=0
  525. verbose_flag=0
  526. unintegrate_flag=0
  527. failure_flag=0
  528. destination_flag=0
  529. destination=""
  530. reloadactions_flag=0
  531. while getopts d:f:h:i:ruv argument
  532. do
  533. case $argument in
  534. d) destination=$OPTARG
  535. destination_flag=1
  536. HASH print the destination name is $destination.
  537. ;;
  538. f) help_file=$OPTARG
  539. helpfile_flag=1
  540. ;;
  541. h) help_text=$OPTARG
  542. help_flag=1
  543. ;;
  544. i) icon_name=$OPTARG
  545. icon_flag=1
  546. ;;
  547. r) reloadactions_flag=1
  548. ;;
  549. u) unintegrate_flag=1
  550. ;;
  551. v) verbose_flag=1
  552. ;;
  553. \?)
  554. PrintUsage
  555. Exit 1
  556. ;;
  557. esac
  558. done
  559. ((shift_positions = OPTIND - 1))
  560. if (( shift_positions < $# ))
  561. then
  562. XCOMM
  563. XCOMM We have at least one remaining non-switch command line argument
  564. XCOMM
  565. shift $shift_positions
  566. HASH
  567. HASH We assume that any remaining arguments constitute the
  568. HASH filename.
  569. HASH At some later point, may want to parse a list of filenames.
  570. HASH
  571. printer_name=$*
  572. printer_flag=1
  573. fi
  574. XCOMM
  575. XCOMM Time to get to work.
  576. XCOMM
  577. Initialize
  578. if (( verbose_flag ))
  579. then
  580. PrintStartLog
  581. fi
  582. CheckOptions
  583. if (( unintegrate_flag ))
  584. then
  585. UnintegratePrinter
  586. else
  587. if (( icon_flag ))
  588. then
  589. CopyIconFiles
  590. HASH Doing so will set the $base_icon_name for inclusion in the
  591. HASH filetypes action definition
  592. fi
  593. MakeDatabaseFile
  594. MakeActionFile
  595. ReloadActions
  596. fi
  597. if (( verbose_flag ))
  598. then
  599. PrintEndLog
  600. fi
  601. Exit 0
  602. XCOMM ######################### eof ##############################