1 #!/bin/sh
   2 #
   3 # CDDL HEADER START
   4 #
   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License, Version 1.0 only
   7 # (the "License").  You may not use this file except in compliance
   8 # with the License.
   9 #
  10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  11 # or http://www.opensolaris.org/os/licensing.
  12 # See the License for the specific language governing permissions
  13 # and limitations under the License.
  14 #
  15 # When distributing Covered Code, include this CDDL HEADER in each
  16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  17 # If applicable, add the following below this CDDL HEADER, with the
  18 # fields enclosed by brackets "[]" replaced with your own identifying
  19 # information: Portions Copyright [yyyy] [name of copyright owner]
  20 #
  21 # CDDL HEADER END
  22 #
  23 #
  24 # Copyright (c) 1994, 1995, 1996 by Sun Microsystems, Inc.
  25 # All Rights Reserved
  26 #
  27 #  Printcap <-> Printers.conf conversion utility...
  28 #
  29 #       Usage: conv_lpd [ -c (printers|printcap) ] [ -n ] (file)
  30 #
  31 
  32 TEXTDOMAIN="SUNW_OST_OSCMD"
  33 export TEXTDOMAIN
  34 
  35 USAGE=`gettext "Usage: conv_lpd [ -c (printers|printcap) ] [ -n ] (file)\n"`
  36 
  37 PATH=/usr/bin:/bin:/usr/sbin export PATH
  38 conversion="printers"
  39 namelist=0
  40 
  41 umask 022
  42 
  43 for i in $*
  44 do
  45         case $1 in
  46                 -c*)
  47                         conversion=$2;
  48                         shift ; shift ;
  49                 ;;
  50                 -n*)
  51                         namelist=1;
  52                         shift ;
  53                 ;;
  54                 *)
  55                         break ;
  56                 ;;
  57         esac
  58 done
  59 
  60 TMPF1=/tmp/tinput1.$$
  61 TMPF2=/tmp/tinput2.$$
  62 FILE=/tmp/input.$$
  63 
  64 # Any remaining arg is the "file" specification.  It is a required arg.
  65 if [ -z "$1" ]; then
  66         echo $USAGE
  67         exit 1
  68 else
  69         cp $1 $TMPF1
  70 fi
  71 
  72 echo  >>$TMPF1
  73 echo "_done" >>$TMPF1
  74 
  75 #
  76 # First, strip all continuation characters, leaving one, single line
  77 # for each printer entry.
  78 #
  79         CONV_FIX=/usr/lib/print/conv_fix
  80 
  81         if [ -f $CONV_FIX ]; then
  82                 $CONV_FIX -f $TMPF1 -o $TMPF2
  83                 if [ $? != 0 ]; then
  84                         echo "$0:"
  85                         gettext "Fatal Error: $CONV_FIX failed.\n"
  86                         gettext "Please contact your Sun support representative.\n"
  87                         exit 1
  88                 fi
  89         else
  90                 gettext "$0: Fatal: Cannot locate $CONV_FIX binary.\n"
  91                 gettext "Please contact your Sun support representative.\n"
  92                 exit 1
  93         fi
  94 
  95 #
  96 # Continuation characters are now stripped.  Continue processing.
  97 #
  98         /bin/sed -e "s/:[       ]*:/:/g" $TMPF2 > $FILE
  99 
 100 #
 101 # Empty colons ":[ <TAB>]*:" are now stripped.  Continue processing.
 102 #
 103 
 104 /usr/xpg4/bin/awk '
 105 BEGIN {
 106         "uname -n" | getline ; 
 107         host = $0 ;
 108         found = 0 ;
 109         local_pr = 0;
 110 }
 111 
 112 {
 113         FS=":"; OFS=":" ;
 114         if ($0 !~ /^#/)
 115          {
 116                         if ($0 ~ /^[_a-zA-Z0-9_]/) {     # New entry
 117                                 if ( found != 0 ) {
 118                                     if ( "'$namelist'" == 1 )
 119                                         printer = names ;
 120                                     else
 121                                         printer = name[1] ;
 122 
 123                                     if ( "'$conversion'" == "printers" ) {
 124                                         printf "\n%s:", names ;
 125                                         for (key in values) {
 126                                                 if ((key != "rp") &&
 127                                                     (key != "rm")) {
 128                                                 printf "\\\n\t:%s=%s:", 
 129                                                         key, values[key] ;
 130                                                 delete values[key];
 131                                                 }
 132                                         }
 133                                         if (values["rm"] != "") {
 134                                                 printf "\\\n\t:bsdaddr=%s,%s:", \
 135                                                         values["rm"], \
 136                                                         values["rp"] ;
 137                                                 if (values["rm"] == host) local_pr++;
 138                                         } else {
 139                                                 printf "\\\n\t:bsdaddr=%s,%s:", \
 140                                                         host, printer ;
 141                                                 local_pr++;
 142                                         }
 143                                         delete values["rp"];
 144                                         delete values["rm"];
 145                                     } else {
 146                                         printf "\n%s:", names ;
 147                                         for (key in values) {
 148                                                 if (key == "bsdaddr") {
 149                                                         split(values[key],
 150                                                                 pair, ",");
 151                                                         printf "\\\n\t:%s=%s:", \
 152                                                                 "rm", pair[1] ;
 153                                                         if (pair[2] == "")
 154                                                                 pair[2] = printer;
 155                                                         printf "\\\n\t:%s=%s:", \
 156                                                                 "rp", pair[2] ;
 157                                                         
 158                                                 } else if ((key == "br") || \
 159                                                            (key == "fc") || \
 160                                                            (key == "fs") || \
 161                                                            (key == "mc") || \
 162                                                            (key == "mx") || \
 163                                                            (key == "pc") || \
 164                                                            (key == "pl") || \
 165                                                            (key == "pw") || \
 166                                                            (key == "px") || \
 167                                                            (key == "py") || \
 168                                                            (key == "xc") || \
 169                                                            (key == "xs"))
 170                                                         printf "\\\n\t:%s#%s:", \
 171                                                                 key, \
 172                                                                 values[key] ;
 173                                                 else if (values[key] == "true")
 174                                                         printf "\\\n\t:%s:", \
 175                                                                 key ;
 176                                                 else if (values[key] != "false")
 177                                                         printf "\\\n\t:%s=%s:", \
 178                                                                 key, \
 179                                                                 values[key] ;
 180                                                 delete values[key];
 181                                         }
 182                                     }
 183                                 }
 184                                 split( $1, name, "|");
 185                                 names = $1 ;
 186                                 found++;
 187                         }
 188 
 189                         for ( i = 1 ; i <= NF ; i++ ) {
 190                                 if (($i == names) || ($i == "") || \
 191                                     ($i == "\t"))
 192                                         continue ;
 193                                 if ((split( $i, pair, "=" ) != 2) && \
 194                                     (split( $i, pair, "\#") != 2))
 195                                         pair[2] = "true";
 196                                 
 197                                 if (pair[1] != "" && pair[1] != "       ")
 198                                         values[pair[1]] = pair[2] ;
 199                         }
 200         }
 201 }
 202 END {
 203          printf "\n" ;
 204          if (local_pr != 0)
 205                  printf  "One or more printers are local, you may want to run lpadmin to configure LP server side operation\n" | "cat 1>&2" ;
 206 
 207 }' ${FILE}
 208 
 209 /bin/rm -f ${TMPF1} ${TMP2} ${FILE}
 210 
 211 exit 0