xref: /onnv-gate/usr/src/cmd/print/scripts/conv_lp (revision 0:68f95e015346)
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#	This script will automatically generate a "printcap" file
30*0Sstevel@tonic-gate#	from the currently configured LP printer configuration.
31*0Sstevel@tonic-gate#
32*0Sstevel@tonic-gatePATH=/bin:/usr/bin:/usr/sbin
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gateTEXTDOMAIN="SUNW_OST_OSCMD"
35*0Sstevel@tonic-gateexport TEXTDOMAIN
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gateexport PATH
38*0Sstevel@tonic-gateumask 022
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gateset -- `getopt d:f: $*`
41*0Sstevel@tonic-gateif [ $? != 0 ] ; then
42*0Sstevel@tonic-gate	echo "Usage: $0 [-d dir] [-f file]"
43*0Sstevel@tonic-gate	exit 1
44*0Sstevel@tonic-gatefi
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gatefor OPTION in $*
47*0Sstevel@tonic-gatedo
48*0Sstevel@tonic-gate	case $OPTION in
49*0Sstevel@tonic-gate	-f) SYSTEM_FILE=$2; shift 2;;
50*0Sstevel@tonic-gate	-d) BASE_DIR=$2; shift 2;;
51*0Sstevel@tonic-gate	--) shift; break;;
52*0Sstevel@tonic-gate	esac
53*0Sstevel@tonic-gatedone
54*0Sstevel@tonic-gate
55*0Sstevel@tonic-gateSYSTEM_FILE=${SYSTEM_FILE:-"${BASE_DIR}/etc/printers.conf"}
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gateif [ ! -d ${BASE_DIR}/etc/lp/printers ] ; then
58*0Sstevel@tonic-gate	gettext "Exit $0: There is no directory ${BASE_DIR}/etc/lp/printers\n\tfrom which to create /etc/printers.conf."
59*0Sstevel@tonic-gate	exit 0
60*0Sstevel@tonic-gatefi
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gateif [ -f ${BASE_DIR}/etc/lp/default ] ; then
63*0Sstevel@tonic-gate	DEFAULT_PRINTER=`cat ${BASE_DIR}/etc/lp/default`
64*0Sstevel@tonic-gate	lpset -n system -a "use=${DEFAULT_PRINTER}" _default
65*0Sstevel@tonic-gate	mv ${BASE_DIR}/etc/lp/default ${BASE_DIR}/etc/default.orig
66*0Sstevel@tonic-gatefi
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gatecd ${BASE_DIR}/etc/lp/printers	# get the list of locally configured printers
69*0Sstevel@tonic-gatePRINTERS=`echo *`
70*0Sstevel@tonic-gate
71*0Sstevel@tonic-gatefor PRINTER in ${PRINTERS}	# for each printer get config info
72*0Sstevel@tonic-gatedo
73*0Sstevel@tonic-gate    if [ "${PRINTER}" = "*" ] ; then
74*0Sstevel@tonic-gate	continue
75*0Sstevel@tonic-gate    fi
76*0Sstevel@tonic-gate
77*0Sstevel@tonic-gate    RNAME=${PRINTER}
78*0Sstevel@tonic-gate    DESC=""
79*0Sstevel@tonic-gate    RHOST=""
80*0Sstevel@tonic-gate
81*0Sstevel@tonic-gate    if [ -f ${PRINTER}/comment ] ; then
82*0Sstevel@tonic-gate	    DESC=`cat ${PRINTER}/comment`
83*0Sstevel@tonic-gate    fi
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gate    REMOTE=`grep Remote: ${PRINTER}/configuration 2>/dev/null | sed -e "s/^Remote: //"`
86*0Sstevel@tonic-gate    DEVICE=`grep Device: ${PRINTER}/configuration 2>/dev/null | sed -e "s/^Device: //"`
87*0Sstevel@tonic-gate
88*0Sstevel@tonic-gate    if [ -n "${DEVICE}" ] ; then
89*0Sstevel@tonic-gate	RHOST=`uname -n`
90*0Sstevel@tonic-gate    elif [ `echo ${REMOTE} | grep -c \!` -ne 0 ] ; then
91*0Sstevel@tonic-gate	RHOST=`echo $REMOTE | cut -d \! -f 1`
92*0Sstevel@tonic-gate	RNAME=`echo $REMOTE | cut -d \! -f 2`
93*0Sstevel@tonic-gate    else
94*0Sstevel@tonic-gate	RHOST=${REMOTE}
95*0Sstevel@tonic-gate    fi
96*0Sstevel@tonic-gate
97*0Sstevel@tonic-gate    lpset -n system -a "bsdaddr=${RHOST},${RNAME}" -a "description=${DESC}" \
98*0Sstevel@tonic-gate	${PRINTER}
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gatedone
101*0Sstevel@tonic-gate
102*0Sstevel@tonic-gateexit 0
103