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