File:
[LON-CAPA] /
doc /
loncapafiles /
cron_lpmlcheck.piml
Revision
1.3:
download - view:
text,
annotated -
select for diffs
Fri Jun 25 16:39:01 2010 UTC (14 years, 2 months ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_9_X,
version_2_9_1,
version_2_12_X,
version_2_11_X,
version_2_11_5_msu,
version_2_11_5,
version_2_11_4_uiuc,
version_2_11_4_msu,
version_2_11_4,
version_2_11_3_uiuc,
version_2_11_3_msu,
version_2_11_3,
version_2_11_2_uiuc,
version_2_11_2_msu,
version_2_11_2_educog,
version_2_11_2,
version_2_11_1,
version_2_11_0_RC3,
version_2_11_0_RC2,
version_2_11_0_RC1,
version_2_11_0,
version_2_10_X,
version_2_10_1,
version_2_10_0_RC2,
version_2_10_0_RC1,
version_2_10_0,
loncapaMITrelate_1,
language_hyphenation_merge,
language_hyphenation,
HEAD,
BZ4492-merge,
BZ4492-feature_horizontal_radioresponse,
BZ4492-feature_Support_horizontal_radioresponse,
BZ4492-Support_horizontal_radioresponse
- Prevent removal of configuration items before the script path in new entries in loncapa
cron.
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:
6: <!-- $Id: cron_lpmlcheck.piml,v 1.3 2010/06/25 16:39:01 raeburn Exp $ -->
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: }
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,"</home/httpd/lib/perl/loncapa_cron-std")) {
46: while (<$locfh>) {
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,"</etc/cron.d/loncapa")) {
62: while(<$stdfh>) {
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,">/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]} eq '') {
80: print $newfh $standard[$i]."\n";
81: } elsif ($custom{$commands[$i]} ne $configs[$i]) {
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>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: }
130: </perlscript>
131: </file>
132: </files>
133: </piml>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>