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