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

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