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

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.2     ! raeburn     6: <!-- $Id: cron_lpmlcheck.piml,v 1.1 2004/06/23 14:41:38 matthew 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]);
        !            79:                 if ($custom{$commands[$i]} ne $configs[$i]) {
        !            80:                     print $newfh $custom{$commands[$i]}.$unesc;
        !            81:                     if (ref($customargs{$commands[$i]}) eq 'ARRAY') {
        !            82:                         if (@{$customargs{$commands[$i]}} > 0) {
        !            83:                             print $newfh ' '.join(' ',@{$customargs{$commands[$i]}});
        !            84:                         }
        !            85:                     }
        !            86:                     print $newfh "\n";
        !            87:                     $changes ++;
        !            88:                 } else {
        !            89:                     print $newfh $standard[$i]."\n";
        !            90:                 }
        !            91:                 $checked{$commands[$i]} = 1;
        !            92:             } else {
        !            93:                 print $newfh $standard[$i]."\n";
        !            94:             }
        !            95:         }
        !            96:         foreach my $key (sort(keys(%custom))) {
        !            97:             unless ($checked{$key}) {
        !            98:                 my $unesc = &unescape($key);
        !            99:                 print $newfh $custom{$key}.$unesc;
        !           100:                 if (ref($customargs{$key}) eq 'ARRAY') {
        !           101:                     if (@{$customargs{$key}} > 0) {
        !           102:                         print $newfh ' '.join(' ',@{$customargs{$key}});
        !           103:                     }
        !           104:                 }
        !           105:                 print $newfh "\n";
        !           106:             }
        !           107:         }
        !           108:         close($newfh);
        !           109:     }
        !           110: }
        !           111: if ($changes&gt;1) {
        !           112:     print "$changes customized lines preserved in /etc/cron.d/loncapa\n"; 
        !           113: } elsif ($changes==1) {
        !           114:     print "One customized line preserved in /etc/cron.d/loncapa\n"; 
        !           115: }
        !           116: 
        !           117: sub escape {
        !           118:     my $str=shift;
        !           119:     $str =~ s/(\W)/"%".unpack('H2',$1)/eg;
        !           120:     return $str;
        !           121: }
        !           122: 
        !           123: sub unescape {
        !           124:     my $str=shift;
        !           125:     $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
        !           126:     return $str;
        !           127: }
1.1       matthew   128: </perlscript>
                    129: </file>
                    130: </files>
                    131: </piml>

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