version 1.7, 2007/04/24 13:09:40
|
version 1.15, 2019/07/02 19:40:27
|
Line 36 B<modify_config_files.pl>
|
Line 36 B<modify_config_files.pl>
|
|
|
=head1 SYNOPSIS |
=head1 SYNOPSIS |
|
|
This script modifies /etc/yum.conf and /etc/my.cnf. |
This script modifies /etc/my.cnf and one of: /etc/yum.conf |
|
(for CentOS/Scientific Linux/RHEL >=5), /etc/apt/sources.list |
|
(for Debian/Ubuntu), /etc/sysconfig/rhn/sources (for RHEL4), |
|
and /etc/yum.repos.d/loncapa.repo (Fedora >= 21). |
|
|
=head1 DESCRIPTION |
=head1 DESCRIPTION |
|
|
This script modifies /etc/yum.conf and /etc/my.cnf to ensure certain parameters |
This script modifies /etc/my.cnf, /etc/yum.conf, /etc/yum.repos.d/loncapa.repo, |
are set properly. The LON-CAPA yum repositories are added to /etc/yum.conf. |
/etc/apt/sources, or /etc/sysconfig/rhn/sources to ensure certain |
|
parameters are set properly. |
|
|
|
The LON-CAPA yum repositories are added to /etc/yum.conf, |
|
/etc/yum.repos.d/loncapa.repo, /etc/sysconfig/rhn/sources |
|
and the LON-CAPA apt repositories are added to |
|
/etc/apt/sources.list. |
|
|
The /etc/my.cnf file is modified to set the wait_timeout to 1 year. Backup |
The /etc/my.cnf file is modified to set the wait_timeout to 1 year. Backup |
copies of each file are made in /etc. |
copies of each file are made in /etc, /etc/apt, and /etc/sysconfig/rhn, as |
|
appropriate. |
|
|
=cut |
=cut |
|
|
Line 59 chomp($dist);
|
Line 70 chomp($dist);
|
close(DSH); |
close(DSH); |
|
|
my $yum_status; |
my $yum_status; |
if ($dist =~ /^fedora\d+$/) { |
my $loninst = 'http://install.loncapa.org'; |
|
my $loninst_re = 'http://install\.loncapa\.org'; |
|
if ($dist =~ /^fedora(\d+)$/) { |
|
my $file = '/etc/yum.conf'; |
|
my $ver = $1; |
|
my $gpgchk = '0'; |
|
my $gpg = "$loninst/versions/fedora/RPM-GPG-KEY-loncapa"; |
|
my $nobackup; |
|
if ($ver > 6) { |
|
$gpgchk = '1'; |
|
} |
|
if ($ver >= 21) { |
|
$file = '/etc/yum.repos.d/loncapa.repo'; |
|
$nobackup = 1; |
|
} |
$yum_status = |
$yum_status = |
&update_file('/etc/yum.conf', |
&update_file($file, |
[{section => 'loncapa-updates-$basearch', |
[{section => 'loncapa-updates-basearch', |
key => 'name=', |
key => 'name=', |
value => 'Fedora Core $releasever LON-CAPA $basearch Updates', |
value => 'Fedora Core $releasever LON-CAPA $basearch Updates', |
}, {section => 'loncapa-updates-$basearch', |
}, {section => 'loncapa-updates-basearch', |
key => 'baseurl=', |
key => 'baseurl=', |
value => 'http://install.loncapa.org/fedora/linux/loncapa/'. |
value => $loninst.'/fedora/linux/loncapa/$releasever/$basearch', |
'$releasever/$basearch', |
}, {section => 'loncapa-updates-basearch', |
}, {section => 'loncapa-updates-$basearch', |
|
key => 'gpgcheck=', |
key => 'gpgcheck=', |
value => '0', |
value => $gpgchk, |
|
}, {section => 'loncapa-updates-basearch', |
|
key => 'gpgkey=', |
|
value => $gpg, |
}, {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', |
}, {section => 'loncapa-updates-noarch', |
}, {section => 'loncapa-updates-noarch', |
key => 'baseurl=', |
key => 'baseurl=', |
value => 'http://install.loncapa.org/fedora/linux/loncapa/'. |
value => $loninst.'/fedora/linux/loncapa/$releasever/noarch', |
'$releasever/noarch', |
|
}, {section => 'loncapa-updates-noarch', |
}, {section => 'loncapa-updates-noarch', |
key => 'gpgcheck=', |
key => 'gpgcheck=', |
value => '0', |
value => $gpgchk, |
}]); |
}, {section => 'loncapa-updates-noarch', |
} elsif ($dist =~ /^rhes(\d+)$/) { |
key => 'gpgkey=', |
if ($1 > 4) { |
value => $gpg, |
$yum_status = |
}],$nobackup); |
&update_file('/etc/yum.conf', |
} elsif ($dist =~ /^(rhes|centos|scientific|oracle)(\d+)$/) { |
[{section => 'loncapa-updates-$basearch', |
my $type = $1; |
key => 'name=', |
my $ver = $2; |
value => 'RHEL $releasever LON-CAPA $basearch Updates', |
my $longver = $ver; |
}, {section => 'loncapa-updates-$basearch', |
if ($type eq 'rhes') { |
key => 'baseurl=', |
if ($ver == 4) { |
value => 'http://install.loncapa.org/redhat/linux/loncapa/'. |
$longver = '4ES'; |
'$releasever/$basearch', |
} elsif ($ver == 5) { |
}, {section => 'loncapa-updates-$basearch', |
$longver = '5Server'; |
key => 'gpgcheck=', |
} |
value => '1', |
} |
}, {section => 'loncapa-updates-$basearch', |
my %info = ( |
key => 'gpgkey=', |
rhes => { |
value => 'http://install.loncapa.org/versions/redhat/'. |
title => 'RHEL', |
'RPM-GPG-KEY-loncapa', |
path => 'redhat/linux/enterprise/loncapa', |
}, {section => 'loncapa-updates-noarch', |
gpg => 'versions/redhat/RPM-GPG-KEY-loncapa', |
key => 'name=', |
gpgchk => 1, |
value => 'RHEL $releasever LON-CAPA noarch Updates', |
}, |
}, {section => 'loncapa-updates-noarch', |
centos => { |
key => 'baseurl=', |
title => 'CentOS', |
value => 'http://install.loncapa.org/redhat/linux/loncapa/'. |
path => 'centos/loncapa', |
'$releasever/noarch', |
gpg => 'versions/centos/RPM-GPG-KEY-loncapa', |
}, {section => 'loncapa-updates-noarch', |
gpgchk => 1, |
key => 'gpgcheck=', |
}, |
value => '1', |
scientific => { |
}, {section => 'loncapa-updates-noarch', |
title => 'Scientific Linux', |
key => 'gpgkey=', |
path => 'scientific/loncapa', |
value => 'http://install.loncapa.org/versions/redhat/'. |
gpg => 'versions/scientific/RPM-GPG-KEY-loncapa', |
'RPM-GPG-KEY-loncapa', |
gpgchk => 1, |
}]); |
}, |
|
oracle => { |
|
title => 'Oracle Linux', |
|
path => 'oracle/loncapa', |
|
gpg => 'versions/oracle/RPM-GPG-KEY-loncapa', |
|
gpgchk => 1, |
|
}, |
|
); |
|
if (ref($info{$type}) eq 'HASH') { |
|
if ($ver > 4) { |
|
$yum_status = |
|
&update_file('/etc/yum.conf', |
|
[{section => 'loncapa-updates-basearch', |
|
key => 'name=', |
|
value => $info{$type}{title}.' $releasever LON-CAPA $basearch Updates', |
|
}, {section => "loncapa-updates-basearch", |
|
key => 'baseurl=', |
|
value => "$loninst/$info{$type}{path}/".'$releasever/$basearch', |
|
}, {section => 'loncapa-updates-basearch', |
|
key => 'gpgcheck=', |
|
value => $info{$type}{gpgchk}, |
|
}, {section => 'loncapa-updates-basearch', |
|
key => 'gpgkey=', |
|
value => "$loninst/$info{$type}{gpg}", |
|
}, {section => 'loncapa-updates-noarch', |
|
key => 'name=', |
|
value => $info{$type}{title}.' $releasever LON-CAPA noarch Updates', |
|
}, {section => 'loncapa-updates-noarch', |
|
key => 'baseurl=', |
|
value => "$loninst/$info{$type}{path}/".'$releasever/noarch', |
|
}, {section => 'loncapa-updates-noarch', |
|
key => 'gpgcheck=', |
|
value => $info{$type}{gpgchk}, |
|
}, {section => 'loncapa-updates-noarch', |
|
key => 'gpgkey=', |
|
value => "$loninst/$info{$type}{gpg}", |
|
}]); |
|
} elsif (($type eq 'rhes') && ($ver == 4)) { |
|
my %rhn = ( |
|
basearch => { |
|
regexp => '\s*yum\s+loncapa\-updates\-basearch\s+'.$loninst_re.'/'.$info{$type}{path}.'/'.$longver.'/\$ARCH', |
|
text => "yum loncapa-updates-basearch $loninst/$info{$type}{path}/$longver/".'$ARCH', |
|
}, |
|
noarch => { |
|
regexp => '\s*yum\s+loncapa\-updates\-noarch\s+'.$loninst_re.'/'.$info{$type}{path}.'/'.$longver.'/noarch', |
|
text => "yum loncapa-updates-noarch $loninst/$info{$type}{path}/$longver/noarch", |
|
}, |
|
); |
|
$yum_status = &update_rhn_source(\%rhn); |
|
} |
|
} |
|
} elsif ($dist =~ /^(debian|ubuntu)\d+$/) { |
|
my %apt_get_source = ( |
|
debian5 => { |
|
regexp => '\s*deb\s+'.$loninst_re.'/debian/\s+lenny\s+main', |
|
text => "deb $loninst/debian/ lenny main", |
|
}, |
|
ubuntu6 => { |
|
regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/\s+dapper\s+main', |
|
text => "deb $loninst/ubuntu/ dapper main", |
|
}, |
|
ubuntu8 => { |
|
regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/\s+hardy\s+main', |
|
text => "deb $loninst/ubuntu/ hardy main", |
|
}, |
|
ubuntu10 => { |
|
regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/\s+lucid\s+main', |
|
text => "deb $loninst/ubuntu/ lucid main", |
|
}, |
|
ubuntu12 => { |
|
regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/\s+precise\s+main', |
|
text => "deb $loninst/ubuntu/ precise main", |
|
}, |
|
ubuntu14 => { |
|
regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/\s+trusty\s+main', |
|
text => "deb $loninst/ubuntu/ trusty main", |
|
}, |
|
ubuntu16 => { |
|
regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/\s+xenial\s+main', |
|
text => "deb $loninst/ubuntu/ xenial main", |
|
}, |
|
ubuntu18 => { |
|
regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/\s+bionic\s+main', |
|
text => "deb $loninst/ubuntu/ bionic main", |
|
}, |
|
); |
|
my $apt_status; |
|
if (defined($apt_get_source{$dist})) { |
|
$apt_status = &update_apt_source($apt_get_source{$dist},); |
} |
} |
} |
} |
|
|
my $mysql_global_status = |
my $mysql_global_status = |
&update_file('/etc/my.cnf', |
&update_file('/etc/my.cnf', |
[{section =>'mysqld', |
[{section =>'mysqld', |
key =>'set-variable=wait_timeout=', |
key =>'wait_timeout=', |
value =>'31536000', }]); |
value =>'31536000', }]); |
|
|
my $local_my_cnf = '/home/www/.my.cnf'; |
my $local_my_cnf = '/home/www/.my.cnf'; |
Line 146 if ($mysql_global_status) { $exitvalue =
|
Line 260 if ($mysql_global_status) { $exitvalue =
|
exit $exitvalue; |
exit $exitvalue; |
|
|
|
|
|
|
################################################################# |
|
################################################################# |
|
|
|
=pod |
|
|
|
=over 4 |
|
|
|
=cut |
|
|
|
################################################################# |
|
################################################################# |
|
sub update_file { |
sub update_file { |
my ($file,$newdata) = @_; |
my ($file,$newdata,$nobackup) = @_; |
return 1 if (! -e $file); |
return 1 if (! -e $file); |
my $backup = $file.'.backup'; |
unless ($nobackup) { |
if (! copy($file,$backup)) { |
my $backup = $file.'.backup'; |
warn "**** Error: Unable to make backup of $file"; |
if (! copy($file,$backup)) { |
return 0; |
warn "**** Error: Unable to make backup of $file"; |
|
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;} |
Line 188 sub update_file {
|
Line 292 sub update_file {
|
|
|
=pod |
=pod |
|
|
=item &parse_config_file |
=over 4 |
|
|
|
=item &parse_config_file() |
|
|
Read a configuration file in and parse it into an internal data structure. |
Read a configuration file in and parse it into an internal data structure. |
|
|
Line 196 Input: filename
|
Line 302 Input: filename
|
|
|
Output: array ref $filedata OR scalar error message |
Output: array ref $filedata OR scalar error message |
|
|
|
=back |
|
|
=cut |
=cut |
|
|
################################################################# |
################################################################# |
Line 234 sub parse_config_file {
|
Line 342 sub parse_config_file {
|
|
|
=pod |
=pod |
|
|
|
=over 4 |
|
|
=item |
=item |
|
|
Write a configuration file out based on the internal data structure returned |
Write a configuration file out based on the internal data structure returned |
Line 243 Inputs: filename, $filedata (the return
|
Line 353 Inputs: filename, $filedata (the return
|
|
|
Returns: undef on success, scalar error message on failure. |
Returns: undef on success, scalar error message on failure. |
|
|
|
=back |
|
|
=cut |
=cut |
|
|
################################################################# |
################################################################# |
Line 284 sub write_config_file {
|
Line 396 sub write_config_file {
|
|
|
=pod |
=pod |
|
|
=item &modify_config_file |
=over 4 |
|
|
|
=item &modify_config_file() |
|
|
Modifies the internal data structure of a configuration file to include new |
Modifies the internal data structure of a configuration file to include new |
sections and/or new configuration directives. |
sections and/or new configuration directives. |
Line 298 $newvalue: The new value to be placed wi
|
Line 412 $newvalue: The new value to be placed wi
|
|
|
Returns: 0 or 1, indicating if the file was modified(1) or not(0). |
Returns: 0 or 1, indicating if the file was modified(1) or not(0). |
|
|
|
=back |
|
|
=cut |
=cut |
|
|
Line 353 sub modify_config_file {
|
Line 468 sub modify_config_file {
|
return $modified; |
return $modified; |
} |
} |
|
|
|
################################################################# |
|
################################################################# |
|
|
|
=pod |
|
|
|
=over 4 |
|
|
|
=item &update_rhn_source() |
|
|
|
Modifies the Red Hat 4 sources file which includes repositories used by up2date |
|
|
|
Inputs: |
|
$rhn_items - a reference to hash of a hash containing the regular expression |
|
to test for, and the text string to append to the file, if an entry for the |
|
LON-CAPA RHEL repository is missing for two cases: |
|
|
|
(a) basearch |
|
(b) noarch |
|
|
|
Returns: 0 or 1, indicating if the file was modified(1) or not(0). |
|
|
|
=back |
|
|
|
=cut |
|
|
|
################################################################# |
|
################################################################# |
|
sub update_rhn_source { |
|
my ($rhn_items) = @_; |
|
return 0 if (ref($rhn_items) ne 'HASH'); |
|
return 0 if ((ref($rhn_items->{basearch}) ne 'HASH') || (ref($rhn_items->{noarch}) ne 'HASH')); |
|
my $file = '/etc/sysconfig/rhn/sources'; |
|
return 0 if (! -e $file); |
|
my $backup = $file.'.backup'; |
|
if (! copy($file,$backup)) { |
|
warn "**** Error: Unable to make backup of $file"; |
|
return 0; |
|
} |
|
my $result = 0; |
|
my $fh; |
|
if (open($fh,"<$file")) { |
|
my $total = 0; |
|
my %found; |
|
foreach my $item (keys(%{$rhn_items})) { |
|
$found{$item} = 0; |
|
} |
|
while(<$fh>) { |
|
foreach my $item (keys(%{$rhn_items})) { |
|
if (ref($rhn_items->{$item}) eq 'HASH') { |
|
my $pattern = $rhn_items->{$item}->{regexp}; |
|
if ($pattern ne '') { |
|
if (m{^$pattern}) { |
|
$found{$item} = 1; |
|
$total ++; |
|
} |
|
} |
|
} |
|
} |
|
last if $total == 2; |
|
} |
|
close($fh); |
|
if ($total < 2) { |
|
if (open($fh,">>$file")) { |
|
foreach my $item (keys(%{$rhn_items})) { |
|
unless ($found{$item}) { |
|
if (ref($rhn_items->{$item}) eq 'HASH') { |
|
if ($rhn_items->{$item}->{text} ne '') { |
|
print $fh "\n".$rhn_items->{$item}->{text}."\n"; |
|
$result = 1; |
|
} |
|
} |
|
} |
|
} |
|
close($fh); |
|
} |
|
} |
|
} |
|
return $result; |
|
} |
|
|
################################################################# |
################################################################# |
################################################################# |
################################################################# |
|
|
=pod |
=pod |
|
|
|
=over 4 |
|
|
|
=item &update_apt_source() |
|
|
|
Modifies the source.list file which includes repositories used by apt-get |
|
|
|
Inputs: |
|
$deb_row - a reference to containing the regular expression |
|
to test for, and the text string to append to the file, if an entry for the |
|
LON-CAPA Debian/ or Ubuntu repository is missing. |
|
|
|
Returns: 0 or 1, indicating if the file was modified(1) or not(0). |
|
|
=back |
=back |
|
|
=cut |
=cut |
|
|
################################################################# |
################################################################# |
################################################################# |
################################################################# |
|
sub update_apt_source { |
|
my ($deb_row) = @_; |
|
return 0 if (ref($deb_row) ne 'HASH'); |
|
return 0 if (($deb_row->{regexp} eq '') || ($deb_row->{text} eq '')); |
|
my $file = '/etc/apt/sources.list'; |
|
return 0 if (! -e $file); |
|
my $backup = $file.'.backup'; |
|
if (! copy($file,$backup)) { |
|
warn "**** Error: Unable to make backup of $file"; |
|
return 0; |
|
} |
|
my $result = 0; |
|
my $fh; |
|
if (open($fh,"<$file")) { |
|
my $found = 0; |
|
my $pattern = $deb_row->{regexp}; |
|
while(<$fh>) { |
|
if (m{^$pattern}) { |
|
$found = 1; |
|
last; |
|
} |
|
} |
|
close($fh); |
|
if (!$found) { |
|
if (open($fh,">>$file")) { |
|
print $fh "\n".$deb_row->{text}."\n"; |
|
close($fh); |
|
$result = 1; |
|
} |
|
} |
|
} |
|
return $result; |
|
} |
|
|