lpadmin revision bcdabfc47e027d458c65d1c456642dd12908e197
134015a2eee98aa663217e87ec879938b5afb27cJazzyNico# CDDL HEADER START
d048f1c15089c16b8ca1b264513a2f92ff86e703JazzyNico# The contents of this file are subject to the terms of the
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# Common Development and Distribution License (the "License").
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# You may not use this file except in compliance with the License.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico# See the License for the specific language governing permissions
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico# and limitations under the License.
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico# When distributing Covered Code, include this CDDL HEADER in each
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico# If applicable, add the following below this CDDL HEADER, with the
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico# fields enclosed by brackets "[]" replaced with your own identifying
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# information: Portions Copyright [yyyy] [name of copyright owner]
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# CDDL HEADER END
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# Use is subject to license terms.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico gettext " lpadmin -S print-wheel -A alert-type [ -W minutes ]\n" 1>&2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico gettext " lpadmin -M -f form-name [ -a [ -o filebreak ]\n" 1>&2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# create a filter table for LP service
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if [[ ! -f /etc/lp/filter.table ]] ; then
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico# enable/disable LP related service(s)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico svcadm ${1} -s svc:/application/print/server:default
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico # svcadm ${1} -s svc:/application/print/rfc1179:default
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico # svcadm ${1} -s svc:/application/print/ipp-listener:default
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico# synchronize printers.conf with LP configuration changes
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico for DEST in ${ADDED} ; do
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico# Delete all destinations in printers.conf
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico for DEST in $(lpget -n system list | egrep -e '.+:$' | sed -e 's/://')
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# Call the ppdmgr utility to add a new PPD file to the system.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# $1 - path to PPD file
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# $2 - label name (optional)
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico # Add new ppd file and echo full path it was actually saved to
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico rm -f ${ppderrfile} >/dev/null 2>&1
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if [[ ${ppdmgrrc} -ne 0 ]] ; then
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico rm -f ${ppderrfile} >/dev/null 2>&1
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico# Execution begins here
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico# be sure that we can run lpset and lpget
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico gettext "lpadmin: System error; cannot set default printer\n" 1>&2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# Deal with the -d option independently since getopts does not handle
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# options that may or may not have arguments
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico else # no default, nothing to do
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico elif [[ $# -eq 2 ]] ; then # add/change the "default"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico else # can't set default to an unconfigured printer
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico else # invalid usage
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# Strip off legal options
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicowhile getopts "A:ac:D:e:f:F:H:hi:I:lm:Mn:o:p:Q:r:S:s:T:u:U:v:W:x:t:P:" arg
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if [[ -n "${delete}" ]] ; then
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if [[ ! -n "${server}" ]] ; then
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico local="true"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico local="true"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico local="true"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico local="true"
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico if [[ ! -f ${LPGET} ]] ; then
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico gettext "lpadmin: System error; cannot set class\n " 1>&2
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico if [[ ${lpget_class} -eq 0 && ! -r /etc/lp/classes/"${class}" ]] ; then
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico gettext "lpadmin: ERROR: Can't create class ${class}.\n" 1>&2
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico gettext " TO FIX: This is an existing printer name;\n" 1>&2
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico local="true"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# We don't have anything to do; let user know and bail
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNicoif [[ ! -n "${printer}" && ! -n "${delete}" && ! -n "${local}" ]] ; then
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico gettext " TO FIX: You must give one of these options:\n" 1>&2
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico# Printer does not exist
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico# To be consistent with 2.5, assume adding local printer
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNicoif [[ ! -n "${device}" && ! -n "${server}" && ! -n "${delete}" && \
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico ! -n "${local}" ]] ; then
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico gettext "lpadmin: ERROR: Missing -U or -v option.\n" 1>&2
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico gettext " TO FIX: Local printers must have\n" 1>&2
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico gettext " have dial-out instructions (-U option).\n" 1>&2
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico# process the "server" value
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# It can be a hostname, UUCP form (server!queue), RCMD form(queue@server),
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# or in URI form ({scheme}://{endpoint})
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *://*) # URI form
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico rem_printer=$(expr "${server}" : ".*://.*/\([^/]*\)")
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *@*) # RCMD form
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico *!*) # UUCP form
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico *) # hostname
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico# if there is a "device" or LP configuration, it's local
037bf91e68f10e796fecad5054b332b003c3a562JazzyNicoif [[ -n "${device}" || -f /etc/lp/printers/${printer}/configuration || \
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico local="true"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# Do the LP configuration for a local printer served by lpsched
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico # enumerate LP configured printers before modification
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico (/bin/ls /etc/lp/printers 2>/dev/null ; /bin/ls /etc/lp/classes \
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico # if there are no printers configured, enable LP service(s)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico # add filters to LP service
40e5cf3e8f0ddda79b1650df77d0f847a22822bfJazzyNico # add new ppd file to PPD file repositories
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico # modify LP destination(s)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico while [[ -n "$*" ]] ; do # to deal with multi-word arguments
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico # replace the ppd_file originally specified with the -n option
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico # with the one returned from call to ppdmgr
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico # execute the LP lpadmin command
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico # enumerate LP configured printers after modification
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico (/bin/ls /etc/lp/printers 2>/dev/null ; /bin/ls /etc/lp/classes \
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico # if there are no destinations, disable the service(s)
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico # sync printers.conf with LP configuration
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico# Do any printers.conf configuration that is required
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNicoif [[ -n "${delete}" ]] ; then
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico elif [[ -z "${local}" ]] ; then
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico if [[ -z "${local}" ]] ; then
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico # if we need a uri, find the "best" one.
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico if [[ -z "${uri}" ]] ; then
037bf91e68f10e796fecad5054b332b003c3a562JazzyNico uri="lpd://${server}/printers/${rem_printer}#Solaris"
88395eed42de4d59f54795b60c8c0a7ab881e153JazzyNico # set the bsdaddr
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico if [[ -n "${printer}" ]] ; then
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico -a "printer-uri-supported=${uri}" \
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico if [[ -n "${printer}" && -n "${description}" ]] ; then
3ced8da2102a0f0325ff7616fe075fc4821ed254JazzyNico# if the "default" doesn't resolve a "bsdaddr", the printer is gone, remove it