source: trunk/debathena/config/cupsys-config/debian/configure-athena-printers @ 25826

Revision 25826, 3.7 KB checked in by jdreed, 11 years ago (diff)
In cupsys-config: * Set an error policy of abort-job so that jobs don't stick around in local cups queues on workstations
  • Property svn:executable set to *
RevLine 
[25317]1#!/bin/sh
2
3ATHENA_PRINTERS=
[25368]4DEFAULT_PRINTER="mitprint"
[25317]5PRLIST="/var/lib/debathena-cupsys-config.added_printers"
6
[25629]7BW_PPDS="drv:///hpijs.drv/hp-laserjet_9050-hpijs-pcl3.ppd \
8         drv:///hpijs.drv/hp-laserjet_9050-hpijs.ppd"
9
10COLOR_PPDS="drv:///hpijs.drv/hp-color_laserjet_cp3525-hpijs-pcl3.ppd \
11            drv:///hpijs.drv/hp-color_laserjet_cp3505-hpijs.ppd"
12
13PPDCACHE="/var/tmp/debathena-cupsys-config-ppd-cache"
14
15select_ppd() {
16    [ -f "$PPDCACHE" ] && [ -r "$PPDCACHE" ] && [ -s "$PPDCACHE" ] || \
17        (rm -rf $PPDCACHE && lpinfo -m | cut -d ' ' -f 1 > $PPDCACHE)
18    first=1
19    ppd=
20    for p in $1; do
21        echo "trying $p"
22        if grep -qFx "$p" "$PPDCACHE"; then
23            ppd=$p
24            break
25        else
26            first=0
27        fi
28    done
29    rv=0
30    [ -n "$ppd" ] && [ $first -ne 1 ] && rv=3
31    return $rv
32}
33
[25317]34add_printers() {
35    rm -f $PRLIST
[25629]36    ppd=
37    select_ppd "$BW_PPDS"
38    if [ $? -eq 3 ]; then
39        echo "NOTE: Using compatibility PPD for 'mitprint' printer" >&2
[25392]40    fi
[25629]41    if [ -n "$ppd" ]; then
42        lpadmin -p mitprint -E -v lpd://mitprint.mit.edu/bw \
43            -D "Pharos (Monochrome)" \
44            -L "Release jobs from any Pharos B&W printer" \
[25761]45            -o printer-is-shared=false \
[25752]46            -o OptionDuplex=True \
[25826]47            -o printer-error-policy=abort-job \
[25629]48            -m "$ppd"
49        if [ $? != 0 ]; then
50            echo "FAILED to add Pharos printer 'mitprint'" >&2
51        else
52            echo "Added Pharos printer 'mitprint'" >&2
53            echo "$p" >> $PRLIST
54        fi
55    else
56        echo "Cannot add Pharos printer 'mitprint': no available PPDs!" >&2
57    fi
58    ppd=
59    select_ppd "$COLOR_PPDS"
60    if [ $? -eq 3 ]; then
61        echo "NOTE: Using compatibility driver for 'mitprint-color' printer" >&2
62    fi
63    if [ -n "$ppd" ]; then
64        lpadmin -p mitprint-color -E -v lpd://mitprint.mit.edu/color \
65            -D "Pharos (Color)" \
66            -L "Release jobs from any Pharos Color printer" \
[25761]67            -o printer-is-shared=false \
[25752]68            -o OptionDuplex=True \
[25826]69            -o printer-error-policy=abort-job \
[25629]70            -m "$ppd"
71        if [ $? != 0 ]; then
72            echo "FAILED to add Pharos printer 'mitprint-color'" >&2
73        else
74            echo "Added Pharos printer 'mitprint-color'" >&2
75            echo "$p" >> $PRLIST
76        fi
[25392]77    else
[25629]78        echo "Cannot add Pharos printer 'mitprint-color': no available PPDs!" >&2
[25392]79    fi
[25317]80    for a in $ATHENA_PRINTERS; do
81        # Don't clobber queue, this is -cluster
82        if add-athena-printer $a; then
83            echo "Added Athena printer $a"
84            echo "$p" >> $PRLIST
85        else
86            echo "FAILED to add Athena printer $a"
87        fi
88    done
[25368]89    # Dear CUPS, 
90    # There exist return codes.  Use them.
91    # Love, Debathena
92    if [ "$(lpstat -d)" = "no system default destination" ]; then
[25369]93        lpadmin -d $DEFAULT_PRINTER
[25368]94    fi
95    # We don't need to deal with this on uninstall.  CUPS is
96    # smart enough (for now, at least) to not retain a default when
97    # the printer in question is deleted.
[25317]98}
99
100del_printers() {
101    # Initially assume we remove nothing and the user can deal
102    PRINTERS_TO_REMOVE=
103    if [ -s $PRLIST ]; then
104        PRINTERS_TO_REMOVE=`cat $PRLIST`
105    fi
106    for p in $PRINTERS_TO_REMOVE; do
107        lpadmin -x $p
108        if [ $? != 0 ]; then
109            echo "Failed to remove printer $p!"
110        fi
111    done
112    rm -f $PRLIST
113}
114
115require_cups() {
116    # Ensure CUPS is running
117    [ -e /etc/init.d/cups ] && rcname=cups || rcname=cupsys
118    if hash invoke-rc.d; then
119        invoke="invoke-rc.d $rcname"
120    else
121        invoke="/etc/init.d/$rcname"
122    fi
123    if ! /etc/init.d/$rcname status; then
124        if ! $invoke start; then
125            echo "FATAL: Couldn't start CUPS!"
126            exit 1
127        fi
128    fi
129    if [ "$(lpstat -r)" != "scheduler is running" ]; then
130      echo "FATAL: cups claimed to have started, but lpstat -r says it's not running!"
131      exit 1
132    fi
133}
134
135case "$1" in
136    add)
137        require_cups 
138        add_printers
139        ;;
140    remove)
141        require_cups
142        del_printers
143        ;;
144    *)
145        echo "Usage: $0 [ add | remove ]"
146        exit 1
147        ;;
148esac
149exit 0
Note: See TracBrowser for help on using the repository browser.