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

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