xref: /illumos-gate/usr/src/cmd/print/scripts/conv_lp (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate#!/bin/sh
2*7c478bd9Sstevel@tonic-gate#
3*7c478bd9Sstevel@tonic-gate# CDDL HEADER START
4*7c478bd9Sstevel@tonic-gate#
5*7c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*7c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
7*7c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
8*7c478bd9Sstevel@tonic-gate# with the License.
9*7c478bd9Sstevel@tonic-gate#
10*7c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*7c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
12*7c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
13*7c478bd9Sstevel@tonic-gate# and limitations under the License.
14*7c478bd9Sstevel@tonic-gate#
15*7c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
16*7c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*7c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
18*7c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
19*7c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
20*7c478bd9Sstevel@tonic-gate#
21*7c478bd9Sstevel@tonic-gate# CDDL HEADER END
22*7c478bd9Sstevel@tonic-gate#
23*7c478bd9Sstevel@tonic-gate#
24*7c478bd9Sstevel@tonic-gate# Copyright (c) 1994, 1995, 1996 by Sun Microsystems, Inc.
25*7c478bd9Sstevel@tonic-gate# All  Rights Reserved
26*7c478bd9Sstevel@tonic-gate#
27*7c478bd9Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate#
29*7c478bd9Sstevel@tonic-gate#	This script will automatically generate a "printcap" file
30*7c478bd9Sstevel@tonic-gate#	from the currently configured LP printer configuration.
31*7c478bd9Sstevel@tonic-gate#
32*7c478bd9Sstevel@tonic-gatePATH=/bin:/usr/bin:/usr/sbin
33*7c478bd9Sstevel@tonic-gate
34*7c478bd9Sstevel@tonic-gateTEXTDOMAIN="SUNW_OST_OSCMD"
35*7c478bd9Sstevel@tonic-gateexport TEXTDOMAIN
36*7c478bd9Sstevel@tonic-gate
37*7c478bd9Sstevel@tonic-gateexport PATH
38*7c478bd9Sstevel@tonic-gateumask 022
39*7c478bd9Sstevel@tonic-gate
40*7c478bd9Sstevel@tonic-gateset -- `getopt d:f: $*`
41*7c478bd9Sstevel@tonic-gateif [ $? != 0 ] ; then
42*7c478bd9Sstevel@tonic-gate	echo "Usage: $0 [-d dir] [-f file]"
43*7c478bd9Sstevel@tonic-gate	exit 1
44*7c478bd9Sstevel@tonic-gatefi
45*7c478bd9Sstevel@tonic-gate
46*7c478bd9Sstevel@tonic-gatefor OPTION in $*
47*7c478bd9Sstevel@tonic-gatedo
48*7c478bd9Sstevel@tonic-gate	case $OPTION in
49*7c478bd9Sstevel@tonic-gate	-f) SYSTEM_FILE=$2; shift 2;;
50*7c478bd9Sstevel@tonic-gate	-d) BASE_DIR=$2; shift 2;;
51*7c478bd9Sstevel@tonic-gate	--) shift; break;;
52*7c478bd9Sstevel@tonic-gate	esac
53*7c478bd9Sstevel@tonic-gatedone
54*7c478bd9Sstevel@tonic-gate
55*7c478bd9Sstevel@tonic-gateSYSTEM_FILE=${SYSTEM_FILE:-"${BASE_DIR}/etc/printers.conf"}
56*7c478bd9Sstevel@tonic-gate
57*7c478bd9Sstevel@tonic-gateif [ ! -d ${BASE_DIR}/etc/lp/printers ] ; then
58*7c478bd9Sstevel@tonic-gate	gettext "Exit $0: There is no directory ${BASE_DIR}/etc/lp/printers\n\tfrom which to create /etc/printers.conf."
59*7c478bd9Sstevel@tonic-gate	exit 0
60*7c478bd9Sstevel@tonic-gatefi
61*7c478bd9Sstevel@tonic-gate
62*7c478bd9Sstevel@tonic-gateif [ -f ${BASE_DIR}/etc/lp/default ] ; then
63*7c478bd9Sstevel@tonic-gate	DEFAULT_PRINTER=`cat ${BASE_DIR}/etc/lp/default`
64*7c478bd9Sstevel@tonic-gate	lpset -n system -a "use=${DEFAULT_PRINTER}" _default
65*7c478bd9Sstevel@tonic-gate	mv ${BASE_DIR}/etc/lp/default ${BASE_DIR}/etc/default.orig
66*7c478bd9Sstevel@tonic-gatefi
67*7c478bd9Sstevel@tonic-gate
68*7c478bd9Sstevel@tonic-gatecd ${BASE_DIR}/etc/lp/printers	# get the list of locally configured printers
69*7c478bd9Sstevel@tonic-gatePRINTERS=`echo *`
70*7c478bd9Sstevel@tonic-gate
71*7c478bd9Sstevel@tonic-gatefor PRINTER in ${PRINTERS}	# for each printer get config info
72*7c478bd9Sstevel@tonic-gatedo
73*7c478bd9Sstevel@tonic-gate    if [ "${PRINTER}" = "*" ] ; then
74*7c478bd9Sstevel@tonic-gate	continue
75*7c478bd9Sstevel@tonic-gate    fi
76*7c478bd9Sstevel@tonic-gate
77*7c478bd9Sstevel@tonic-gate    RNAME=${PRINTER}
78*7c478bd9Sstevel@tonic-gate    DESC=""
79*7c478bd9Sstevel@tonic-gate    RHOST=""
80*7c478bd9Sstevel@tonic-gate
81*7c478bd9Sstevel@tonic-gate    if [ -f ${PRINTER}/comment ] ; then
82*7c478bd9Sstevel@tonic-gate	    DESC=`cat ${PRINTER}/comment`
83*7c478bd9Sstevel@tonic-gate    fi
84*7c478bd9Sstevel@tonic-gate
85*7c478bd9Sstevel@tonic-gate    REMOTE=`grep Remote: ${PRINTER}/configuration 2>/dev/null | sed -e "s/^Remote: //"`
86*7c478bd9Sstevel@tonic-gate    DEVICE=`grep Device: ${PRINTER}/configuration 2>/dev/null | sed -e "s/^Device: //"`
87*7c478bd9Sstevel@tonic-gate
88*7c478bd9Sstevel@tonic-gate    if [ -n "${DEVICE}" ] ; then
89*7c478bd9Sstevel@tonic-gate	RHOST=`uname -n`
90*7c478bd9Sstevel@tonic-gate    elif [ `echo ${REMOTE} | grep -c \!` -ne 0 ] ; then
91*7c478bd9Sstevel@tonic-gate	RHOST=`echo $REMOTE | cut -d \! -f 1`
92*7c478bd9Sstevel@tonic-gate	RNAME=`echo $REMOTE | cut -d \! -f 2`
93*7c478bd9Sstevel@tonic-gate    else
94*7c478bd9Sstevel@tonic-gate	RHOST=${REMOTE}
95*7c478bd9Sstevel@tonic-gate    fi
96*7c478bd9Sstevel@tonic-gate
97*7c478bd9Sstevel@tonic-gate    lpset -n system -a "bsdaddr=${RHOST},${RNAME}" -a "description=${DESC}" \
98*7c478bd9Sstevel@tonic-gate	${PRINTER}
99*7c478bd9Sstevel@tonic-gate
100*7c478bd9Sstevel@tonic-gatedone
101*7c478bd9Sstevel@tonic-gate
102*7c478bd9Sstevel@tonic-gateexit 0
103