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

Revision 25390, 2.6 KB checked in by jdreed, 13 years ago (diff)
In cupsys-config: * Add the color printer
  • Property svn:executable set to *
Line 
1#!/bin/sh
2
3PHAROS_BW_PRINTERS="mitprint"
4PHAROS_COLOR_PRINTERS="mitprint-color"
5ATHENA_PRINTERS=
6DEFAULT_PRINTER="mitprint"
7PRLIST="/var/lib/debathena-cupsys-config.added_printers"
8
9add_printers() {
10    rm -f $PRLIST
11    for p in $PHAROS_BW_PRINTERS; do
12        lpadmin -p $p -E -v lpd://mitprint.mit.edu/bw \
13                -D "Pharos (Monochrome)" \
14                -L "Release jobs from any Pharos printer" \
15                -o printer-is-share=false \
16                -m drv:///hpijs.drv/hp-laserjet_9050-hpijs-pcl3.ppd
17        if [ $? != 0 ]; then
18            echo "FAILED to add Pharos printer $p"
19        else
20            echo "Added Pharos printer $p"
21            echo "$p" >> $PRLIST
22        fi
23    done
24    for p in $PHAROS_COLOR_PRINTERS; do
25        lpadmin -p $p -E -v lpd://mitprint.mit.edu/color \
26                -D "Pharos (Color)" \
27                -L "Release jobs from any Pharos Color printer" \
28                -o printer-is-share=false \
29                -m drv:///hpijs.drv/hp-color_laserjet_cp3525-hpijs-pcl3.ppd
30        if [ $? != 0 ]; then
31            echo "FAILED to add Pharos printer $p"
32        else
33            echo "Added Pharos printer $p"
34            echo "$p" >> $PRLIST
35        fi
36    done
37    for a in $ATHENA_PRINTERS; do
38        # Don't clobber queue, this is -cluster
39        if add-athena-printer $a; then
40            echo "Added Athena printer $a"
41            echo "$p" >> $PRLIST
42        else
43            echo "FAILED to add Athena printer $a"
44        fi
45    done
46    # Dear CUPS, 
47    # There exist return codes.  Use them.
48    # Love, Debathena
49    if [ "$(lpstat -d)" = "no system default destination" ]; then
50        lpadmin -d $DEFAULT_PRINTER
51    fi
52    # We don't need to deal with this on uninstall.  CUPS is
53    # smart enough (for now, at least) to not retain a default when
54    # the printer in question is deleted.
55}
56
57del_printers() {
58    # Initially assume we remove nothing and the user can deal
59    PRINTERS_TO_REMOVE=
60    if [ -s $PRLIST ]; then
61        PRINTERS_TO_REMOVE=`cat $PRLIST`
62    fi
63    for p in $PRINTERS_TO_REMOVE; do
64        lpadmin -x $p
65        if [ $? != 0 ]; then
66            echo "Failed to remove printer $p!"
67        fi
68    done
69    rm -f $PRLIST
70}
71
72require_cups() {
73    # Ensure CUPS is running
74    [ -e /etc/init.d/cups ] && rcname=cups || rcname=cupsys
75    if hash invoke-rc.d; then
76        invoke="invoke-rc.d $rcname"
77    else
78        invoke="/etc/init.d/$rcname"
79    fi
80    if ! /etc/init.d/$rcname status; then
81        if ! $invoke start; then
82            echo "FATAL: Couldn't start CUPS!"
83            exit 1
84        fi
85    fi
86    if [ "$(lpstat -r)" != "scheduler is running" ]; then
87      echo "FATAL: cups claimed to have started, but lpstat -r says it's not running!"
88      exit 1
89    fi
90}
91
92case "$1" in
93    add)
94        require_cups 
95        add_printers
96        ;;
97    remove)
98        require_cups
99        del_printers
100        ;;
101    *)
102        echo "Usage: $0 [ add | remove ]"
103        exit 1
104        ;;
105esac
106exit 0
Note: See TracBrowser for help on using the repository browser.