martin: server/perl-kolab/Kolab-Conf Conf.pm.in,1.10,1.11

cvs at kolab.org cvs at kolab.org
Mon Jun 4 08:41:12 CEST 2007


Author: martin

Update of /kolabrepository/server/perl-kolab/Kolab-Conf
In directory doto:/tmp/cvs-serv2989

Modified Files:
	Conf.pm.in 
Log Message:
Martin Konold: Added support for running explicit command on change as definable in template https://intevation.de/roundup/kolab/issue1679?


Index: Conf.pm.in
===================================================================
RCS file: /kolabrepository/server/perl-kolab/Kolab-Conf/Conf.pm.in,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- Conf.pm.in	6 Jan 2007 21:36:20 -0000	1.10
+++ Conf.pm.in	4 Jun 2007 06:41:10 -0000	1.11
@@ -75,6 +75,7 @@
 my %templates = ();
 my %ownership = ();
 my %permissions = ();
+my %templatehaschanged = ();
 
 # my %templates = (
 # 		 "$templatedir/rc.conf.template" => "@sysconfdir@/rc.conf",
@@ -339,6 +340,10 @@
                 $Kolab::haschanged{'amavisd'} = 1;
 	    } elsif ($cfg =~ /clamav/) {
                 $Kolab::haschanged{'clamav'} = 1;
+#} elsif ($cfg =~ /example/) {
+	    } else {
+            	   Kolab::log('T', "`$cfg' change detected ", KOLAB_DEBUG );
+		   $templatehaschanged{$tmpl} = 1;
 	    }
 
             Kolab::log('T', "`$cfg' change detected: $rc", KOLAB_DEBUG );
@@ -730,7 +735,7 @@
 sub loadMetaTemplates
 {	
 	my $templatedir = shift;
-	my ($tref, $pref, $oref) = @_;
+	my ($tref, $pref, $oref, $cmdref) = @_;
 
 	Kolab::log('T', 'Collecting template files', KOLAB_DEBUG );
 	opendir(DIR, $templatedir) or Kolab::log('T', 'Given templatedir $templatedir does not exist!', KOLAB_ERROR );
@@ -738,6 +743,7 @@
 	closedir(DIR);
 
 	foreach my $template (@metatemplates) {
+	 	my $runonchange = undef;
 		#Open each file and check for the META
 		if (open (TEMPLATE, "$templatedir/$template" )) {
 			my $line = <TEMPLATE>;
@@ -746,6 +752,7 @@
 				my ($found_end, $target, $permissions, $ownership);
 				while (<TEMPLATE>) {
 				$line = $_;
+				
 				if (!$found_end) {
 					$found_end = $line =~ /^KOLAB_META_END$/;
 					if (!$found_end && $line) {
@@ -764,6 +771,11 @@
 							$ownership = $value;
 							Kolab::log('T', 'META Ownership '.$ownership, KOLAB_DEBUG );
 						}
+						if ($key =~ /^RUNONCHANGE$/) {
+							$runonchange = $value;
+							Kolab::log('T', 'META Cmd to execute '.$runonchange, KOLAB_DEBUG );
+						}
+
 					}
 				}
 				}
@@ -773,6 +785,8 @@
 				   $$oref{$target} = $ownership;
 				   $permissions = oct($permissions);
 				   $$pref{$target} = $permissions;
+				   my $runcmdtemplate = $templatedir."/".$template;
+				   $$cmdref{$runcmdtemplate} = $runonchange if (defined $runonchange);
 				}
 				
 			}
@@ -788,12 +802,13 @@
     my $key;
     my $value;
     my $section="";
+    my %runonchange;
 
 
     Kolab::log('T', 'Regenerating configuration files', KOLAB_DEBUG );
 
     Kolab::log('T', 'Loading meta-template data', KOLAB_DEBUG );
-    loadMetaTemplates( $templatedir, \%templates, \%permissions, \%ownership );
+    loadMetaTemplates( $templatedir, \%templates, \%permissions, \%ownership, \%runonchange );
 
     foreach $key (keys %templates) {
       my $tpl = $templates{$key};
@@ -809,6 +824,16 @@
     buildCyrusGroups;
 
     Kolab::log('T', 'Finished regenerating configuration files', KOLAB_DEBUG );
+
+    foreach $key (keys %runonchange) {
+	   if (defined $templatehaschanged{$key})
+	   {
+                  Kolab::log('T', 'Actioning RUNONCHANGE for $key', KOLAB_DEBUG );
+		  my $cmd = $runonchange{$key};
+		  system($cmd);
+		  Kolab::log('T', 'Executing command', KOLAB_DEBUG );
+	   }
+    }
 }
 
 sub checkPermissions {
@@ -869,7 +894,7 @@
 Portions based on work by the following people:
 
   (c) 2003  Tassilo Erlewein  <tassilo.erlewein at erfrakon.de>
-  (c) 2003  Martin Konold     <martin.konold at erfrakon.de>
+  (c) 2003,2004,255,2006,2007  Martin Konold     <martin.konold at erfrakon.de>
   (c) 2003  Achim Frank       <achim.frank at erfrakon.de>
 
 This  program is free  software; you can redistribute  it and/or





More information about the commits mailing list