--- loncom/debugging_tools/modify_config_files.pl 2017/06/05 21:06:25 1.13 +++ loncom/debugging_tools/modify_config_files.pl 2021/03/25 13:23:07 1.20 @@ -2,7 +2,7 @@ # # The LearningOnline Network # -# $Id: modify_config_files.pl,v 1.13 2017/06/05 21:06:25 raeburn Exp $ +# $Id: modify_config_files.pl,v 1.20 2021/03/25 13:23:07 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -37,9 +37,10 @@ B =head1 SYNOPSIS This script modifies /etc/my.cnf and one of: /etc/yum.conf -(for CentOS/Scientific Linux/RHEL >=5), /etc/apt/sources.list +(for CentOS/Scientific Linux/RHEL >=5 and <8), /etc/apt/sources.list (for Debian/Ubuntu), /etc/sysconfig/rhn/sources (for RHEL4), -and /etc/yum.repos.d/loncapa.repo (Fedora >= 21). +and /etc/yum.repos.d/loncapa.repo (Fedora >= 21; Oracle Linux; +CentOS/RHEL >= 8). =head1 DESCRIPTION @@ -112,10 +113,11 @@ if ($dist =~ /^fedora(\d+)$/) { key => 'gpgkey=', value => $gpg, }],$nobackup); -} elsif ($dist =~ /^(rhes|centos|scientific)(\d+)$/) { +} elsif ($dist =~ /^(rhes|centos|scientific|oracle)(\d+)$/) { my $type = $1; my $ver = $2; my $longver = $ver; + my $nobackup; if ($type eq 'rhes') { if ($ver == 4) { $longver = '4ES'; @@ -142,11 +144,22 @@ if ($dist =~ /^fedora(\d+)$/) { gpg => 'versions/scientific/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) { + my $file = '/etc/yum.conf'; + if (($ver > 7) || ($type eq 'oracle')) { + $file = '/etc/yum.repos.d/loncapa.repo'; + $nobackup = 1; + } $yum_status = - &update_file('/etc/yum.conf', + &update_file($file, [{section => 'loncapa-updates-basearch', key => 'name=', value => $info{$type}{title}.' $releasever LON-CAPA $basearch Updates', @@ -171,7 +184,7 @@ if ($dist =~ /^fedora(\d+)$/) { }, {section => 'loncapa-updates-noarch', key => 'gpgkey=', value => "$loninst/$info{$type}{gpg}", - }]); + }],$nobackup); } elsif (($type eq 'rhes') && ($ver == 4)) { my %rhn = ( basearch => { @@ -189,17 +202,41 @@ if ($dist =~ /^fedora(\d+)$/) { } 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", + 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", + 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", + 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", + }, + ubuntu20 => { + regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/?\s+focal\s+main', + text => "deb $loninst/ubuntu focal main", + }, ); my $apt_status; if (defined($apt_get_source{$dist})) { @@ -207,11 +244,30 @@ if ($dist =~ /^fedora(\d+)$/) { } } -my $mysql_global_status = - &update_file('/etc/my.cnf', - [{section =>'mysqld', - key =>'wait_timeout=', - value =>'31536000', }]); +my $mysqlfile = '/etc/my.cnf'; +my $mysqlconf = [{section =>'mysqld', + key =>'wait_timeout=', + value =>'31536000'}]; +if ($dist =~ /^ubuntu(\d+)$/) { + my $version = $1; + $mysqlfile = '/etc/mysql/my.cnf'; + if ($version > 14) { + $mysqlfile = '/etc/mysql/mysql.conf.d/mysqld.cnf'; + if ($version < 20) { + push(@{$mysqlconf}, + {section =>'mysqld', + key =>'sql_mode=', + value =>'"STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"'}); + } else { + push(@{$mysqlconf}, + {section =>'mysqld', + key =>'sql_mode=', + value =>'"STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"'}); + } + } +} + +my $mysql_global_status = &update_file($mysqlfile,$mysqlconf); my $local_my_cnf = '/home/www/.my.cnf'; if (! -e $local_my_cnf) { @@ -339,7 +395,7 @@ sub write_config_file { if (! defined($structure) || ! ref($structure)) { 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[$i]; chomp($line); @@ -482,7 +538,7 @@ sub update_rhn_source { } my $result = 0; my $fh; - if (open($fh,"<$file")) { + if (open($fh,'<',$file)) { my $total = 0; my %found; foreach my $item (keys(%{$rhn_items})) { @@ -504,7 +560,7 @@ sub update_rhn_source { } close($fh); if ($total < 2) { - if (open($fh,">>$file")) { + if (open($fh,'>>',$file)) { foreach my $item (keys(%{$rhn_items})) { unless ($found{$item}) { if (ref($rhn_items->{$item}) eq 'HASH') { @@ -559,7 +615,7 @@ sub update_apt_source { } my $result = 0; my $fh; - if (open($fh,"<$file")) { + if (open($fh,'<',$file)) { my $found = 0; my $pattern = $deb_row->{regexp}; while(<$fh>) { @@ -570,7 +626,7 @@ sub update_apt_source { } close($fh); if (!$found) { - if (open($fh,">>$file")) { + if (open($fh,'>>',$file)) { print $fh "\n".$deb_row->{text}."\n"; close($fh); $result = 1;