Annotation of loncom/debugging_tools/modify_config_files.pl, revision 1.20
1.1 matthew 1: #!/usr/bin/perl -w
2: #
3: # The LearningOnline Network
4: #
1.20 ! raeburn 5: # $Id: modify_config_files.pl,v 1.19 2021/03/22 21:15:53 raeburn Exp $
1.1 matthew 6: #
7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
27: # http://www.lon-capa.org/
28: #
29: ###
30:
31: =pod
32:
33: =head1 NAME
34:
35: B<modify_config_files.pl>
36:
37: =head1 SYNOPSIS
38:
1.9 raeburn 39: This script modifies /etc/my.cnf and one of: /etc/yum.conf
1.16 raeburn 40: (for CentOS/Scientific Linux/RHEL >=5 and <8), /etc/apt/sources.list
1.13 raeburn 41: (for Debian/Ubuntu), /etc/sysconfig/rhn/sources (for RHEL4),
1.16 raeburn 42: and /etc/yum.repos.d/loncapa.repo (Fedora >= 21; Oracle Linux;
43: CentOS/RHEL >= 8).
1.1 matthew 44:
45: =head1 DESCRIPTION
46:
1.13 raeburn 47: This script modifies /etc/my.cnf, /etc/yum.conf, /etc/yum.repos.d/loncapa.repo,
48: /etc/apt/sources, or /etc/sysconfig/rhn/sources to ensure certain
49: parameters are set properly.
50:
51: The LON-CAPA yum repositories are added to /etc/yum.conf,
52: /etc/yum.repos.d/loncapa.repo, /etc/sysconfig/rhn/sources
53: and the LON-CAPA apt repositories are added to
1.9 raeburn 54: /etc/apt/sources.list.
55:
1.1 matthew 56: The /etc/my.cnf file is modified to set the wait_timeout to 1 year. Backup
1.9 raeburn 57: copies of each file are made in /etc, /etc/apt, and /etc/sysconfig/rhn, as
58: appropriate.
1.1 matthew 59:
60: =cut
61:
62: use strict;
63: use File::Copy;
1.3 matthew 64: use lib '/home/httpd/lib/perl/';
65: use LONCAPA::Configuration;
66: my $loncapa_config=LONCAPA::Configuration::read_conf('loncapa.conf');
1.1 matthew 67:
1.6 raeburn 68: open(DSH,"$$loncapa_config{'lonDaemons'}/distprobe |");
69: my $dist = <DSH>;
70: chomp($dist);
71: close(DSH);
72:
73: my $yum_status;
1.9 raeburn 74: my $loninst = 'http://install.loncapa.org';
75: my $loninst_re = 'http://install\.loncapa\.org';
76: if ($dist =~ /^fedora(\d+)$/) {
1.13 raeburn 77: my $file = '/etc/yum.conf';
1.9 raeburn 78: my $ver = $1;
1.10 raeburn 79: my $gpgchk = '0';
1.9 raeburn 80: my $gpg = "$loninst/versions/fedora/RPM-GPG-KEY-loncapa";
1.13 raeburn 81: my $nobackup;
1.9 raeburn 82: if ($ver > 6) {
1.10 raeburn 83: $gpgchk = '1';
1.9 raeburn 84: }
1.13 raeburn 85: if ($ver >= 21) {
86: $file = '/etc/yum.repos.d/loncapa.repo';
87: $nobackup = 1;
88: }
1.6 raeburn 89: $yum_status =
1.13 raeburn 90: &update_file($file,
1.10 raeburn 91: [{section => 'loncapa-updates-basearch',
1.1 matthew 92: key => 'name=',
1.6 raeburn 93: value => 'Fedora Core $releasever LON-CAPA $basearch Updates',
1.10 raeburn 94: }, {section => 'loncapa-updates-basearch',
1.1 matthew 95: key => 'baseurl=',
1.9 raeburn 96: value => $loninst.'/fedora/linux/loncapa/$releasever/$basearch',
1.10 raeburn 97: }, {section => 'loncapa-updates-basearch',
1.5 matthew 98: key => 'gpgcheck=',
1.9 raeburn 99: value => $gpgchk,
1.10 raeburn 100: }, {section => 'loncapa-updates-basearch',
1.13 raeburn 101: key => 'gpgkey=',
1.9 raeburn 102: value => $gpg,
1.1 matthew 103: }, {section => 'loncapa-updates-noarch',
104: key => 'name=',
105: value => 'Fedora Core $releasever LON-CAPA noarch Updates',
106: }, {section => 'loncapa-updates-noarch',
107: key => 'baseurl=',
1.9 raeburn 108: value => $loninst.'/fedora/linux/loncapa/$releasever/noarch',
1.5 matthew 109: }, {section => 'loncapa-updates-noarch',
110: key => 'gpgcheck=',
1.9 raeburn 111: value => $gpgchk,
112: }, {section => 'loncapa-updates-noarch',
1.13 raeburn 113: key => 'gpgkey=',
1.9 raeburn 114: value => $gpg,
1.13 raeburn 115: }],$nobackup);
1.15 raeburn 116: } elsif ($dist =~ /^(rhes|centos|scientific|oracle)(\d+)$/) {
1.9 raeburn 117: my $type = $1;
118: my $ver = $2;
119: my $longver = $ver;
1.16 raeburn 120: my $nobackup;
1.9 raeburn 121: if ($type eq 'rhes') {
122: if ($ver == 4) {
123: $longver = '4ES';
124: } elsif ($ver == 5) {
125: $longver = '5Server';
126: }
127: }
128: my %info = (
129: rhes => {
130: title => 'RHEL',
131: path => 'redhat/linux/enterprise/loncapa',
132: gpg => 'versions/redhat/RPM-GPG-KEY-loncapa',
133: gpgchk => 1,
134: },
135: centos => {
136: title => 'CentOS',
137: path => 'centos/loncapa',
138: gpg => 'versions/centos/RPM-GPG-KEY-loncapa',
139: gpgchk => 1,
140: },
141: scientific => {
142: title => 'Scientific Linux',
143: path => 'scientific/loncapa',
144: gpg => 'versions/scientific/RPM-GPG-KEY-loncapa',
145: gpgchk => 1,
146: },
1.15 raeburn 147: oracle => {
148: title => 'Oracle Linux',
149: path => 'oracle/loncapa',
150: gpg => 'versions/oracle/RPM-GPG-KEY-loncapa',
151: gpgchk => 1,
152: },
1.9 raeburn 153: );
154: if (ref($info{$type}) eq 'HASH') {
155: if ($ver > 4) {
1.16 raeburn 156: my $file = '/etc/yum.conf';
157: if (($ver > 7) || ($type eq 'oracle')) {
158: $file = '/etc/yum.repos.d/loncapa.repo';
159: $nobackup = 1;
160: }
1.9 raeburn 161: $yum_status =
1.16 raeburn 162: &update_file($file,
1.9 raeburn 163: [{section => 'loncapa-updates-basearch',
164: key => 'name=',
165: value => $info{$type}{title}.' $releasever LON-CAPA $basearch Updates',
166: }, {section => "loncapa-updates-basearch",
167: key => 'baseurl=',
168: value => "$loninst/$info{$type}{path}/".'$releasever/$basearch',
169: }, {section => 'loncapa-updates-basearch',
170: key => 'gpgcheck=',
1.11 raeburn 171: value => $info{$type}{gpgchk},
1.10 raeburn 172: }, {section => 'loncapa-updates-basearch',
1.9 raeburn 173: key => 'gpgkey=',
174: value => "$loninst/$info{$type}{gpg}",
175: }, {section => 'loncapa-updates-noarch',
176: key => 'name=',
177: value => $info{$type}{title}.' $releasever LON-CAPA noarch Updates',
178: }, {section => 'loncapa-updates-noarch',
179: key => 'baseurl=',
180: value => "$loninst/$info{$type}{path}/".'$releasever/noarch',
181: }, {section => 'loncapa-updates-noarch',
182: key => 'gpgcheck=',
1.11 raeburn 183: value => $info{$type}{gpgchk},
1.9 raeburn 184: }, {section => 'loncapa-updates-noarch',
185: key => 'gpgkey=',
186: value => "$loninst/$info{$type}{gpg}",
1.16 raeburn 187: }],$nobackup);
1.9 raeburn 188: } elsif (($type eq 'rhes') && ($ver == 4)) {
189: my %rhn = (
190: basearch => {
191: regexp => '\s*yum\s+loncapa\-updates\-basearch\s+'.$loninst_re.'/'.$info{$type}{path}.'/'.$longver.'/\$ARCH',
192: text => "yum loncapa-updates-basearch $loninst/$info{$type}{path}/$longver/".'$ARCH',
193: },
194: noarch => {
195: regexp => '\s*yum\s+loncapa\-updates\-noarch\s+'.$loninst_re.'/'.$info{$type}{path}.'/'.$longver.'/noarch',
196: text => "yum loncapa-updates-noarch $loninst/$info{$type}{path}/$longver/noarch",
197: },
198: );
199: $yum_status = &update_rhn_source(\%rhn);
200: }
201: }
202: } elsif ($dist =~ /^(debian|ubuntu)\d+$/) {
203: my %apt_get_source = (
204: debian5 => {
1.18 raeburn 205: regexp => '\s*deb\s+'.$loninst_re.'/debian/?\s+lenny\s+main',
206: text => "deb $loninst/debian lenny main",
1.9 raeburn 207: },
208: ubuntu6 => {
1.18 raeburn 209: regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/?\s+dapper\s+main',
210: text => "deb $loninst/ubuntu dapper main",
1.9 raeburn 211: },
212: ubuntu8 => {
1.18 raeburn 213: regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/?\s+hardy\s+main',
214: text => "deb $loninst/ubuntu hardy main",
1.9 raeburn 215: },
1.14 raeburn 216: ubuntu10 => {
1.18 raeburn 217: regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/?\s+lucid\s+main',
218: text => "deb $loninst/ubuntu lucid main",
1.14 raeburn 219: },
220: ubuntu12 => {
1.18 raeburn 221: regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/?\s+precise\s+main',
222: text => "deb $loninst/ubuntu precise main",
1.14 raeburn 223: },
224: ubuntu14 => {
1.18 raeburn 225: regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/?\s+trusty\s+main',
226: text => "deb $loninst/ubuntu trusty main",
1.14 raeburn 227: },
228: ubuntu16 => {
1.18 raeburn 229: regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/?\s+xenial\s+main',
230: text => "deb $loninst/ubuntu xenial main",
1.14 raeburn 231: },
232: ubuntu18 => {
1.18 raeburn 233: regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/?\s+bionic\s+main',
234: text => "deb $loninst/ubuntu bionic main",
1.14 raeburn 235: },
1.17 raeburn 236: ubuntu20 => {
1.18 raeburn 237: regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/?\s+focal\s+main',
238: text => "deb $loninst/ubuntu focal main",
1.17 raeburn 239: },
1.9 raeburn 240: );
241: my $apt_status;
242: if (defined($apt_get_source{$dist})) {
243: $apt_status = &update_apt_source($apt_get_source{$dist},);
1.6 raeburn 244: }
245: }
1.1 matthew 246:
1.19 raeburn 247: my $mysqlfile = '/etc/my.cnf';
1.20 ! raeburn 248: my $mysqlconf = [{section =>'mysqld',
! 249: key =>'wait_timeout=',
! 250: value =>'31536000'}];
1.19 raeburn 251: if ($dist =~ /^ubuntu(\d+)$/) {
252: my $version = $1;
253: $mysqlfile = '/etc/mysql/my.cnf';
254: if ($version > 14) {
255: $mysqlfile = '/etc/mysql/mysql.conf.d/mysqld.cnf';
1.20 ! raeburn 256: if ($version < 20) {
! 257: push(@{$mysqlconf},
! 258: {section =>'mysqld',
! 259: key =>'sql_mode=',
! 260: value =>'"STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"'});
! 261: } else {
! 262: push(@{$mysqlconf},
! 263: {section =>'mysqld',
! 264: key =>'sql_mode=',
! 265: value =>'"STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"'});
! 266: }
1.19 raeburn 267: }
268: }
269:
1.20 ! raeburn 270: my $mysql_global_status = &update_file($mysqlfile,$mysqlconf);
1.1 matthew 271:
1.3 matthew 272: my $local_my_cnf = '/home/www/.my.cnf';
273: if (! -e $local_my_cnf) {
1.4 matthew 274: # Create a file so we can do something with it...
1.3 matthew 275: system("touch $local_my_cnf");
276: }
1.4 matthew 277: my $mysql_www_status =
278: &update_file($local_my_cnf,
1.3 matthew 279: [{section =>'client',
280: key =>'user=',
281: value =>'www',},
282: {section =>'client',
283: key =>'password=',
284: value =>$loncapa_config->{'lonSqlAccess'}},]);
285:
1.4 matthew 286: my $exitvalue = 0;
287:
288: if ($mysql_global_status) { $exitvalue = 1; }
289:
290: exit $exitvalue;
1.1 matthew 291:
292:
293: sub update_file {
1.13 raeburn 294: my ($file,$newdata,$nobackup) = @_;
1.1 matthew 295: return 1 if (! -e $file);
1.13 raeburn 296: unless ($nobackup) {
297: my $backup = $file.'.backup';
298: if (! copy($file,$backup)) {
299: warn "**** Error: Unable to make backup of $file";
300: return 0;
301: }
1.1 matthew 302: }
303: my ($filedata) = &parse_config_file($file);
1.4 matthew 304: if (! ref($filedata)) { warn "**** Error: $filedata"; return 0;}
305: my $modified = 0;
1.1 matthew 306: foreach my $data (@$newdata) {
307: my $section = $data->{'section'};
308: my $key = $data->{'key'};
309: my $value = $data->{'value'};
1.4 matthew 310: my $result = &modify_config_file($filedata,$section,$key,$value);
311: if ($result) { $modified = 1; }
312: }
313: if ($modified) {
314: my $result = &write_config_file($file,$filedata);
315: if (defined($result)) { warn 'Error:'.$result; return 0; }
1.1 matthew 316: }
1.4 matthew 317: return $modified;
1.1 matthew 318: }
319:
320: #################################################################
321: #################################################################
322:
323: =pod
324:
1.9 raeburn 325: =over 4
326:
327: =item &parse_config_file()
1.1 matthew 328:
329: Read a configuration file in and parse it into an internal data structure.
330:
331: Input: filename
332:
333: Output: array ref $filedata OR scalar error message
334:
1.9 raeburn 335: =back
336:
1.1 matthew 337: =cut
338:
339: #################################################################
340: #################################################################
341: sub parse_config_file {
342: my ($file) = @_;
343: open(INFILE,$file) || return ('Unable to open '.$file.' for reading');
344: my @Input = <INFILE>;
345: close(INFILE);
346: my @Structure;
347: my %Sections;
348: while (my $line = shift(@Input)) {
349: chomp($line);
350: if ($line =~ /^\[([^\]]*)\]/) {
351: my $section_id = $1;
352: push(@Structure,'__section__'.$section_id);
353: while ($line = shift(@Input)) {
1.4 matthew 354: chomp($line);
1.1 matthew 355: if ($line =~ /^\[([^\]]*)\]/) {
356: unshift(@Input,$line);
357: last;
358: } else {
359: push(@{$Sections{$section_id}},$line);
360: }
361: }
362: } else {
363: push(@Structure,$line);
364: }
365: }
366: my $filedata = [\@Structure,\%Sections];
367: return $filedata;
368: }
369:
370: #################################################################
371: #################################################################
372:
373: =pod
374:
1.9 raeburn 375: =over 4
376:
1.1 matthew 377: =item
378:
379: Write a configuration file out based on the internal data structure returned
380: by &parse_config_file
381:
382: Inputs: filename, $filedata (the return value of &parse_config_file
383:
384: Returns: undef on success, scalar error message on failure.
385:
1.9 raeburn 386: =back
387:
1.1 matthew 388: =cut
389:
390: #################################################################
391: #################################################################
392: sub write_config_file {
393: my ($file,$filedata) = @_;
394: my ($structure,$sections) = @$filedata;
395: if (! defined($structure) || ! ref($structure)) {
396: return 'Bad subroutine inputs';
397: }
1.18 raeburn 398: open(OUTPUT,'>',$file) || return('Unable to open '.$file.' for writing');
1.1 matthew 399: for (my $i=0;$i<scalar(@$structure);$i++) {
400: my $line = $structure->[$i];
401: chomp($line);
402: if ($line =~ /^__section__(.*)$/) {
403: my $section_id = $1;
404: print OUTPUT ('['.$section_id.']'.$/);
405: foreach my $section_line (@{$sections->{$section_id}}) {
406: chomp($section_line);
407: print OUTPUT $section_line.$/;
408: }
409: # Deal with blank lines
410: if ($sections->{$section_id}->[-1] =~ /^\s*$/) {
411: # No need to output a blank line at the end if there is one
412: # already
413: } else {
414: print OUTPUT $/;
415: }
416: } else {
417: print OUTPUT $line.$/;
418: }
419: }
420: close OUTPUT;
421: return undef;
422: }
423:
424: #################################################################
425: #################################################################
426:
427: =pod
428:
1.9 raeburn 429: =over 4
430:
431: =item &modify_config_file()
1.1 matthew 432:
433: Modifies the internal data structure of a configuration file to include new
434: sections and/or new configuration directives.
435:
436: Inputs: $filedata (see &parse_config_file
437: $section, the [section] the new entry is to reside in. A value of undef will
438: cause the "outer" section (as in yum.conf) to be updated (or have the new
439: value prepended).
440: $newkey: A line which matches this will be replaced with $newkey.$newvalue
441: $newvalue: The new value to be placed with the new key.
442:
1.4 matthew 443: Returns: 0 or 1, indicating if the file was modified(1) or not(0).
444:
1.9 raeburn 445: =back
1.4 matthew 446:
1.1 matthew 447: =cut
448:
449: #################################################################
450: #################################################################
451: sub modify_config_file {
452: my ($filedata,$section,$newkey,$newvalue)=@_;
1.4 matthew 453: my $modified = 0; # returned value - set to true if the file is modified
1.1 matthew 454: my ($structure,$sections) = @$filedata;
455: if (! defined($newvalue)) {
456: $newvalue = '';
457: }
458: my $newline = $newkey.$newvalue;
459: #
460: # Determine which array ref gets the item
461: my $target;
462: if (defined($section)) {
463: if (! exists($sections->{$section})) {
464: push(@$structure,'__section__'.$section);
465: $sections->{$section}=[];
466: }
467: $target = $sections->{$section};
468: } else {
469: $target = $structure;
470: }
471: #
472: # Put the item in or update it.
473: my $key_is_new = 1;
474: for (my $i=0;$i<scalar(@$target);$i++) {
475: if ($target->[$i] =~/^$newkey/) {
1.4 matthew 476: if ($target->[$i] ne $newline) {
477: $target->[$i]=$newline;
478: $modified = 1;
479: }
1.1 matthew 480: $key_is_new = 0;
481: last;
482: }
483: }
484: if ($key_is_new) {
485: if (! defined($section)) {
486: unshift(@$target,$newline);
487: } else {
488: # No need to put things after a blank line.
1.2 matthew 489: if (defined($target->[-1]) && $target->[-1] =~ /^\s*$/) {
1.1 matthew 490: $target->[-1] = $newline;
1.4 matthew 491: $modified = 1;
1.1 matthew 492: } else {
493: push(@$target,$newline);
1.4 matthew 494: $modified = 1;
1.1 matthew 495: }
496: }
497: }
1.4 matthew 498: return $modified;
1.1 matthew 499: }
500:
1.9 raeburn 501: #################################################################
502: #################################################################
503:
504: =pod
505:
506: =over 4
507:
508: =item &update_rhn_source()
509:
510: Modifies the Red Hat 4 sources file which includes repositories used by up2date
511:
512: Inputs:
513: $rhn_items - a reference to hash of a hash containing the regular expression
514: to test for, and the text string to append to the file, if an entry for the
515: LON-CAPA RHEL repository is missing for two cases:
516:
517: (a) basearch
518: (b) noarch
519:
520: Returns: 0 or 1, indicating if the file was modified(1) or not(0).
521:
522: =back
523:
524: =cut
525:
526: #################################################################
527: #################################################################
528: sub update_rhn_source {
529: my ($rhn_items) = @_;
530: return 0 if (ref($rhn_items) ne 'HASH');
531: return 0 if ((ref($rhn_items->{basearch}) ne 'HASH') || (ref($rhn_items->{noarch}) ne 'HASH'));
532: my $file = '/etc/sysconfig/rhn/sources';
533: return 0 if (! -e $file);
534: my $backup = $file.'.backup';
535: if (! copy($file,$backup)) {
536: warn "**** Error: Unable to make backup of $file";
537: return 0;
538: }
539: my $result = 0;
540: my $fh;
1.18 raeburn 541: if (open($fh,'<',$file)) {
1.9 raeburn 542: my $total = 0;
543: my %found;
544: foreach my $item (keys(%{$rhn_items})) {
545: $found{$item} = 0;
546: }
547: while(<$fh>) {
548: foreach my $item (keys(%{$rhn_items})) {
549: if (ref($rhn_items->{$item}) eq 'HASH') {
550: my $pattern = $rhn_items->{$item}->{regexp};
551: if ($pattern ne '') {
552: if (m{^$pattern}) {
553: $found{$item} = 1;
554: $total ++;
555: }
556: }
557: }
558: }
559: last if $total == 2;
560: }
561: close($fh);
562: if ($total < 2) {
1.18 raeburn 563: if (open($fh,'>>',$file)) {
1.9 raeburn 564: foreach my $item (keys(%{$rhn_items})) {
565: unless ($found{$item}) {
566: if (ref($rhn_items->{$item}) eq 'HASH') {
567: if ($rhn_items->{$item}->{text} ne '') {
568: print $fh "\n".$rhn_items->{$item}->{text}."\n";
569: $result = 1;
570: }
571: }
572: }
573: }
574: close($fh);
575: }
576: }
577: }
578: return $result;
579: }
1.1 matthew 580:
581: #################################################################
582: #################################################################
583:
584: =pod
585:
1.9 raeburn 586: =over 4
587:
588: =item &update_apt_source()
589:
590: Modifies the source.list file which includes repositories used by apt-get
591:
592: Inputs:
593: $deb_row - a reference to containing the regular expression
594: to test for, and the text string to append to the file, if an entry for the
595: LON-CAPA Debian/ or Ubuntu repository is missing.
596:
597: Returns: 0 or 1, indicating if the file was modified(1) or not(0).
598:
1.1 matthew 599: =back
600:
601: =cut
602:
603: #################################################################
604: #################################################################
1.9 raeburn 605: sub update_apt_source {
606: my ($deb_row) = @_;
607: return 0 if (ref($deb_row) ne 'HASH');
608: return 0 if (($deb_row->{regexp} eq '') || ($deb_row->{text} eq ''));
609: my $file = '/etc/apt/sources.list';
610: return 0 if (! -e $file);
611: my $backup = $file.'.backup';
612: if (! copy($file,$backup)) {
613: warn "**** Error: Unable to make backup of $file";
614: return 0;
615: }
616: my $result = 0;
617: my $fh;
1.18 raeburn 618: if (open($fh,'<',$file)) {
1.9 raeburn 619: my $found = 0;
620: my $pattern = $deb_row->{regexp};
621: while(<$fh>) {
622: if (m{^$pattern}) {
623: $found = 1;
624: last;
625: }
626: }
627: close($fh);
628: if (!$found) {
1.18 raeburn 629: if (open($fh,'>>',$file)) {
1.9 raeburn 630: print $fh "\n".$deb_row->{text}."\n";
631: close($fh);
632: $result = 1;
633: }
634: }
635: }
636: return $result;
637: }
638:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>