[1885] in Moira Commits

home help back first fref pref prev next nref lref last post

/svn/moira r4026 - trunk/moira/gen

daemon@ATHENA.MIT.EDU (Garry Zacheiss)
Thu Jan 20 13:46:11 2011

Date: Thu, 20 Jan 2011 13:46:05 -0500
From: Garry Zacheiss <zacheiss@MIT.EDU>
Message-Id: <201101201846.p0KIk5Rt006988@drugstore.mit.edu>
To: moira-commits@mit.edu
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Author: zacheiss
Date: 2011-01-20 13:46:05 -0500 (Thu, 20 Jan 2011)
New Revision: 4026

Modified:
   trunk/moira/gen/cups-cluster.sh
   trunk/moira/gen/cups-print.sh
Log:
Add new queues to SMB service advertisements.  Make cups-print and cups-cluster look the same again.

Modified: trunk/moira/gen/cups-cluster.sh
===================================================================
--- trunk/moira/gen/cups-cluster.sh	2010-11-30 17:17:02 UTC (rev 4025)
+++ trunk/moira/gen/cups-cluster.sh	2011-01-20 18:46:05 UTC (rev 4026)
@@ -13,20 +13,21 @@
 MR_MKCRED=47836474
 MR_TARERR=47836476
 
-PATH=/bin
+PATH=/usr/local/samba/bin:/bin; export PATH
 TARFILE=/var/tmp/cups-cluster.out
 CUPSLOCAL=/etc/cups
+SAMBAPASSWD=`cat /etc/cups/sambapasswd`
 
-/etc/init.d/cups stop
-
 # Alert if the tar file or other needed files do not exist
 test -r $TARFILE || exit $MR_MISSINGFILE
 test -d $CUPSLOCAL || exit $MR_MISSINGFILE
 
+# We need to kill off CUPS to prevent it from overwriting
+# state data whilst updating
+/etc/init.d/cups stop
+
 /etc/cups/bin/check-disabled.pl 2>/dev/null
 
-# Unpack the tar file, getting only files that are newer than the
-# on-disk copies (-u).
 cd /
 tar xf $TARFILE || exit $MR_TARERR
 
@@ -37,18 +38,48 @@
 
 /etc/init.d/cups start
 
-/etc/cups/bin/gen-ppd.pl 2>/dev/null
+# Now, make a stab at the PPD file.  This is okay to run after
+# because CUPS will pick up the new PPDs later
+/etc/cups/bin/gen-ppd.pl
 
+if [ $? != 0 ]; then
+    exit $MR_MKCRED
+fi
+
 # if Samba-enabled, then restart it too to have it pick up
 # new definitions
 if [ -x /etc/init.d/smb ]; then
        /etc/init.d/smb restart
 fi
 
-if [ $? != 0 ]; then
-    exit $MR_MKCRED
-fi
+test -r /etc/cups/all-queues || exit $MR_MISSINGFILE
 
+# Generate list of all queues.
+rm -f /etc/cups/all-queues.new
+rm -f /etc/cups/all-queues.tmp
+grep "<Printer" /etc/cups/printers.conf | awk '{print $2}' | sed -e 's/>//' > /etc/cups/all-queues.tmp
+grep '^Printer' /etc/cups/classes.conf | awk '{print $2}' >> /etc/cups/all-queues.tmp
+sort -u /etc/cups/all-queues.tmp > /etc/cups/all-queues.new
+
+# Sanity check that the file isn't empty.
+test -s /etc/cups/all-queues.new || exit $MR_MKCRED
+
+rm -f /etc/cups/all-queues.tmp
+mv /etc/cups/all-queues /etc/cups/all-queues.old && mv /etc/cups/all-queues.new /etc/cups/all-queues
+
+# Generate list of new queues since the last time we ran.
+newqueues=`comm -13 /etc/cups/all-queues.old /etc/cups/all-queues`
+for queue in $newqueues; do
+    # If PPD file doesn't exist, cupsaddsmb will bomb out.
+    if [ -f /etc/cups/ppd/$queue.ppd ]; then
+        # Add this queue to SMB service advertisements.
+	/usr/sbin/cupsaddsmb -v -U root%$SAMBAPASSWD -W PRINTERS $queue
+	if [ $? != 0 ]; then
+	    echo "Failed to configure $queue for SMB printing."
+	fi
+    fi
+done
+
 # cleanup
 test -f $TARFILE && rm -f $TARFILE
 test -f $0 && rm -f $0

Modified: trunk/moira/gen/cups-print.sh
===================================================================
--- trunk/moira/gen/cups-print.sh	2010-11-30 17:17:02 UTC (rev 4025)
+++ trunk/moira/gen/cups-print.sh	2011-01-20 18:46:05 UTC (rev 4026)
@@ -13,9 +13,10 @@
 MR_MKCRED=47836474
 MR_TARERR=47836476
 
-PATH=/bin
+PATH=/usr/local/samba/bin:/bin; export PATH
 TARFILE=/var/tmp/cups-print.out
 CUPSLOCAL=/etc/cups
+SAMBAPASSWD=`cat /etc/cups/sambapasswd`
 
 # Alert if the tar file or other needed files do not exist
 test -r $TARFILE || exit $MR_MISSINGFILE
@@ -27,8 +28,6 @@
 
 /etc/cups/bin/check-disabled.pl 2>/dev/null
 
-# Unpack the tar file, getting only files that are newer than the
-# on-disk copies (-u).
 cd /
 tar xf $TARFILE || exit $MR_TARERR
 
@@ -53,6 +52,34 @@
        /etc/init.d/smb restart
 fi
 
+test -r /etc/cups/all-queues || exit $MR_MISSINGFILE
+
+# Generate list of all queues.
+rm -f /etc/cups/all-queues.new
+rm -f /etc/cups/all-queues.tmp
+grep "<Printer" /etc/cups/printers.conf | awk '{print $2}' | sed -e 's/>//' > /etc/cups/all-queues.tmp
+grep '^Printer' /etc/cups/classes.conf | awk '{print $2}' >> /etc/cups/all-queues.tmp
+sort -u /etc/cups/all-queues.tmp > /etc/cups/all-queues.new
+
+# Sanity check that the file isn't empty.
+test -s /etc/cups/all-queues.new || exit $MR_MKCRED
+
+rm -f /etc/cups/all-queues.tmp
+mv /etc/cups/all-queues /etc/cups/all-queues.old && mv /etc/cups/all-queues.new /etc/cups/all-queues
+
+# Generate list of new queues since the last time we ran.
+newqueues=`comm -13 /etc/cups/all-queues.old /etc/cups/all-queues`
+for queue in $newqueues; do
+    # If PPD file doesn't exist, cupsaddsmb will bomb out.
+    if [ -f /etc/cups/ppd/$queue.ppd ]; then
+        # Add this queue to SMB service advertisements.
+	/usr/sbin/cupsaddsmb -v -U root%$SAMBAPASSWD -W PRINTERS $queue
+	if [ $? != 0 ]; then
+	    echo "Failed to configure $queue for SMB printing."
+	fi
+    fi
+done
+
 # cleanup
 test -f $TARFILE && rm -f $TARFILE
 test -f $0 && rm -f $0


home help back first fref pref prev next nref lref last post