source: trunk/third/moira/gen/cups-print.sh @ 25198

Revision 25198, 2.5 KB checked in by jdreed, 13 years ago (diff)
In moira: * Snapshot moira@r4042 (6/28/11) * Update version number to include moira revision number
  • Property svn:executable set to *
Line 
1#! /bin/sh
2# $Id: cups-print.sh 4027 2011-01-21 03:45:40Z zacheiss $
3
4if [ -d /var/athena ] && [ -w /var/athena ]; then
5    exec >/var/athena/moira_update.log 2>&1
6else
7    exec >/tmp/moira_update.log 2>&1
8fi
9
10# The following exit codes are defined and MUST BE CONSISTENT with the
11# error codes the library uses:
12MR_MISSINGFILE=47836473
13MR_MKCRED=47836474
14MR_TARERR=47836476
15
16PATH=/usr/local/samba/bin:/usr/bin:/bin; export PATH
17TARFILE=/var/tmp/cups-print.out
18CUPSLOCAL=/etc/cups
19SAMBAPASSWD=`cat /etc/cups/sambapasswd`
20
21# Alert if the tar file or other needed files do not exist
22test -r $TARFILE || exit $MR_MISSINGFILE
23test -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
31cd /
32tar xf $TARFILE || exit $MR_TARERR
33
34/etc/cups/bin/post-dcm-disable.pl 2>/dev/null
35if [ -s /etc/cups/printers.conf.tmp ]; then
36    mv /etc/cups/printers.conf.tmp /etc/cups/printers.conf
37fi
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
45if [ $? != 0 ]; then
46    exit $MR_MKCRED
47fi
48
49# if Samba-enabled, then restart it too to have it pick up
50# new definitions
51if [ -x /etc/init.d/smb ]; then
52       /etc/init.d/smb restart
53fi
54
55test -r /etc/cups/all-queues || exit $MR_MISSINGFILE
56
57# Generate list of all queues.
58rm -f /etc/cups/all-queues.new
59rm -f /etc/cups/all-queues.tmp
60grep "<Printer" /etc/cups/printers.conf | awk '{print $2}' | sed -e 's/>//' > /etc/cups/all-queues.tmp
61grep '^Printer' /etc/cups/classes.conf | awk '{print $2}' >> /etc/cups/all-queues.tmp
62sort -u /etc/cups/all-queues.tmp > /etc/cups/all-queues.new
63
64# Sanity check that the file isn't empty.
65test -s /etc/cups/all-queues.new || exit $MR_MKCRED
66
67rm -f /etc/cups/all-queues.tmp
68mv /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.
71newqueues=`comm -13 /etc/cups/all-queues.old /etc/cups/all-queues`
72for 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
81done
82
83# cleanup
84test -f $TARFILE && rm -f $TARFILE
85test -f $0 && rm -f $0
86
87exit 0
88
Note: See TracBrowser for help on using the repository browser.