Annotation of doc/loncapafiles/cron_lpmlcheck.piml, revision 1.3

1.1       matthew     1: <!DOCTYPE piml PUBLIC "-//TUX/DTD piml 1.0 Final//EN" 
                      2: 	"http://lpml.sourceforge.net/DTD/piml.dtd">
                      3: <!-- cron_lpmlcheck.piml -->
                      4: <!-- Matthew Hall -->
                      5: 
1.3     ! raeburn     6: <!-- $Id: cron_lpmlcheck.piml,v 1.2 2010/05/23 16:07:09 raeburn Exp $ -->
1.1       matthew     7: 
                      8: <!--
                      9: 
                     10: This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                     11: 
                     12: LON-CAPA is free software; you can redistribute it and/or modify
                     13: it under the terms of the GNU General Public License as published by
                     14: the Free Software Foundation; either version 2 of the License, or
                     15: (at your option) any later version.
                     16: 
                     17: LON-CAPA is distributed in the hope that it will be useful,
                     18: but WITHOUT ANY WARRANTY; without even the implied warranty of
                     19: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     20: GNU General Public License for more details.
                     21: 
                     22: You should have received a copy of the GNU General Public License
                     23: along with LON-CAPA; if not, write to the Free Software
                     24: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     25: 
                     26: /home/httpd/html/adm/gpl.txt
                     27: 
                     28: http://www.lon-capa.org/
                     29: 
                     30: -->
                     31: 
                     32: <piml>
                     33: <targetroot>/</targetroot>
                     34: <files>
                     35: <file>
                     36: <target dist="default">/home/httpd/lonUsers</target>
                     37: <perlscript mode="fg">
                     38: if (-e '/etc/cron.d/loncapa.lpmlsave') {
                     39:     unlink ('/etc/cron.d/loncapa.lpmlsave');
                     40: }
1.2       raeburn    41: print "\nUpdating /etc/cron.d/loncapa configuration file\n";
                     42: my (@configs,@commands,@standard,%checked,%custom,%customargs);
                     43: my $count = 0;
                     44: my $changes = 0;
                     45: if (open(my $locfh,"&lt;/home/httpd/lib/perl/loncapa_cron-std")) {
                     46:     while (&lt;$locfh&gt;) {
                     47:         my $line = $_;
                     48:         chomp($line);
                     49:         $standard[$count] = $line;
                     50:         if ($line =~ m{^#?\s*\d+[^/]+/}) {
                     51:             my ($config,$script) = split('/',$line,2);
                     52:             $script =~ s/\s+$//;
                     53:             my ($cmd,@args) = split(/\s+/,$script);
                     54:             $commands[$count] = &escape('/'.$cmd);
                     55:             $configs[$count] = $config;
                     56:         }
                     57:         $standard[$count] = $line;
                     58:         $count ++;
                     59:     }
                     60:     close($locfh);
                     61:     if (open(my $stdfh,"&lt;/etc/cron.d/loncapa")) {
                     62:         while(&lt;$stdfh&gt;) {
                     63:             my $line = $_;
                     64:             chomp($line);
                     65:             if ($line =~ m{#?\s*\d+[^/]+/}) {
                     66:                 my ($config,$script) = split('/',$line,2);
                     67:                 $script =~ s/\s+$//;
                     68:                 my ($cmd,@args) = split(/\s+/,$script);
                     69:                 my $key = &escape('/'.$cmd);
                     70:                 $custom{$key} = $config;
                     71:                 $customargs{$key} = \@args;
                     72:             }
                     73:         }
                     74:     }
                     75:     if (open(my $newfh,"&gt;/etc/cron.d/loncapa")) {
                     76:         for (my $i=0; $i<@standard; $i++) {
                     77:             if ($commands[$i] ne '') {
                     78:                 my $unesc = &unescape($commands[$i]);
1.3     ! raeburn    79:                 if ($custom{$commands[$i]} eq '') {
        !            80:                     print $newfh $standard[$i]."\n";
        !            81:                 } elsif ($custom{$commands[$i]} ne $configs[$i]) {
1.2       raeburn    82:                     print $newfh $custom{$commands[$i]}.$unesc;
                     83:                     if (ref($customargs{$commands[$i]}) eq 'ARRAY') {
                     84:                         if (@{$customargs{$commands[$i]}} > 0) {
                     85:                             print $newfh ' '.join(' ',@{$customargs{$commands[$i]}});
                     86:                         }
                     87:                     }
                     88:                     print $newfh "\n";
                     89:                     $changes ++;
                     90:                 } else {
                     91:                     print $newfh $standard[$i]."\n";
                     92:                 }
                     93:                 $checked{$commands[$i]} = 1;
                     94:             } else {
                     95:                 print $newfh $standard[$i]."\n";
                     96:             }
                     97:         }
                     98:         foreach my $key (sort(keys(%custom))) {
                     99:             unless ($checked{$key}) {
                    100:                 my $unesc = &unescape($key);
                    101:                 print $newfh $custom{$key}.$unesc;
                    102:                 if (ref($customargs{$key}) eq 'ARRAY') {
                    103:                     if (@{$customargs{$key}} > 0) {
                    104:                         print $newfh ' '.join(' ',@{$customargs{$key}});
                    105:                     }
                    106:                 }
                    107:                 print $newfh "\n";
                    108:             }
                    109:         }
                    110:         close($newfh);
                    111:     }
                    112: }
                    113: if ($changes&gt;1) {
                    114:     print "$changes customized lines preserved in /etc/cron.d/loncapa\n"; 
                    115: } elsif ($changes==1) {
                    116:     print "One customized line preserved in /etc/cron.d/loncapa\n"; 
                    117: }
                    118: 
                    119: sub escape {
                    120:     my $str=shift;
                    121:     $str =~ s/(\W)/"%".unpack('H2',$1)/eg;
                    122:     return $str;
                    123: }
                    124: 
                    125: sub unescape {
                    126:     my $str=shift;
                    127:     $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                    128:     return $str;
                    129: }
1.1       matthew   130: </perlscript>
                    131: </file>
                    132: </files>
                    133: </piml>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>