version 1.12, 2011/05/31 02:55:15
|
version 1.18, 2021/03/13 19:38:32
|
Line 37 B<modify_config_files.pl>
|
Line 37 B<modify_config_files.pl>
|
=head1 SYNOPSIS |
=head1 SYNOPSIS |
|
|
This script modifies /etc/my.cnf and one of: /etc/yum.conf |
This script modifies /etc/my.cnf and one of: /etc/yum.conf |
(for Fedora/CentOS/Scientific Linux/RHEL5), /etc/apt/sources.list |
(for CentOS/Scientific Linux/RHEL >=5 and <8), /etc/apt/sources.list |
(for Debian/Ubuntu) and /etc/sysconfig/rhn/sources (for RHEL4). |
(for Debian/Ubuntu), /etc/sysconfig/rhn/sources (for RHEL4), |
|
and /etc/yum.repos.d/loncapa.repo (Fedora >= 21; Oracle Linux; |
|
CentOS/RHEL >= 8). |
|
|
=head1 DESCRIPTION |
=head1 DESCRIPTION |
|
|
This script modifies /etc/my.cnf and /etc/yum.conf or /etc/apt/sources |
This script modifies /etc/my.cnf, /etc/yum.conf, /etc/yum.repos.d/loncapa.repo, |
or /etc/sysconfig/rhn/sources to ensure certain parameters are set |
/etc/apt/sources, or /etc/sysconfig/rhn/sources to ensure certain |
properly. The LON-CAPA yum repositories are added to /etc/yum.conf or |
parameters are set properly. |
/etc/sysconfig/rhn/sources and the LON-CAPA apt repositories are added to |
|
|
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. |
/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 |
Line 69 my $yum_status;
|
Line 74 my $yum_status;
|
my $loninst = 'http://install.loncapa.org'; |
my $loninst = 'http://install.loncapa.org'; |
my $loninst_re = 'http://install\.loncapa\.org'; |
my $loninst_re = 'http://install\.loncapa\.org'; |
if ($dist =~ /^fedora(\d+)$/) { |
if ($dist =~ /^fedora(\d+)$/) { |
|
my $file = '/etc/yum.conf'; |
my $ver = $1; |
my $ver = $1; |
my $gpgchk = '0'; |
my $gpgchk = '0'; |
my $gpg = "$loninst/versions/fedora/RPM-GPG-KEY-loncapa"; |
my $gpg = "$loninst/versions/fedora/RPM-GPG-KEY-loncapa"; |
|
my $nobackup; |
if ($ver > 6) { |
if ($ver > 6) { |
$gpgchk = '1'; |
$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', |
Line 87 if ($dist =~ /^fedora(\d+)$/) {
|
Line 98 if ($dist =~ /^fedora(\d+)$/) {
|
key => 'gpgcheck=', |
key => 'gpgcheck=', |
value => $gpgchk, |
value => $gpgchk, |
}, {section => 'loncapa-updates-basearch', |
}, {section => 'loncapa-updates-basearch', |
key => 'gpg=', |
key => 'gpgkey=', |
value => $gpg, |
value => $gpg, |
}, {section => 'loncapa-updates-noarch', |
}, {section => 'loncapa-updates-noarch', |
key => 'name=', |
key => 'name=', |
Line 99 if ($dist =~ /^fedora(\d+)$/) {
|
Line 110 if ($dist =~ /^fedora(\d+)$/) {
|
key => 'gpgcheck=', |
key => 'gpgcheck=', |
value => $gpgchk, |
value => $gpgchk, |
}, {section => 'loncapa-updates-noarch', |
}, {section => 'loncapa-updates-noarch', |
key => 'gpg=', |
key => 'gpgkey=', |
value => $gpg, |
value => $gpg, |
}]); |
}],$nobackup); |
} elsif ($dist =~ /^(rhes|centos|scientific)(\d+)$/) { |
} elsif ($dist =~ /^(rhes|centos|scientific|oracle)(\d+)$/) { |
my $type = $1; |
my $type = $1; |
my $ver = $2; |
my $ver = $2; |
my $longver = $ver; |
my $longver = $ver; |
|
my $nobackup; |
if ($type eq 'rhes') { |
if ($type eq 'rhes') { |
if ($ver == 4) { |
if ($ver == 4) { |
$longver = '4ES'; |
$longver = '4ES'; |
Line 132 if ($dist =~ /^fedora(\d+)$/) {
|
Line 144 if ($dist =~ /^fedora(\d+)$/) {
|
gpg => 'versions/scientific/RPM-GPG-KEY-loncapa', |
gpg => 'versions/scientific/RPM-GPG-KEY-loncapa', |
gpgchk => 1, |
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 (ref($info{$type}) eq 'HASH') { |
if ($ver > 4) { |
if ($ver > 4) { |
|
my $file = '/etc/yum.conf'; |
|
if (($ver > 7) || ($type eq 'oracle')) { |
|
$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 => $info{$type}{title}.' $releasever LON-CAPA $basearch Updates', |
value => $info{$type}{title}.' $releasever LON-CAPA $basearch Updates', |
Line 161 if ($dist =~ /^fedora(\d+)$/) {
|
Line 184 if ($dist =~ /^fedora(\d+)$/) {
|
}, {section => 'loncapa-updates-noarch', |
}, {section => 'loncapa-updates-noarch', |
key => 'gpgkey=', |
key => 'gpgkey=', |
value => "$loninst/$info{$type}{gpg}", |
value => "$loninst/$info{$type}{gpg}", |
}]); |
}],$nobackup); |
} elsif (($type eq 'rhes') && ($ver == 4)) { |
} elsif (($type eq 'rhes') && ($ver == 4)) { |
my %rhn = ( |
my %rhn = ( |
basearch => { |
basearch => { |
Line 179 if ($dist =~ /^fedora(\d+)$/) {
|
Line 202 if ($dist =~ /^fedora(\d+)$/) {
|
} elsif ($dist =~ /^(debian|ubuntu)\d+$/) { |
} elsif ($dist =~ /^(debian|ubuntu)\d+$/) { |
my %apt_get_source = ( |
my %apt_get_source = ( |
debian5 => { |
debian5 => { |
regexp => '\s*deb\s+'.$loninst_re.'/debian/\s+lenny\s+main', |
regexp => '\s*deb\s+'.$loninst_re.'/debian/?\s+lenny\s+main', |
text => "deb $loninst/debian/ lenny main", |
text => "deb $loninst/debian lenny main", |
}, |
}, |
ubuntu6 => { |
ubuntu6 => { |
regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/\s+dapper\s+main', |
regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/?\s+dapper\s+main', |
text => "deb $loninst/ubuntu/ dapper main", |
text => "deb $loninst/ubuntu dapper main", |
}, |
}, |
ubuntu8 => { |
ubuntu8 => { |
regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/\s+hardy\s+main', |
regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/?\s+hardy\s+main', |
text => "deb $loninst/ubuntu/ hardy 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", |
|
}, |
|
ubuntu20 => { |
|
regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/?\s+focal\s+main', |
|
text => "deb $loninst/ubuntu focal main", |
|
}, |
); |
); |
my $apt_status; |
my $apt_status; |
if (defined($apt_get_source{$dist})) { |
if (defined($apt_get_source{$dist})) { |
Line 225 exit $exitvalue;
|
Line 272 exit $exitvalue;
|
|
|
|
|
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 327 sub write_config_file {
|
Line 376 sub write_config_file {
|
if (! defined($structure) || ! ref($structure)) { |
if (! defined($structure) || ! ref($structure)) { |
return 'Bad subroutine inputs'; |
return 'Bad subroutine inputs'; |
} |
} |
open(OUTPUT,'>'.$file) || return('Unable to open '.$file.' for writing'); |
open(OUTPUT,'>',$file) || return('Unable to open '.$file.' for writing'); |
for (my $i=0;$i<scalar(@$structure);$i++) { |
for (my $i=0;$i<scalar(@$structure);$i++) { |
my $line = $structure->[$i]; |
my $line = $structure->[$i]; |
chomp($line); |
chomp($line); |
Line 470 sub update_rhn_source {
|
Line 519 sub update_rhn_source {
|
} |
} |
my $result = 0; |
my $result = 0; |
my $fh; |
my $fh; |
if (open($fh,"<$file")) { |
if (open($fh,'<',$file)) { |
my $total = 0; |
my $total = 0; |
my %found; |
my %found; |
foreach my $item (keys(%{$rhn_items})) { |
foreach my $item (keys(%{$rhn_items})) { |
Line 492 sub update_rhn_source {
|
Line 541 sub update_rhn_source {
|
} |
} |
close($fh); |
close($fh); |
if ($total < 2) { |
if ($total < 2) { |
if (open($fh,">>$file")) { |
if (open($fh,'>>',$file)) { |
foreach my $item (keys(%{$rhn_items})) { |
foreach my $item (keys(%{$rhn_items})) { |
unless ($found{$item}) { |
unless ($found{$item}) { |
if (ref($rhn_items->{$item}) eq 'HASH') { |
if (ref($rhn_items->{$item}) eq 'HASH') { |
Line 547 sub update_apt_source {
|
Line 596 sub update_apt_source {
|
} |
} |
my $result = 0; |
my $result = 0; |
my $fh; |
my $fh; |
if (open($fh,"<$file")) { |
if (open($fh,'<',$file)) { |
my $found = 0; |
my $found = 0; |
my $pattern = $deb_row->{regexp}; |
my $pattern = $deb_row->{regexp}; |
while(<$fh>) { |
while(<$fh>) { |
Line 558 sub update_apt_source {
|
Line 607 sub update_apt_source {
|
} |
} |
close($fh); |
close($fh); |
if (!$found) { |
if (!$found) { |
if (open($fh,">>$file")) { |
if (open($fh,'>>',$file)) { |
print $fh "\n".$deb_row->{text}."\n"; |
print $fh "\n".$deb_row->{text}."\n"; |
close($fh); |
close($fh); |
$result = 1; |
$result = 1; |