#!/bin/sh # # $FreeBSD$ usage() { echo "$0: usage:" >&2 echo "$0 [enable|disable] devicename" >&2 exit 1 } if [ -z "$2" ]; then usage fi printer="$(awk -v DEVICENAME="$2" ' /^<(Default)?Printer[[:space:]]/ { if (match($0, /[^[:space:]>]+>/)) { PRINTER=substr($0, RSTART, RLENGTH - 1); } } /^<\/(Default)?Printer/ { PRINTER="" } match($0, "DeviceURI[[:space:]]+usb:/dev/" DEVICENAME "\$") { print PRINTER } ' %%PREFIX%%/etc/cups/printers.conf)" if [ -z "$printer" ]; then # nothing to do exit 0 fi case "$1" in enable) chown cups:cups "/dev/$2" %%PREFIX%%/sbin/cupsenable "$printer" ;; disable) %%PREFIX%%/sbin/cupsdisable "$printer" ;; *) usage ;; esac exit 0 # eof