9622934a862fa39a8e90c816c4136e293d75629djacobs# CDDL HEADER START
9622934a862fa39a8e90c816c4136e293d75629djacobs# The contents of this file are subject to the terms of the
9622934a862fa39a8e90c816c4136e293d75629djacobs# Common Development and Distribution License (the "License").
9622934a862fa39a8e90c816c4136e293d75629djacobs# You may not use this file except in compliance with the License.
9622934a862fa39a8e90c816c4136e293d75629djacobs# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9622934a862fa39a8e90c816c4136e293d75629djacobs# See the License for the specific language governing permissions
9622934a862fa39a8e90c816c4136e293d75629djacobs# and limitations under the License.
9622934a862fa39a8e90c816c4136e293d75629djacobs# When distributing Covered Code, include this CDDL HEADER in each
9622934a862fa39a8e90c816c4136e293d75629djacobs# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
9622934a862fa39a8e90c816c4136e293d75629djacobs# If applicable, add the following below this CDDL HEADER, with the
9622934a862fa39a8e90c816c4136e293d75629djacobs# fields enclosed by brackets "[]" replaced with your own identifying
9622934a862fa39a8e90c816c4136e293d75629djacobs# information: Portions Copyright [yyyy] [name of copyright owner]
9622934a862fa39a8e90c816c4136e293d75629djacobs# CDDL HEADER END
6124874e2cec65f2e7a974b3833b05dbf2a7d905Ghee Teo# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
9622934a862fa39a8e90c816c4136e293d75629djacobs# Use is subject to license terms.
9622934a862fa39a8e90c816c4136e293d75629djacobs# This program manages the "active" print service selection.
9622934a862fa39a8e90c816c4136e293d75629djacobs# If called as 'print-service', it takes one of four options.
9622934a862fa39a8e90c816c4136e293d75629djacobs# [-s[et] service [-m]] Select the "active" print service, optionally
9622934a862fa39a8e90c816c4136e293d75629djacobs# migrating basic print queue configuration.
9622934a862fa39a8e90c816c4136e293d75629djacobs# [-q[uery]] Display the "active" print service.
9622934a862fa39a8e90c816c4136e293d75629djacobs# [-e[xport] file] Export basic print queue configuration to
9622934a862fa39a8e90c816c4136e293d75629djacobs# [-i[mport] file] Import basic print queue configuration from
9622934a862fa39a8e90c816c4136e293d75629djacobs# If called by any other name, it will look for a corresponding command
9622934a862fa39a8e90c816c4136e293d75629djacobs# under /usr/lib/{active-service}/bin/{command} and execute that program
9622934a862fa39a8e90c816c4136e293d75629djacobs# with the original arguments.
9622934a862fa39a8e90c816c4136e293d75629djacobs $cmd [-s[et] service [-m]] Select the \"active\" print service,
9622934a862fa39a8e90c816c4136e293d75629djacobs optionally migrating basic print queue
9622934a862fa39a8e90c816c4136e293d75629djacobs configuration.
9622934a862fa39a8e90c816c4136e293d75629djacobs $cmd [-q[uery]] Display the "active" print service.
9622934a862fa39a8e90c816c4136e293d75629djacobs $cmd [-e[xport] file] Export basic print queue configuration
9622934a862fa39a8e90c816c4136e293d75629djacobs $cmd [-i[mport] file] Import basic print queue configuration
9622934a862fa39a8e90c816c4136e293d75629djacobs from a file.
9622934a862fa39a8e90c816c4136e293d75629djacobs open($FH, "$SVCPROP -C -p $property $fmri 2>/dev/null |");
9622934a862fa39a8e90c816c4136e293d75629djacobs open($FH, "$SVCCFG -s $fmri \"$operation\" 2>/dev/null |");
9622934a862fa39a8e90c816c4136e293d75629djacobs $service = svcprop("$SVC_CUPS_SCHEDULER:default", "general/active");
9622934a862fa39a8e90c816c4136e293d75629djacobs ($service =~ /true/) && ($service = 'cups') || ($service = 'lp');
9622934a862fa39a8e90c816c4136e293d75629djacobs fatal("failed to detect active print service: $!\n");
9622934a862fa39a8e90c816c4136e293d75629djacobs ($command =~ /(en|dis)able/) && ($service eq 'cups') &&
9622934a862fa39a8e90c816c4136e293d75629djacobs ($executable = "/usr/lib/$service/bin/$service$command");
9622934a862fa39a8e90c816c4136e293d75629djacobs fatal("$command is not available from $service print service\n");
9622934a862fa39a8e90c816c4136e293d75629djacobs # export old print queue configuration (if migrating)
36615d24946b849e48cedbbafa9adfb4a02b590cjacobs (-f '/etc/printers.conf') && (! -f '/etc/lp/printers.conf') &&
36615d24946b849e48cedbbafa9adfb4a02b590cjacobs rename('/etc/printers.conf', '/etc/lp/printers.conf');
36615d24946b849e48cedbbafa9adfb4a02b590cjacobs svcadm("disable", $SVC_LP_SCHEDULER, $SVC_LP_IPP, $SVC_LP_LPD,
9622934a862fa39a8e90c816c4136e293d75629djacobs svcadm("enable", $SVC_CUPS_SCHEDULER, $SVC_CUPS_LPD);
6124874e2cec65f2e7a974b3833b05dbf2a7d905Ghee Teo system("pkill -USR1 -f '/desktop-print-management-applet'");
9622934a862fa39a8e90c816c4136e293d75629djacobs svcadm("disable", $SVC_CUPS_SCHEDULER, $SVC_CUPS_LPD);
36615d24946b849e48cedbbafa9adfb4a02b590cjacobs svcadm("enable", $SVC_LP_SCHEDULER, $SVC_LP_IPP, $SVC_LP_LPD,
36615d24946b849e48cedbbafa9adfb4a02b590cjacobs rename('/etc/lp/printers.conf', '/etc/printers.conf');
9622934a862fa39a8e90c816c4136e293d75629djacobs svccfg("cups/scheduler:default", "delprop general/active");
6124874e2cec65f2e7a974b3833b05dbf2a7d905Ghee Teo system("pkill -USR1 -f '/desktop-print-management-applet'");
9622934a862fa39a8e90c816c4136e293d75629djacobs # import the new print queue configuration (if migrating)
9622934a862fa39a8e90c816c4136e293d75629djacobs fatal("failed to detect active print service: $!\n");
9622934a862fa39a8e90c816c4136e293d75629djacobs my ($import_path, $export_path, $svc_name, $query, $migrate) = ();
9622934a862fa39a8e90c816c4136e293d75629djacobs my $res = GetOptions('q|query' => \$query, 's|set=s' => \$service,
9622934a862fa39a8e90c816c4136e293d75629djacobs 'm|migrate' => \$migrate, 'e|export=s' => \$export_path,
9622934a862fa39a8e90c816c4136e293d75629djacobs if (defined($import_path) && !defined($export_path) &&
9622934a862fa39a8e90c816c4136e293d75629djacobs !defined($query) && !defined($service) && !defined($migrate)) {
9622934a862fa39a8e90c816c4136e293d75629djacobs } elsif (!defined($import_path) && defined($export_path) &&
9622934a862fa39a8e90c816c4136e293d75629djacobs !defined($query) && !defined($service) && !defined($migrate)) {
9622934a862fa39a8e90c816c4136e293d75629djacobs } elsif (!defined($import_path) && !defined($export_path) &&
9622934a862fa39a8e90c816c4136e293d75629djacobs defined($query) && !defined($service) && !defined($migrate)) {
9622934a862fa39a8e90c816c4136e293d75629djacobs } elsif (!defined($import_path) && !defined($export_path) &&