version 1.3, 2004/08/11 17:32:53
|
version 1.4, 2004/08/23 19:47:39
|
Line 53 use lib '/home/httpd/lib/perl/';
|
Line 53 use lib '/home/httpd/lib/perl/';
|
use LONCAPA::Configuration; |
use LONCAPA::Configuration; |
my $loncapa_config=LONCAPA::Configuration::read_conf('loncapa.conf'); |
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 70 my $loncapa_config=LONCAPA::Configuratio
|
Line 71 my $loncapa_config=LONCAPA::Configuratio
|
'$releasever/noarch', |
'$releasever/noarch', |
}]); |
}]); |
|
|
&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', }]); |
|
|
|
|
my $local_my_cnf = '/home/www/.my.cnf'; |
my $local_my_cnf = '/home/www/.my.cnf'; |
if (! -e $local_my_cnf) { |
if (! -e $local_my_cnf) { |
# # Create a file so we can do something with it... |
# Create a file so we can do something with it... |
system("touch $local_my_cnf"); |
system("touch $local_my_cnf"); |
} |
} |
&update_file($local_my_cnf, |
my $mysql_www_status = |
|
&update_file($local_my_cnf, |
[{section =>'client', |
[{section =>'client', |
key =>'user=', |
key =>'user=', |
value =>'www',}, |
value =>'www',}, |
Line 89 if (! -e $local_my_cnf) {
|
Line 91 if (! -e $local_my_cnf) {
|
key =>'password=', |
key =>'password=', |
value =>$loncapa_config->{'lonSqlAccess'}},]); |
value =>$loncapa_config->{'lonSqlAccess'}},]); |
|
|
exit; |
my $exitvalue = 0; |
|
|
|
if ($mysql_global_status) { $exitvalue = 1; } |
|
|
|
exit $exitvalue; |
|
|
|
|
|
|
Line 109 sub update_file {
|
Line 115 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 155 sub parse_config_file {
|
Line 165 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 237 value prepended).
|
Line 248 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 264 sub modify_config_file {
|
Line 279 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 278 sub modify_config_file {
|
Line 295 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; |
} |
} |
|
|
|
|