[csw-devel] SF.net SVN: gar:[9940] csw/mgar/pkg/cswclassutils/trunk

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Thu May 20 18:26:17 CEST 2010


Revision: 9940
          http://gar.svn.sourceforge.net/gar/?rev=9940&view=rev
Author:   wahwah
Date:     2010-05-20 16:26:17 +0000 (Thu, 20 May 2010)

Log Message:
-----------
cswclassutils: cswcrontab overhaul.  It works now\!

Modified Paths:
--------------
    csw/mgar/pkg/cswclassutils/trunk/checksums
    csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswcrontab
    csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.r.cswcrontab

Modified: csw/mgar/pkg/cswclassutils/trunk/checksums
===================================================================
--- csw/mgar/pkg/cswclassutils/trunk/checksums	2010-05-20 14:45:27 UTC (rev 9939)
+++ csw/mgar/pkg/cswclassutils/trunk/checksums	2010-05-20 16:26:17 UTC (rev 9940)
@@ -1,6 +1,6 @@
 48a97af56d55bc90ce90303228ed8cc3  COPYING
 9846081f8109dc9149dc026b89fbf137  CSWcswclassutils.i.cswcpsampleconf
-9a6f5ad4919b78e4083491edcd86db0c  CSWcswclassutils.i.cswcrontab
+c3f8655f3a4c3898af79960d8668e6c3  CSWcswclassutils.i.cswcrontab
 5e2ae2c6bd828061f86d84f09087b06a  CSWcswclassutils.i.cswetcservices
 4a0971d15bc02e7496f876336c68ddf4  CSWcswclassutils.i.cswinetd
 6abb13158fee906870d1d68dc0fae6f3  CSWcswclassutils.i.cswinitsmf
@@ -9,9 +9,9 @@
 0fc6128391af4c9aebf72b84755532cb  CSWcswclassutils.i.cswpreserveconf
 9018419febe06c12e89d66cc76e7261f  CSWcswclassutils.i.cswpycompile
 4f816acb06e8f95add6faf8607859da2  CSWcswclassutils.i.cswtexinfo
-5071bfb677bcdeda35ccdb9cd6f56f34  CSWcswclassutils.i.cswusergroup
+e906a50bc2d82e341f78d582f32ecb88  CSWcswclassutils.i.cswusergroup
 d278a28a6f901c4ff5f07c583b4cff3d  CSWcswclassutils.r.cswcpsampleconf
-a204ca80139dd1d79e1a3af3e8bad7cb  CSWcswclassutils.r.cswcrontab
+cab36ddd88277add693740a36b199efb  CSWcswclassutils.r.cswcrontab
 d60261ddc46e2cc83ecbbfc586a7e686  CSWcswclassutils.r.cswetcservices
 9039ea60ad4c3f8994205fb242a49a72  CSWcswclassutils.r.cswinetd
 791db9c2f6685aca67043820d260fc60  CSWcswclassutils.r.cswinitsmf

Modified: csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswcrontab
===================================================================
--- csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswcrontab	2010-05-20 14:45:27 UTC (rev 9939)
+++ csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswcrontab	2010-05-20 16:26:17 UTC (rev 9940)
@@ -3,14 +3,59 @@
 # i.cswcrontab - Class action script
 #                for registration of crontab entries
 #
-# Written and maintained by Dagobert Michelsen
+#   Written and   maintained by Dagobert Michelsen
+# Rewritten and unmaintained by Maciej Bliziński
 #
 
-# set DEBUG to any value to enable trace output
-DEBUG=
+set -e
+set -u
 
+if [ -r ${PKG_INSTALL_ROOT:-}/opt/csw/etc/csw.conf ] ; then
+  . ${PKG_INSTALL_ROOT:-}/opt/csw/etc/csw.conf
+fi
+if [ -r ${PKG_INSTALL_ROOT:-}/etc/opt/csw/csw.conf ] ; then
+  . ${PKG_INSTALL_ROOT:-}/etc/opt/csw/csw.conf
+fi
 echo "Installing class <cswcrontab> ..."
 
+if [ -z "${PKGINST}" ]; then
+  echo 'PKGINST is empty!'
+fi
+
+crontab_tag="Added by cswcrontab for"
+readonly crontab_tag
+
+remove_cron_lines() {
+  # Removed marked lines from a file.
+  # states: 1: reading a line, switching to 2 if matches
+  #         2: removing a line
+  cron_id="$1"
+  cron_file="$2"
+  state=1
+  rm -f "${cron_file}"
+  touch "${cron_file}"
+  while read LINE; do
+    if [ ${state} -eq 1 ]; then
+      if echo "${LINE}" | grep "^# ${crontab_tag} ${cron_id}\$" >/dev/null; then
+        state=2
+        continue
+      fi
+      if [ ${state} -eq 2 ]; then
+        echo >/dev/null # ...since /bin/sh doesn't understand negation
+        state=1
+      else
+        echo "${LINE}" >> "${cron_file}"
+      fi
+    fi
+  done
+}
+
+debug() {
+  if [ -n "${classutils_debug:-}" ]; then
+    echo >&2 "DEBUG: $*"
+  fi
+}
+
 while read src dest; do
 
   echo $dest
@@ -23,28 +68,27 @@
   TMPFILE=/tmp/cswcrontab.${PKGINST}.$$
 
   umask 600
-  /usr/bin/crontab -l ${USERNAME} | /usr/bin/grep -v "# Added by ${PKGINST}\$" > ${TMPFILE}
+  /usr/bin/crontab -l ${USERNAME} | remove_cron_lines "${PKGINST}" "${TMPFILE}"
 
-  if [ -n "$DEBUG" ]; then
-    echo "DEBUG: Contents of ${TMPFILE} after removing old lines from this package:" >&2
+  debug "Contents of ${TMPFILE} after removing old lines from this package:"
+  if [ -n "${classutils_debug:-}" ]; then
     cat ${TMPFILE} >&2
   fi
 
-  cat $dest | while read LINE; do
-    echo "${LINE} % Added by ${PKGINST}" >> ${TMPFILE}
-    if [ -n "$DEBUG" ]; then
-      echo "DEBUG: Adding '${LINE} % Added by ${PKGINST}' to the end of the crontab" >&2
-    fi
-  done
+  while read LINE; do
+    echo "# ${crontab_tag} ${PKGINST}" >> ${TMPFILE}
+    echo "${LINE}" >> ${TMPFILE}
+    debug "Adding '${LINE}' to the end of the crontab"
+  done < $dest
 
-  if [ -n "$DEBUG" ]; then
-    echo "DEBUG: Installing crontab for user '${USERNAME}'" >&2
-    cat ${TMPFILE} >&2
+  if [ -n "${classutils_debug:-}" ]; then
+    debug "Installing crontab for user '${USERNAME}'"
+    cat "${TMPFILE}" >&2
   fi
 
-  su ${USERNAME} /usr/bin/crontab ${TMPFILE}
-  rm -f ${TMPFILE}
-  
+  su ${USERNAME} -c "/usr/bin/crontab \"${TMPFILE}\""
+  rm -f "${TMPFILE}"
+
 done
 
 exit 0

Modified: csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.r.cswcrontab
===================================================================
--- csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.r.cswcrontab	2010-05-20 14:45:27 UTC (rev 9939)
+++ csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.r.cswcrontab	2010-05-20 16:26:17 UTC (rev 9940)
@@ -3,12 +3,61 @@
 # r.cswcrontab - Class action script
 #                for registration of crontab entries
 #
-# Written and maintained by Dagobert Michelsen
+#   Written and   maintained by Dagobert Michelsen
+# Rewritten and unmaintained by Maciej Bliziński
 #
 
+set -e
+set -u
+
+if [ -r ${PKG_INSTALL_ROOT:-}/opt/csw/etc/csw.conf ] ; then
+  . ${PKG_INSTALL_ROOT:-}/opt/csw/etc/csw.conf
+fi
+if [ -r ${PKG_INSTALL_ROOT:-}/etc/opt/csw/csw.conf ] ; then
+  . ${PKG_INSTALL_ROOT:-}/etc/opt/csw/csw.conf
+fi
 echo "Removing class <cswcrontab> ..."
 
+if [ -z "${PKGINST}" ]; then
+  echo 'PKGINST is empty!'
+fi
+
+crontab_tag="Added by cswcrontab for"
+readonly crontab_tag
+
+remove_cron_lines() {
+  # Removed marked lines from a file.
+  # states: 1: reading a line, switching to 2 if matches
+  #         2: removing a line
+  cron_id="$1"
+  cron_file="$2"
+  state=1
+  rm -f "${cron_file}"
+  touch "${cron_file}"
+  while read LINE; do
+    if [ ${state} -eq 1 ]; then
+      if echo "${LINE}" | grep "^# ${crontab_tag} ${cron_id}\$" >/dev/null; then
+        state=2
+        continue
+      fi
+      if [ ${state} -eq 2 ]; then
+        echo >/dev/null # ...since /bin/sh doesn't understand negation
+        state=1
+      else
+        echo "${LINE}" >> "${cron_file}"
+      fi
+    fi
+  done
+}
+
+debug() {
+  if [ -n "${classutils_debug:-}" ]; then
+    echo >&2 "DEBUG: $*"
+  fi
+}
+
 while read dest; do
+
   echo $dest
   rm -f $dest
 
@@ -16,18 +65,17 @@
   TMPFILE=/tmp/cswcrontab.${PKGINST}.$$
 
   umask 600
+  /usr/bin/crontab -l ${USERNAME} | remove_cron_lines "${PKGINST}" "${TMPFILE}"
 
-  echo "The following lines will be removed from the crontab of the user '${USERNAME}':"
-  /usr/bin/crontab -l ${USERNAME} | /usr/bin/grep "# Added by ${PKGINST}\$"
 
-  /usr/bin/crontab -l ${USERNAME} | /usr/bin/grep -v "# Added by ${PKGINST}\$" > ${TMPFILE}
-
-  if [ -n "$DEBUG" ]; then
-    echo "DEBUG: Installing crontab for user '${USERNAME}'" >&2
-    cat ${TMPFILE} >&2
+  if [ -n "${classutils_debug:-}" ]; then
+    debug "Installing crontab for user '${USERNAME}'"
+    cat "${TMPFILE}" >&2
   fi
 
-  su ${USERNAME} /usr/bin/crontab ${TMPFILE}
-  rm -f ${TMPFILE}
- 
+  su ${USERNAME} -c "/usr/bin/crontab \"${TMPFILE}\""
+  rm -f "${TMPFILE}"
+
 done
+
+exit 0


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


More information about the devel mailing list