version 1.2, 2004/08/10 20:26:02
|
version 1.5, 2004/11/19 20:46:07
|
Line 49 copies of each file are made in /etc.
|
Line 49 copies of each file are made in /etc.
|
|
|
use strict; |
use strict; |
use File::Copy; |
use File::Copy; |
|
use lib '/home/httpd/lib/perl/'; |
|
use LONCAPA::Configuration; |
|
my $loncapa_config=LONCAPA::Configuration::read_conf('loncapa.conf'); |
|
|
&update_file('/etc/yum.conf', |
my $yum_status = |
|
&update_file('/etc/yum.conf', |
[{section => 'loncapa-updates-i386', |
[{section => 'loncapa-updates-i386', |
key => 'name=', |
key => 'name=', |
value => 'Fedora Core $releasever LON-CAPA i386 Updates', |
value => 'Fedora Core $releasever LON-CAPA i386 Updates', |
Line 58 use File::Copy;
|
Line 62 use File::Copy;
|
key => 'baseurl=', |
key => 'baseurl=', |
value => 'http://install.loncapa.org/fedora/linux/loncapa/'. |
value => 'http://install.loncapa.org/fedora/linux/loncapa/'. |
'$releasever/i386', |
'$releasever/i386', |
|
}, {section => 'loncapa-updates-i386', |
|
key => 'gpgcheck=', |
|
value => '0', |
}, {section => 'loncapa-updates-noarch', |
}, {section => 'loncapa-updates-noarch', |
key => 'name=', |
key => 'name=', |
value => 'Fedora Core $releasever LON-CAPA noarch Updates', |
value => 'Fedora Core $releasever LON-CAPA noarch Updates', |
Line 65 use File::Copy;
|
Line 72 use File::Copy;
|
key => 'baseurl=', |
key => 'baseurl=', |
value => 'http://install.loncapa.org/fedora/linux/loncapa/'. |
value => 'http://install.loncapa.org/fedora/linux/loncapa/'. |
'$releasever/noarch', |
'$releasever/noarch', |
|
}, {section => 'loncapa-updates-noarch', |
|
key => 'gpgcheck=', |
|
value => '0', |
}]); |
}]); |
|
|
&update_file('/etc/my.cnf', |
my $mysql_global_status = |
|
&update_file('/etc/my.cnf', |
[{section =>'mysqld', |
[{section =>'mysqld', |
key =>'set-variable=wait_timeout=', |
key =>'set-variable=wait_timeout=', |
value =>'31536000', }]); |
value =>'31536000', }]); |
|
|
exit; |
my $local_my_cnf = '/home/www/.my.cnf'; |
|
if (! -e $local_my_cnf) { |
|
# Create a file so we can do something with it... |
|
system("touch $local_my_cnf"); |
|
} |
|
my $mysql_www_status = |
|
&update_file($local_my_cnf, |
|
[{section =>'client', |
|
key =>'user=', |
|
value =>'www',}, |
|
{section =>'client', |
|
key =>'password=', |
|
value =>$loncapa_config->{'lonSqlAccess'}},]); |
|
|
|
my $exitvalue = 0; |
|
|
|
if ($mysql_global_status) { $exitvalue = 1; } |
|
|
|
exit $exitvalue; |
|
|
|
|
|
|
Line 92 sub update_file {
|
Line 121 sub update_file {
|
return 1 if (! -e $file); |
return 1 if (! -e $file); |
my $backup = $file.'.backup'; |
my $backup = $file.'.backup'; |
if (! copy($file,$backup)) { |
if (! copy($file,$backup)) { |
warn "Error: Unable to make backup of $file"; |
warn "**** Error: Unable to make backup of $file"; |
return 0; |
return 0; |
} |
} |
my ($filedata) = &parse_config_file($file); |
my ($filedata) = &parse_config_file($file); |
if (! ref($filedata)) { warn "Error: $filedata"; return 0;} |
if (! ref($filedata)) { warn "**** Error: $filedata"; return 0;} |
|
my $modified = 0; |
foreach my $data (@$newdata) { |
foreach my $data (@$newdata) { |
my $section = $data->{'section'}; |
my $section = $data->{'section'}; |
my $key = $data->{'key'}; |
my $key = $data->{'key'}; |
my $value = $data->{'value'}; |
my $value = $data->{'value'}; |
&modify_config_file($filedata,$section,$key,$value) |
my $result = &modify_config_file($filedata,$section,$key,$value); |
|
if ($result) { $modified = 1; } |
|
} |
|
if ($modified) { |
|
my $result = &write_config_file($file,$filedata); |
|
if (defined($result)) { warn 'Error:'.$result; return 0; } |
} |
} |
my $result = &write_config_file($file,$filedata); |
return $modified; |
if (defined($result)) { warn 'Error:'.$result; return 0; } |
|
return 1; |
|
} |
} |
|
|
################################################################# |
################################################################# |
Line 138 sub parse_config_file {
|
Line 171 sub parse_config_file {
|
my $section_id = $1; |
my $section_id = $1; |
push(@Structure,'__section__'.$section_id); |
push(@Structure,'__section__'.$section_id); |
while ($line = shift(@Input)) { |
while ($line = shift(@Input)) { |
|
chomp($line); |
if ($line =~ /^\[([^\]]*)\]/) { |
if ($line =~ /^\[([^\]]*)\]/) { |
unshift(@Input,$line); |
unshift(@Input,$line); |
last; |
last; |
Line 220 value prepended).
|
Line 254 value prepended).
|
$newkey: A line which matches this will be replaced with $newkey.$newvalue |
$newkey: A line which matches this will be replaced with $newkey.$newvalue |
$newvalue: The new value to be placed with the new key. |
$newvalue: The new value to be placed with the new key. |
|
|
|
Returns: 0 or 1, indicating if the file was modified(1) or not(0). |
|
|
|
|
=cut |
=cut |
|
|
################################################################# |
################################################################# |
################################################################# |
################################################################# |
sub modify_config_file { |
sub modify_config_file { |
my ($filedata,$section,$newkey,$newvalue)=@_; |
my ($filedata,$section,$newkey,$newvalue)=@_; |
|
my $modified = 0; # returned value - set to true if the file is modified |
my ($structure,$sections) = @$filedata; |
my ($structure,$sections) = @$filedata; |
if (! defined($newvalue)) { |
if (! defined($newvalue)) { |
$newvalue = ''; |
$newvalue = ''; |
Line 247 sub modify_config_file {
|
Line 285 sub modify_config_file {
|
# Put the item in or update it. |
# Put the item in or update it. |
my $key_is_new = 1; |
my $key_is_new = 1; |
for (my $i=0;$i<scalar(@$target);$i++) { |
for (my $i=0;$i<scalar(@$target);$i++) { |
|
|
if ($target->[$i] =~/^$newkey/) { |
if ($target->[$i] =~/^$newkey/) { |
$target->[$i]=$newline; |
if ($target->[$i] ne $newline) { |
|
$target->[$i]=$newline; |
|
$modified = 1; |
|
} |
$key_is_new = 0; |
$key_is_new = 0; |
last; |
last; |
} |
} |
Line 261 sub modify_config_file {
|
Line 301 sub modify_config_file {
|
# No need to put things after a blank line. |
# No need to put things after a blank line. |
if (defined($target->[-1]) && $target->[-1] =~ /^\s*$/) { |
if (defined($target->[-1]) && $target->[-1] =~ /^\s*$/) { |
$target->[-1] = $newline; |
$target->[-1] = $newline; |
|
$modified = 1; |
} else { |
} else { |
push(@$target,$newline); |
push(@$target,$newline); |
|
$modified = 1; |
} |
} |
} |
} |
} |
} |
return ($filedata); |
return $modified; |
} |
} |
|
|
|
|