#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (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
# 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 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
TEXTDOMAIN="SUNW_OST_OSCMD"
export TEXTDOMAIN
exit 1
}
# create a filter table for LP service
if [[ ! -f /etc/lp/filter.table ]] ; then
-F $filter
done
fi
}
# svcadm ${1} -s svc:/application/print/rfc1179:default
# svcadm ${1} -s svc:/application/print/ipp-listener:default
}
# synchronize printers.conf with LP configuration changes
lp_uri="ipp://${lp_server}/printers/${DEST}"
lp_bsdaddr="${lp_server},${DEST},Solaris"
-a "printer-uri-supported=${lp_uri}" \
-a "bsdaddr=${lp_bsdaddr}" \
done
done
}
# Delete all destinations in printers.conf
do
status=$?
done
}
# Call the ppdmgr utility to add a new PPD file to the system.
#
# $1 - path to PPD file
# $2 - label name (optional)
# Add new ppd file and echo full path it was actually saved to
ppdmgrcmd="${PFEXEC} ${PPDMGR} -a ${1} -w"
if [[ -z "${ppderrfile}" ]] ; then
exit 2
fi
ppd_file=$(${ppdmgrcmd} 2>${ppderrfile})
ppdmgrrc=$?
if [[ -s "${ppderrfile}" ]] ; then
print -n "lpadmin: " 1>&2
cat ${ppderrfile} 1>&2
rm -f ${ppderrfile} >/dev/null 2>&1
exit 1
fi
fi
rm -f ${ppderrfile} >/dev/null 2>&1
}
#
# Execution begins here
#
# be sure that we can run lpset and lpget
exit 2
fi
if [[ $# -lt 1 ]] ; then
exit 1
fi
# Deal with the -d option independently since getopts does not handle
# options that may or may not have arguments
#
if [[ ${1} = "-d" ]] ; then
exit_code=$?
exit_code=$?
else # no default, nothing to do
fi
exit_code=$?
exit_code=$?
else # can't set default to an unconfigured printer
fi
else # invalid usage
exit 1
fi
exit ${exit_code}
fi
# Strip off legal options
while 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
do
D)
description="${OPTARG}"
;;
n)
ppd_file="${OPTARG}"
;;
p)
if [[ -n "${delete}" ]] ; then
fi
;;
s)
;;
v|U)
if [[ ! -n "${server}" ]] ; then
fi
local="true"
;;
x)
if [[ -n "${printer}" || -n "${server}" || \
-n "${device}" || -n "${description}" ]] ; then
fi
if [[ ${printer} = "all" ]] ; then
local="true"
fi
;;
S|M|A)
local="true"
;;
c)
local="true"
if [[ ! -f ${LPGET} ]] ; then
exit 2
fi
lpget_class=$?
exit 1
fi
;;
r)
local="true"
;;
esac
done
#
# We don't have anything to do; let user know and bail
#
if [[ ! -n "${printer}" && ! -n "${delete}" && ! -n "${local}" ]] ; then
exit 1
fi
#
# Printer does not exist
# To be consistent with 2.5, assume adding local printer
#
if [[ ! -n "${device}" && ! -n "${server}" && ! -n "${delete}" && \
! -n "${local}" ]] ; then
lpget_stat=$?
exit 1
fi
fi
# process the "server" value
# It can be a hostname, UUCP form (server!queue), RCMD form(queue@server),
# or in URI form ({scheme}://{endpoint})
#
case "${server}" in
*://*) # URI form
;;
*@*) # RCMD form
;;
*!*) # UUCP form
;;
*) # hostname
;;
esac
# if there is a "device" or LP configuration, it's local
local="true"
fi
# Do the LP configuration for a local printer served by lpsched
if [[ -x ${LPADMIN} && -n "${local}" ]] ; then
# enumerate LP configured printers before modification
PRE=$(${MKTEMP} lpadmin-pre.XXXXXX)
if [[ -z "${PRE}" ]] ; then
exit 2
fi
# if there are no printers configured, enable LP service(s)
# add filters to LP service
# add new ppd file to PPD file repositories
if [[ -n "${ppd_file}" && -x ${PPDMGR} ]] ; then
add_new_ppd_file "${ppd_file}"
fi
# modify LP destination(s)
CMD="${PFEXEC} ${LPADMIN}"
while [[ -n "$*" ]] ; do # to deal with multi-word arguments
# replace the ppd_file originally specified with the -n option
# with the one returned from call to ppdmgr
if [[ "${1}" = "-n" ]] ; then
shift
fi
shift
done
*\"-D\")
;;
esac
# execute the LP lpadmin command
eval $CMD
exit_code=$?
# enumerate LP configured printers after modification
POST=$(${MKTEMP} lpadmin-post.XXXXXX)
if [[ -z "${POST}" ]] ; then
exit 2
fi
# if there are no destinations, disable the service(s)
# sync printers.conf with LP configuration
lp_config_sync_pconf "${PRE}" "${POST}"
fi
# Do any printers.conf configuration that is required
if [[ -n "${delete}" ]] ; then
if [[ "${delete}" = "all" ]] ; then
elif [[ -z "${local}" ]] ; then
exit_code=$?
fi
else
if [[ -z "${local}" ]] ; then
# if we need a uri, find the "best" one.
if [[ -z "${uri}" ]] ; then
uri="ipp://${server}/printers/${rem_printer}"
if [[ $? -ne 0 ]] ; then
uri="lpd://${server}/printers/${rem_printer}#Solaris"
fi
fi
# set the bsdaddr
bsdaddr="${server},${rem_printer},Solaris"
if [[ -n "${printer}" && -n "${server}" ]] ; then
-a "printer-uri-supported=${uri}" \
-a "bsdaddr=${bsdaddr}" ${printer}
exit_code=$?
fi
fi
if [[ -n "${printer}" && -n "${description}" ]] ; then
-a "description=${description}" ${printer}
exit_code=$?
fi
fi
# if the "default" doesn't resolve a "bsdaddr", the printer is gone, remove it
exit $exit_code