summaryrefslogtreecommitdiff
path: root/usr/src/cmd/print/scripts/conv_lp
blob: 286ba6f682d5c32d96cef3569354b2a978069fdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License").  You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 1994, 1995, 1996 by Sun Microsystems, Inc.
# All  Rights Reserved
#
# ident	"%Z%%M%	%I%	%E% SMI"
#
#	This script will automatically generate a "printcap" file
#	from the currently configured LP printer configuration.
#
PATH=/bin:/usr/bin:/usr/sbin

TEXTDOMAIN="SUNW_OST_OSCMD"
export TEXTDOMAIN

export PATH
umask 022

set -- `getopt d:f: $*`
if [ $? != 0 ] ; then
	echo "Usage: $0 [-d dir] [-f file]"
	exit 1
fi

for OPTION in $*
do
	case $OPTION in
	-f) SYSTEM_FILE=$2; shift 2;;
	-d) BASE_DIR=$2; shift 2;;
	--) shift; break;;
	esac
done

SYSTEM_FILE=${SYSTEM_FILE:-"${BASE_DIR}/etc/printers.conf"}

if [ ! -d ${BASE_DIR}/etc/lp/printers ] ; then
	gettext "Exit $0: There is no directory ${BASE_DIR}/etc/lp/printers\n\tfrom which to create /etc/printers.conf."
	exit 0
fi

if [ -f ${BASE_DIR}/etc/lp/default ] ; then
	DEFAULT_PRINTER=`cat ${BASE_DIR}/etc/lp/default`
	lpset -n system -a "use=${DEFAULT_PRINTER}" _default
	mv ${BASE_DIR}/etc/lp/default ${BASE_DIR}/etc/default.orig
fi

cd ${BASE_DIR}/etc/lp/printers	# get the list of locally configured printers
PRINTERS=`echo *`

for PRINTER in ${PRINTERS}	# for each printer get config info
do
    if [ "${PRINTER}" = "*" ] ; then
	continue
    fi

    RNAME=${PRINTER}
    DESC=""
    RHOST=""

    if [ -f ${PRINTER}/comment ] ; then
	    DESC=`cat ${PRINTER}/comment`
    fi

    REMOTE=`grep Remote: ${PRINTER}/configuration 2>/dev/null | sed -e "s/^Remote: //"`
    DEVICE=`grep Device: ${PRINTER}/configuration 2>/dev/null | sed -e "s/^Device: //"`

    if [ -n "${DEVICE}" ] ; then
	RHOST=`uname -n`
    elif [ `echo ${REMOTE} | grep -c \!` -ne 0 ] ; then
	RHOST=`echo $REMOTE | cut -d \! -f 1`
	RNAME=`echo $REMOTE | cut -d \! -f 2`
    else
	RHOST=${REMOTE}
    fi

    lpset -n system -a "bsdaddr=${RHOST},${RNAME}" -a "description=${DESC}" \
	${PRINTER}

done

exit 0