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

bdwalton at users.sourceforge.net bdwalton at users.sourceforge.net
Mon Jul 30 03:14:22 CEST 2012


Revision: 18871
          http://gar.svn.sourceforge.net/gar/?rev=18871&view=rev
Author:   bdwalton
Date:     2012-07-30 01:14:22 +0000 (Mon, 30 Jul 2012)
Log Message:
-----------
i.cswcrontab: protect against first run where user has no crontab; mantis 4887

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

Modified: csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswcrontab
===================================================================
--- csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswcrontab	2012-07-29 08:14:53 UTC (rev 18870)
+++ csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswcrontab	2012-07-30 01:14:22 UTC (rev 18871)
@@ -68,12 +68,14 @@
 
   TMPFILE=/tmp/cswcrontab.${PKGINST}.$$
 
-  umask 600
-  /usr/bin/crontab -l ${USERNAME} | remove_cron_lines "${PKGINST}" "${TMPFILE}"
+  if [ -f "/var/spool/cron/crontabs/${USERNAME}" ]; then
+      umask 600
+      /usr/bin/crontab -l ${USERNAME} | remove_cron_lines "${PKGINST}" "${TMPFILE}"
 
-  debug "Contents of ${TMPFILE} after removing old lines from this package:"
-  if [ -n "${classutils_debug:-}" ]; then
-    cat ${TMPFILE} >&2
+      debug "Contents of ${TMPFILE} after removing old lines from this package:"
+      if [ -n "${classutils_debug:-}" ]; then
+	  cat ${TMPFILE} >&2
+      fi
   fi
 
   while read LINE; do

Modified: csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswinitsmf
===================================================================
--- csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswinitsmf	2012-07-29 08:14:53 UTC (rev 18870)
+++ csw/mgar/pkg/cswclassutils/trunk/files/CSWcswclassutils.i.cswinitsmf	2012-07-30 01:14:22 UTC (rev 18871)
@@ -23,6 +23,7 @@
 # 2009-08-10 Fix autoenable bug (Bug ID 0003785)
 # 2010-10-25 Fix grep bug in FMRI 'dot in name' detection (Bug ID 0004588)
 # 2011-04-21 Read absolute state value instead of defaulting to enabled
+# 2012-07-26 Better handle -R (alt root) for BE patching, etc. -bw
 
 DEBUG=		# clear to disable debug, set to anything to enable
 SVCDIR=/var/opt/csw/svc
@@ -110,11 +111,11 @@
     testpath=$SVCDIR/manifest
     for i in `echo $FMRI | sed 's/\// /g'`; do
       testpath=$testpath/$i
-      if [ ! -d $testpath ]; then
+      if [ ! -d $PKG_INSTALL_ROOT/$testpath ]; then
         echo Creating $testpath ...
-        /usr/bin/mkdir $testpath
-        /usr/bin/chown root:bin $testpath
-        /usr/bin/chmod 755 $testpath
+        /usr/bin/mkdir $PKG_INSTALL_ROOT/$testpath
+        /usr/bin/chown root:bin $PKG_INSTALL_ROOT/$testpath
+        /usr/bin/chmod 755 $PKG_INSTALL_ROOT/$testpath
         /usr/sbin/installf -c cswinitsmf $PKGINST $testpath d 755 root bin
       fi
     done
@@ -122,10 +123,10 @@
       echo FMRI: $FMRI
     fi
     echo Creating service script in $SVCDIR/method/svc-$service ...
-    /usr/bin/ln -s $dest $SVCDIR/method/svc-$service
+    /usr/bin/ln -s $dest $PKG_INSTALL_ROOT/$SVCDIR/method/svc-$service
     /usr/sbin/installf -c cswinitsmf $PKGINST $SVCDIR/method/svc-$service=$dest s
-    /usr/bin/chmod 755 $SVCDIR/method/svc-$service
-    /usr/bin/chown root:bin $SVCDIR/method/svc-$service
+    /usr/bin/chmod 755 $PKG_INSTALL_ROOT/$SVCDIR/method/svc-$service
+    /usr/bin/chown root:bin $PKG_INSTALL_ROOT/$SVCDIR/method/svc-$service
 
     MANIFEST=
     if [ "`grep '^#MANIFEST' $dest`" ]; then
@@ -136,7 +137,7 @@
       echo Creating manifest ...
       # Add first part of manifest
       MANIFEST=$SVCDIR/manifest/$FMRI/$service.xml
-      cat > $MANIFEST << EOF
+      cat > $PKG_INSTALL_ROOT/$MANIFEST << EOF
 <?xml version='1.0'?>
 <!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
 <!--
@@ -185,8 +186,8 @@
 EOF
 
       # Add restart option to manifest if service script supports it
-      if [ "`/usr/bin/egrep 'restart.?\)' $SVCDIR/method/svc-$service`" ]; then
-        cat >> $MANIFEST << EOF
+      if [ "`/usr/bin/egrep 'restart.?\)' $PKG_INSTALL_ROOT/$SVCDIR/method/svc-$service`" ]; then
+        cat >> $PKG_INSTALL_ROOT/$MANIFEST << EOF
   <exec_method
     type='method'
     name='restart'
@@ -198,8 +199,8 @@
       fi
 
       # Add refresh option to manifest if service script supports it
-      if [ "`/usr/bin/egrep 'refresh.?\)' $SVCDIR/method/svc-$service`" ]; then
-        cat >> $MANIFEST << EOF
+      if [ "`/usr/bin/egrep 'refresh.?\)' $PKG_INSTALL_ROOT/$SVCDIR/method/svc-$service`" ]; then
+        cat >> $PKG_INSTALL_ROOT/$MANIFEST << EOF
   <exec_method
     type='method'
     name='refresh'
@@ -211,14 +212,14 @@
       fi
 
       # Add last part of manifest
-      cat >> $MANIFEST << EOF
+      cat >> $PKG_INSTALL_ROOT/$MANIFEST << EOF
 </service>
 
 </service_bundle>
 EOF
       /usr/sbin/installf -c cswinitsmf $PKGINST $MANIFEST f 644 root bin
-      /usr/bin/chmod 644 $MANIFEST
-      /usr/bin/chown root:bin $MANIFEST
+      /usr/bin/chmod 644 $PKG_INSTALL_ROOT/$MANIFEST
+      /usr/bin/chown root:bin $PKG_INSTALL_ROOT/$MANIFEST
     else
       # Custom manifest
       echo Using custom manifest ...
@@ -230,8 +231,10 @@
 
     # Register with SMF
     echo Configuring service in SMF ...
-    /usr/sbin/svccfg import $MANIFEST > /dev/null 2>&1
-    /usr/sbin/svcadm disable svc:/$FMRI/$service > /dev/null 2>&1
+    chroot ${PKG_INSTALL_ROOT:-/} /usr/sbin/svccfg import $MANIFEST > /dev/null 2>&1
+    if [ "${PKG_INSTALL_ROOT:-/}" != "/" ]; then
+	/usr/sbin/svcadm disable svc:/$FMRI/$service > /dev/null 2>&1
+    fi
     echo $PKGINST is using Service Management Facility. The FMRI is svc:/$FMRI/$service:default
 
     # Start service
@@ -244,7 +247,7 @@
     # enable the service if it was enabled before, OR if $daemon = yes and AUTOENABLE is set
     # previous SMF state always takes precedence
     # note: autoenable_daemons and autoenable_$service controls $daemon, $AUTOENABLE is set by the package itself
-    if [ "$SMF_STATE" = "enabled" ] || [ "$daemon" = "yes" -a "$AUTOENABLE" != "no" -a "$AUTOENABLE" != "false" ]; then
+    if [ "$SMF_STATE" = "enabled" ] || [ "$daemon" = "yes" -a "$AUTOENABLE" != "no" -a "$AUTOENABLE" != "false" -a "${PKG_INSTALL_ROOT:-/}" = "/" ]; then
       echo "Clearing svc:/$FMRI/$service in case it's in the maintenance state..."
       /usr/sbin/svcadm clear svc:/$FMRI/$service > /dev/null 2>&1
       echo Enabling svc:/$FMRI/$service ...
@@ -257,7 +260,7 @@
 
     # Create link to /etc/init.d
     echo /etc/init.d/$service
-    /usr/bin/ln -s $dest /etc/init.d/$service
+    /usr/bin/ln -s $dest ${PKG_INSTALL_ROOT}/etc/init.d/$service
     /usr/sbin/installf -c cswinitsmf $PKGINST /etc/init.d/$service=$dest s
 
     # Create rc-symlinks if enabled
@@ -301,12 +304,12 @@
       for i in $RC_KLEV; do
         echo /etc/rc$i.d/K$RC_KNUM$service
         /usr/sbin/installf -c cswinitsmf $PKGINST /etc/rc$i.d/K$RC_KNUM$service=/etc/init.d/$service s
-        /bin/ln -s /etc/init.d/$service /etc/rc$i.d/K$RC_KNUM$service
+        /bin/ln -s /etc/init.d/$service ${PKG_INSTALL_ROOT}/etc/rc$i.d/K$RC_KNUM$service
       done
       for i in $RC_SLEV; do
         echo /etc/rc$i.d/S$RC_SNUM$service
         /usr/sbin/installf -c cswinitsmf $PKGINST /etc/rc$i.d/S$RC_SNUM$service=/etc/init.d/$service s
-        /bin/ln -s /etc/init.d/$service /etc/rc$i.d/S$RC_SNUM$service
+        /bin/ln -s /etc/init.d/$service ${PKG_INSTALL_ROOT}/etc/rc$i.d/S$RC_SNUM$service
       done
 
       # Start service
@@ -317,8 +320,10 @@
       if [ "$AUTOENABLE" != "no" -a "$AUTOENABLE" != "false" ]; then
         echo Starting $service ...
         # fix permissions temporarily since 644 is used until verification
-        /usr/bin/chmod 744 /etc/init.d/$service
-        /etc/init.d/$service start > /dev/null 2>&1
+        /usr/bin/chmod 744 ${PKG_INSTALL_ROOT}/etc/init.d/$service
+	if [ "${PKG_INSTALL_ROOT:-/}" = "/" ]; then
+            /etc/init.d/$service start > /dev/null 2>&1
+	fi
       fi
     fi
   fi

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