1 | #! /bin/sh |
---|
2 | # $Id: cups-print.sh 4027 2011-01-21 03:45:40Z zacheiss $ |
---|
3 | |
---|
4 | if [ -d /var/athena ] && [ -w /var/athena ]; then |
---|
5 | exec >/var/athena/moira_update.log 2>&1 |
---|
6 | else |
---|
7 | exec >/tmp/moira_update.log 2>&1 |
---|
8 | fi |
---|
9 | |
---|
10 | # The following exit codes are defined and MUST BE CONSISTENT with the |
---|
11 | # error codes the library uses: |
---|
12 | MR_MISSINGFILE=47836473 |
---|
13 | MR_MKCRED=47836474 |
---|
14 | MR_TARERR=47836476 |
---|
15 | |
---|
16 | PATH=/usr/local/samba/bin:/usr/bin:/bin; export PATH |
---|
17 | TARFILE=/var/tmp/cups-print.out |
---|
18 | CUPSLOCAL=/etc/cups |
---|
19 | SAMBAPASSWD=`cat /etc/cups/sambapasswd` |
---|
20 | |
---|
21 | # Alert if the tar file or other needed files do not exist |
---|
22 | test -r $TARFILE || exit $MR_MISSINGFILE |
---|
23 | test -d $CUPSLOCAL || exit $MR_MISSINGFILE |
---|
24 | |
---|
25 | # We need to kill off CUPS to prevent it from overwriting |
---|
26 | # state data whilst updating |
---|
27 | /etc/init.d/cups stop |
---|
28 | |
---|
29 | /etc/cups/bin/check-disabled.pl 2>/dev/null |
---|
30 | |
---|
31 | cd / |
---|
32 | tar xf $TARFILE || exit $MR_TARERR |
---|
33 | |
---|
34 | /etc/cups/bin/post-dcm-disable.pl 2>/dev/null |
---|
35 | if [ -s /etc/cups/printers.conf.tmp ]; then |
---|
36 | mv /etc/cups/printers.conf.tmp /etc/cups/printers.conf |
---|
37 | fi |
---|
38 | |
---|
39 | /etc/init.d/cups start |
---|
40 | |
---|
41 | # Now, make a stab at the PPD file. This is okay to run after |
---|
42 | # because CUPS will pick up the new PPDs later |
---|
43 | /etc/cups/bin/gen-ppd.pl |
---|
44 | |
---|
45 | if [ $? != 0 ]; then |
---|
46 | exit $MR_MKCRED |
---|
47 | fi |
---|
48 | |
---|
49 | # if Samba-enabled, then restart it too to have it pick up |
---|
50 | # new definitions |
---|
51 | if [ -x /etc/init.d/smb ]; then |
---|
52 | /etc/init.d/smb restart |
---|
53 | fi |
---|
54 | |
---|
55 | test -r /etc/cups/all-queues || exit $MR_MISSINGFILE |
---|
56 | |
---|
57 | # Generate list of all queues. |
---|
58 | rm -f /etc/cups/all-queues.new |
---|
59 | rm -f /etc/cups/all-queues.tmp |
---|
60 | grep "<Printer" /etc/cups/printers.conf | awk '{print $2}' | sed -e 's/>//' > /etc/cups/all-queues.tmp |
---|
61 | grep '^Printer' /etc/cups/classes.conf | awk '{print $2}' >> /etc/cups/all-queues.tmp |
---|
62 | sort -u /etc/cups/all-queues.tmp > /etc/cups/all-queues.new |
---|
63 | |
---|
64 | # Sanity check that the file isn't empty. |
---|
65 | test -s /etc/cups/all-queues.new || exit $MR_MKCRED |
---|
66 | |
---|
67 | rm -f /etc/cups/all-queues.tmp |
---|
68 | mv /etc/cups/all-queues /etc/cups/all-queues.old && mv /etc/cups/all-queues.new /etc/cups/all-queues |
---|
69 | |
---|
70 | # Generate list of new queues since the last time we ran. |
---|
71 | newqueues=`comm -13 /etc/cups/all-queues.old /etc/cups/all-queues` |
---|
72 | for queue in $newqueues; do |
---|
73 | # If PPD file doesn't exist, cupsaddsmb will bomb out. |
---|
74 | if [ -f /etc/cups/ppd/$queue.ppd ]; then |
---|
75 | # Add this queue to SMB service advertisements. |
---|
76 | /usr/sbin/cupsaddsmb -v -U root%$SAMBAPASSWD -W PRINTERS $queue |
---|
77 | if [ $? != 0 ]; then |
---|
78 | echo "Failed to configure $queue for SMB printing." |
---|
79 | fi |
---|
80 | fi |
---|
81 | done |
---|
82 | |
---|
83 | # cleanup |
---|
84 | test -f $TARFILE && rm -f $TARFILE |
---|
85 | test -f $0 && rm -f $0 |
---|
86 | |
---|
87 | exit 0 |
---|
88 | |
---|