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

Revision 25761, 3.6 KB checked in by jdreed, 12 years ago (diff)
The CUPS option is printer-is-shared, not printer-is-share
  • Property svn:executable set to *
Line 
1#!/bin/sh
2
3ATHENA_PRINTERS=
4DEFAULT_PRINTER="mitprint"
5PRLIST="/var/lib/debathena-cupsys-config.added_printers"
6
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
34add_printers() {
35    rm -f $PRLIST
36    ppd=
37    select_ppd "$BW_PPDS"
38    if [ $? -eq 3 ]; then
39        echo "NOTE: Using compatibility PPD for 'mitprint' printer" >&2
40    fi
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" \
45            -o printer-is-shared=false \
46            -o OptionDuplex=True \
47            -m "$ppd"
48        if [ $? != 0 ]; then
49            echo "FAILED to add Pharos printer 'mitprint'" >&2
50        else
51            echo "Added Pharos printer 'mitprint'" >&2
52            echo "$p" >> $PRLIST
53        fi
54    else
55        echo "Cannot add Pharos printer 'mitprint': no available PPDs!" >&2
56    fi
57    ppd=
58    select_ppd "$COLOR_PPDS"
59    if [ $? -eq 3 ]; then
60        echo "NOTE: Using compatibility driver for 'mitprint-color' printer" >&2
61    fi
62    if [ -n "$ppd" ]; then
63        lpadmin -p mitprint-color -E -v lpd://mitprint.mit.edu/color \
64            -D "Pharos (Color)" \
65            -L "Release jobs from any Pharos Color printer" \
66            -o printer-is-shared=false \
67            -o OptionDuplex=True \
68            -m "$ppd"
69        if [ $? != 0 ]; then
70            echo "FAILED to add Pharos printer 'mitprint-color'" >&2
71        else
72            echo "Added Pharos printer 'mitprint-color'" >&2
73            echo "$p" >> $PRLIST
74        fi
75    else
76        echo "Cannot add Pharos printer 'mitprint-color': no available PPDs!" >&2
77    fi
78    for a in $ATHENA_PRINTERS; do
79        # Don't clobber queue, this is -cluster
80        if add-athena-printer $a; then
81            echo "Added Athena printer $a"
82            echo "$p" >> $PRLIST
83        else
84            echo "FAILED to add Athena printer $a"
85        fi
86    done
87    # Dear CUPS, 
88    # There exist return codes.  Use them.
89    # Love, Debathena
90    if [ "$(lpstat -d)" = "no system default destination" ]; then
91        lpadmin -d $DEFAULT_PRINTER
92    fi
93    # We don't need to deal with this on uninstall.  CUPS is
94    # smart enough (for now, at least) to not retain a default when
95    # the printer in question is deleted.
96}
97
98del_printers() {
99    # Initially assume we remove nothing and the user can deal
100    PRINTERS_TO_REMOVE=
101    if [ -s $PRLIST ]; then
102        PRINTERS_TO_REMOVE=`cat $PRLIST`
103    fi
104    for p in $PRINTERS_TO_REMOVE; do
105        lpadmin -x $p
106        if [ $? != 0 ]; then
107            echo "Failed to remove printer $p!"
108        fi
109    done
110    rm -f $PRLIST
111}
112
113require_cups() {
114    # Ensure CUPS is running
115    [ -e /etc/init.d/cups ] && rcname=cups || rcname=cupsys
116    if hash invoke-rc.d; then
117        invoke="invoke-rc.d $rcname"
118    else
119        invoke="/etc/init.d/$rcname"
120    fi
121    if ! /etc/init.d/$rcname status; then
122        if ! $invoke start; then
123            echo "FATAL: Couldn't start CUPS!"
124            exit 1
125        fi
126    fi
127    if [ "$(lpstat -r)" != "scheduler is running" ]; then
128      echo "FATAL: cups claimed to have started, but lpstat -r says it's not running!"
129      exit 1
130    fi
131}
132
133case "$1" in
134    add)
135        require_cups 
136        add_printers
137        ;;
138    remove)
139        require_cups
140        del_printers
141        ;;
142    *)
143        echo "Usage: $0 [ add | remove ]"
144        exit 1
145        ;;
146esac
147exit 0
Note: See TracBrowser for help on using the repository browser.