2 XCOMM $XConsortium: dtprintegrate.src /main/5 1996/04/23 12:02:04 drk $
3 XCOMM ####################################################################
4 XCOMM ## File: dtprintegrate
6 XCOMM ## Default Location: /usr/dt/bin/dtprintegrate
8 XCOMM ## Purpose: Set up the desktop configuration files for
9 XCOMM ## the desktop components.
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.
15 XCOMM ## Invoked by: System administrators, either by hand or by means
16 XCOMM ## of the printer installation script.
18 XCOMM ## Product: @(#)Common Desktop Environment 1.0
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.
26 XCOMM ## Note: Please do not modify this file.
27 XCOMM ## Later product updates will overwrite this file.
29 XCOMM ####################################################################
32 XCOMM #################################################################
33 XCOMM ## Internal Globals
35 XCOMM ## Set default values.
37 COMMAND_NAME=dtprintegrate
39 ACTION_STUB_FILE=/usr/dt/appconfig/appmanager/C/Desktop_Apps/Dtcalc
41 base_icon_name="Fpprnt"
51 XCOMM #################################################################
54 XCOMM ## Do upfront processing.
56 XCOMM #################################################################
68 HASH Location for Print action files...
70 DEFAULT_FOLDER=/etc/dt/appconfig/appmanager/C/Printers
71 DTPRINTERFOLDER=${DTPRINTERFOLDER:-$DEFAULT_FOLDER}
73 if (( ${#DTUSERPRINTERFOLDER} ))
75 DTPRINTERFOLDER="$DTUSERPRINTERFOLDER"
78 if [ ! -d $DTPRINTERFOLDER ]
80 mkdir -p $DTPRINTERFOLDER > /dev/null 2>/dev/null
84 HASH Location for Print definition (*.dt) files...
86 DEFAULT_FOLDER=/etc/dt/appconfig/types/C
87 DTPRINTACTIONFOLDER=${DTPRINTACTIONFOLDER:-$DEFAULT_FOLDER}
89 if [ ! -d $DTPRINTACTIONFOLDER ]
91 mkdir -p $DTPRINTACTIONFOLDER > /dev/null 2>/dev/null
95 HASH Search path for printer icons...
97 DEFAULT_PATH=.,$HOME/.dt/icons,/usr/dt/appconfig/icons/C
98 DTPRINTICONPATH=${DTPRINTICONPATH:-$DEFAULT_PATH}
101 HASH Location for printer icons...
103 DEFAULT_FOLDER=/etc/dt/appconfig/icons/C
104 DTPRINTERICONFOLDER=${DTPRINTERICONFOLDER:-$DEFAULT_FOLDER}
109 database_file=${printer_name}.dt
111 databasefile_path=$DTPRINTACTIONFOLDER/$database_file
113 action_file=${printer_name}_Print
115 action_path=$DTPRINTERFOLDER/$action_file
118 XCOMM #################################################################
119 XCOMM ## CheckOptions()
121 XCOMM ## Check the options supplied in the command line
124 XCOMM #################################################################
127 if (( $printer_flag == "0" ))
129 HASH We require a printer specification
137 XCOMM #################################################################
138 XCOMM ## AddHelpFileContents
140 XCOMM ## Add the contents of the help file to $1
142 XCOMM #################################################################
143 AddHelpFileContents()
145 if [[ ! -r $help_file || ! -s $help_file ]]
148 print " Sorry--Unable to read the help file: "
149 print " \"$help_file\"."
152 if (( $verbose_flag ))
158 echo " DESCRIPTION \\" >> $databasefile_path
162 while read -u8 this_line
164 print $this_line " \\" >> $databasefile_path
166 print "**" >> $databasefile_path
171 XCOMM #################################################################
172 XCOMM ## MakeDatabaseFile()
174 XCOMM ## Make the *.dt file for the printer
176 XCOMM #################################################################
180 touch $databasefile_path > /dev/null 2>/dev/null
182 chmod +w $databasefile_path > /dev/null 2>/dev/null
184 if [[ ! -f $databasefile_path || ! -w $databasefile_path ]]
187 PrintCreateError "$DTPRINTACTIONFOLDER" "$database_file"
188 if (( $verbose_flag ))
196 HASH First, write the preamble for this *.dt file
199 echo "################################################################"
201 echo "# Actions and Datatypes for Printer \"$printer_name\""
203 echo "# Common Desktop Environment 1.0"
205 echo "# This file created by the \"dtprintegrate\" utility."
207 echo "# Date of integration: `date`. "
209 echo "################################################################"
211 ) > $databasefile_path
214 HASH Now, create the Print action for the printer
218 echo "ACTION ${printer_name}_Print"
221 echo " LABEL $printer_name"
222 echo " ICON ${base_icon_name}"
224 echo " WINDOW_TYPE NO_STDIO"
225 if (( destination_flag ))
227 echo " EXEC_STRING env LPDEST=$destination \\"
229 echo " EXEC_STRING env LPDEST=$printer_name \\"
232 echo " /usr/dt/bin/dtaction Print %(File)Arg_1%"
233 ) >> $databasefile_path
237 echo " DESCRIPTION $help_text" >> $databasefile_path
238 elif (( $helpfile_flag ))
240 AddHelpFileContents $databasefile_path
243 echo "}" >> $databasefile_path
246 HASH Next, create the print manager action for the printer
250 echo "ACTION ${printer_name}_Print"
254 echo " WINDOW_TYPE NO_STDIO"
255 if (( destination_flag ))
257 echo " EXEC_STRING env LPDEST=$destination \\"
259 echo " EXEC_STRING env LPDEST=$printer_name \\"
261 echo " /usr/dt/bin/dtaction Dtqueueinfo"
263 ) >> $databasefile_path
266 XCOMM #################################################################
268 XCOMM ## TraversePath()
270 XCOMM ## Parse a given search path, using comma (,) and colon (:) as
271 XCOMM ## delimiters. Pass each path element to another
274 XCOMM #################################################################
283 if [[ -n "$search_path" && -n "$dir_function" ]]; then
285 HASH look for colon and comma delimiters
288 set -A dir_array $search_path
289 while ((path<=${#dir_array[*]}-1)) ;do
290 $dir_function ${dir_array[$path]}
298 XCOMM #################################################################
300 XCOMM ## GetIconBaseName()
302 XCOMM ## Given a file name of the form "base.l.bm" where size
303 XCOMM ## can be ".l", ".m", ".s.", or ".t" and visual type can be
304 XCOMM ## ".bm" or ".pm", set $base_icon_name to just the base.
306 XCOMM #################################################################
309 base_icon_name=`basename $1 .bm`
310 base_icon_name=`basename $base_icon_name .pm`
311 base_icon_name=`basename $base_icon_name .l`
312 base_icon_name=`basename $base_icon_name .m`
313 base_icon_name=`basename $base_icon_name .s`
314 base_icon_name=`basename $base_icon_name .t`
317 XCOMM #################################################################
319 XCOMM ## DoTheActualIconCopy()
321 XCOMM ## Once we've determined the base name, and we've got the
322 XCOMM ## source icon directory ($1), then copy all the icons
323 XCOMM ## with the same base name into the destination $DTPRINTERICONFOLDER.
325 XCOMM #################################################################
326 DoTheActualIconCopy()
328 for i in $1/${base_icon_name}.*
332 simple_icon_name=${i##*/}
334 if [ -f $DTPRINTERICONFOLDER/$simple_icon_name ]
336 mv -f $DTPRINTERICONFOLDER/$simple_icon_name $DTPRINTERICONFOLDER/#$simple_icon_name
339 cp $i $DTPRINTERICONFOLDER
341 if (( $verbose_flag ))
343 print " Copied icon file $i "
344 print " to $DTPRINTERICONFOLDER."
350 XCOMM #################################################################
351 XCOMM ## CopyIconFiles()
353 XCOMM ## Given $icon_name, get its base name, ensure that
354 XCOMM ## the destination icon folder exists, and march down
355 XCOMM ## the icon path, looking for matching icons, and copying
356 XCOMM ## them to the destination folder.
358 XCOMM #################################################################
362 GetIconBaseName $icon_name
364 touch $DTPRINTERICONFOLDER/$icon_name.install > /dev/null 2>/dev/null
366 if [[ ! -f $DTPRINTERICONFOLDER/$icon_name.install ]]
369 PrintCreateError "$DTPRINTERICONFOLDER" "$DTPRINTERICONFOLDER/$icon_name.*"
370 if (( $verbose_flag ))
377 rm -f $DTPRINTERICONFOLDER/$icon_name.install
379 TraversePath "$DTPRINTICONPATH" DoTheActualIconCopy
381 XCOMM ## install default icon if none found above. ###
385 XCOMM #################################################################
386 XCOMM ## MakeActionFile()
388 XCOMM ## Make the Action file for the printer in the
389 XCOMM ## $DTPRINTERFOLDER
391 XCOMM #################################################################
395 touch $action_path > /dev/null 2>/dev/null
397 chmod +x $action_path > /dev/null 2>/dev/null
399 if [[ ! -f $action_path || ! -x $action_path ]]
402 PrintCreateError "$DTPRINTERFOLDER" "$action_file"
403 if (( $verbose_flag ))
410 if [ -x $ACTION_STUB_FILE ]
413 cp $ACTION_STUB_FILE "$action_path"
416 PrintCreateError "$DTPRINTERFOLDER" "$action_file"
417 if (( $verbose_flag ))
425 XCOMM #################################################################
426 XCOMM ## PrintStartLog()
428 XCOMM ## Print the start of the log
430 XCOMM #################################################################
432 print "$COMMAND_NAME..."
436 XCOMM #################################################################
437 XCOMM ## PrintEndLog()
439 XCOMM ## Print the values of the variables.
441 XCOMM #################################################################
443 print " DTPRINTACTIONFOLDER == $DTPRINTACTIONFOLDER"
445 print " DTPRINTERFOLDER == $DTPRINTERFOLDER"
447 if (( $failure_flag == 0 )) && (( $unintegrate_flag == 0))
449 print " Created one database file,"
450 print " \"$databasefile_path\","
451 print " and one action file, "
452 print " \"$action_path\"."
455 if (( $failure_flag ==0 ))
457 print "...successfully completed."
459 print "...completed UNsuccesfully."
464 XCOMM #################################################################
465 XCOMM ## PrintCreateError()
467 XCOMM ## Print an error message
469 XCOMM #################################################################
472 print " Sorry--Unable to create the file \"$2\" under subdirectory"
478 XCOMM #################################################################
479 XCOMM ## PrintUsage()
481 XCOMM ## Print a usage message.
483 XCOMM #################################################################
486 print "Usage: $COMMAND_NAME [-d <destination>] [-i <icon_name>]"
487 print " [-h <help_text> | -f <help_file>]"
488 print " [-r] [-u] [-v] printer_name"
490 print " <destination> specifies print destination known to the print"
491 print " <icon_name> specifies the icon to use to represent the printer"
492 print " <help_text> specifies the help text for the printer"
493 print " <help_file> specifies the help file for the printer"
494 print " -r forces reloading of the action database"
495 print " -u unintegrates the printer"
496 print " -v directs verbose messages to standard out"
497 print " printer_name specifies the printer name"
499 print " All parameters except \"<printer_name>\" are optional."
503 XCOMM #################################################################
504 XCOMM ## ReloadActions()
507 XCOMM #################################################################
510 HASH Shorten forms like "host:0.0" to "host"
512 display_host=${DISPLAY%:*}
513 display_host=${display_host%%.*}
516 HASH Shorten forms like "host.dom.com" to "host"
518 session_host=`uname -n`
519 session_host=${session_host%%.*}
521 if (( reloadactions_flag ))
524 HASH User wants to force reloading actions
526 if [[ -x /usr/dt/bin/dtaction && -n "$DISPLAY" ]]
528 /usr/dt/bin/dtaction ReloadActions
530 elif [[ "$display_host" = "$session_host" ]]
532 HASH Our session server is running on the desktop
535 if [ -x /usr/dt/bin/dtaction ]
537 /usr/dt/bin/dtaction ReloadActions
539 elif [[ -z "$display_host" && -n "$DISPLAY" ]]
542 HASH Covers the case in which the simple value ":0.0" is our $DISPLAY
544 if [ -x /usr/dt/bin/dtaction ]
546 /usr/dt/bin/dtaction ReloadActions
551 XCOMM #################################################################
552 XCOMM ## UnintegratePrinter()
555 XCOMM #################################################################
556 UnintegratePrinter() {
558 if [[ -f $action_path ]]
561 if (( verbose_flag ))
563 print " Removed one action file: "
564 print " \"$action_path\"."
568 if [[ -f $databasefile_path ]]
570 rm -fr $databasefile_path
571 if (( verbose_flag ))
573 print " Removed one database file:"
574 print " \"$databasefile_path\"."
581 XCOMM #################################################################
585 XCOMM #################################################################
590 XCOMM #################################################################
593 XCOMM ## Set up and call the routines
595 XCOMM #################################################################
610 while getopts d:f:h:i:ruv argument
613 d) destination=$OPTARG
615 HASH print the destination name is $destination.
626 r) reloadactions_flag=1
628 u) unintegrate_flag=1
639 ((shift_positions = OPTIND - 1))
641 if (( $shift_positions < $# ))
644 XCOMM We have at least one remaining non-switch command line argument
646 shift $shift_positions
648 HASH We assume that any remaining arguments constitute the
650 HASH At some later point, may want to parse a list of filenames.
657 XCOMM Time to get to work.
661 if (( $verbose_flag ))
668 if (( $unintegrate_flag ))
678 HASH Doing so will set the $base_icon_name for inclusion in the
679 HASH filetypes action definition
690 if (( $verbose_flag ))
697 XCOMM ######################### eof ##############################