version 1.9, 2009/07/14 03:05:59
|
version 1.28, 2024/07/30 18:26:49
|
Line 36 B<modify_config_files.pl>
|
Line 36 B<modify_config_files.pl>
|
|
|
=head1 SYNOPSIS |
=head1 SYNOPSIS |
|
|
This script modifies /etc/my.cnf and one of: /etc/yum.conf |
This script modifies local MySQL configuration file(s), which will be: |
(for Fedora/CentOS/Scientific Linux/RHEL5), /etc/apt/sources.list |
/home/www/.my.cnf and, depending on distro/version also one of: |
(for Debian/Ubuntu) and /etc/sysconfig/rhn/sources (for RHEL4). |
/etc/my.cnf, /etc/mysql/my.cnf, /etc/mysql/mysql.conf.d/mysqld.cnf, |
|
or /etc/mysql/mariadb.conf.d/50-server.cnf, and also the file used to |
|
store information about the LON-CAPA package repositories located at |
|
install.loncapa.org. which provide rpm or deb packages created for the |
|
Linux distro/version being used. The file to modify will be one of: |
|
/etc/yum.conf (for CentOS/Scientific Linux/RHEL >=5 and <8), |
|
/etc/apt/sources.list (for Debian < 10 and Ubuntu < 22), or |
|
/etc/apt/sources.list.d/loncapa.list (for Debian >= 10 and Ubuntu > 20), |
|
/etc/sysconfig/rhn/sources (for RHEL4), or /etc/yum.repos.d/loncapa.repo |
|
(for Fedora >= 21; Oracle Linux; AlmaLinux; RockyLinux; CentOS/RHEL >= 8). |
|
|
|
The script also modifies /home/www/.inputrc on Linux distros which have |
|
readline 8.1 or newer, i.e., CentOS/Scientific Linux/RHEL >= 9, |
|
Ubuntu >= 22, Debian >= 12, and Fedora >= 34. |
|
|
=head1 DESCRIPTION |
=head1 DESCRIPTION |
|
|
This script modifies /etc/my.cnf and /etc/yum.conf or /etc/apt/sources |
This script will modify /etc/my.cnf, /etc/mysql/my.cnf, |
or /etc/sysconfig/rhn/sources to ensure certain parameters are set |
/etc/mysql/mysql.conf.d/mysqld.cnf, or |
properly. The LON-CAPA yum repositories are added to /etc/yum.conf or |
/etc/mysql/mariadb.conf.d/50-server.cnf, |
/etc/sysconfig/rhn/sources and the LON-CAPA apt repositories are added to |
and /etc/yum.conf, /etc/yum.repos.d/loncapa.repo, |
/etc/apt/sources.list. |
/etc/apt/sources.list, /etc/apt/sources.list.d/loncapa.list or |
|
/etc/sysconfig/rhn/sources and /home/www/.inputrc to ensure |
The /etc/my.cnf file is modified to set the wait_timeout to 1 year. Backup |
certain parameters are set properly. |
copies of each file are made in /etc, /etc/apt, and /etc/sysconfig/rhn, as |
|
appropriate. |
The LON-CAPA yum repositories are added to /etc/yum.conf, |
|
/etc/yum.repos.d/loncapa.repo, or /etc/sysconfig/rhn/sources |
|
and the LON-CAPA apt repositories are added to |
|
/etc/apt/sources.list or /etc/apt/sources.list.d/loncapa.list. |
|
|
|
The /etc/my.cnf, /etc/mysql/my.cnf /etc/mysql/mysql.conf.d/mysqld.cnf |
|
or /etc/mysql/mariadb.conf.d/50-server.cnf file is modified to set the |
|
wait_timeout to 1 year. Backup copies of each file are made in |
|
/etc, /etc/apt, and /etc/sysconfig/rhn, as appropriate. |
|
|
=cut |
=cut |
|
|
Line 69 my $yum_status;
|
Line 90 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', |
}, {section => 'loncapa-updates-$basearch', |
}, {section => 'loncapa-updates-basearch', |
key => 'baseurl=', |
key => 'baseurl=', |
value => $loninst.'/fedora/linux/loncapa/$releasever/$basearch', |
value => $loninst.'/fedora/linux/loncapa/$releasever/$basearch', |
}, {section => 'loncapa-updates-$basearch', |
}, {section => 'loncapa-updates-basearch', |
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 126 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|rocky|alma)(\d+)(|\-stream)$/) { |
my $type = $1; |
my $type = $1; |
my $ver = $2; |
my $ver = $2; |
|
my $stream = $3; |
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'; |
} elsif ($ver == 5) { |
} elsif ($ver == 5) { |
$longver = '5Server'; |
$longver = '5Server'; |
} |
} |
|
} elsif ($type eq 'centos') { |
|
$type .= $stream; |
} |
} |
my %info = ( |
my %info = ( |
rhes => { |
rhes => { |
Line 132 if ($dist =~ /^fedora(\d+)$/) {
|
Line 163 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, |
|
}, |
|
rocky => { |
|
title => 'Rocky Linux', |
|
path => 'rocky/loncapa', |
|
gpg => 'versions/rocky/RPM-GPG-KEY-loncapa', |
|
gpgchk => 1, |
|
}, |
|
alma => { |
|
title => 'AlmaLinux', |
|
path => 'alma/loncapa', |
|
gpg => 'versions/alma/RPM-GPG-KEY-loncapa', |
|
gpgchk => 1, |
|
}, |
|
'centos-stream' => { |
|
title => 'CentOS Stream', |
|
path => 'centos/loncapa', |
|
gpg => 'versions/centos/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') || ($type eq 'rocky') || |
|
($type eq 'alma') || ($type eq 'centos-stream')) { |
|
$file = '/etc/yum.repos.d/loncapa.repo'; |
|
$nobackup = 1; |
|
} |
|
my $release = '$releasever'; |
|
if ($type eq 'centos-stream') { |
|
$release .= '-stream'; |
|
} |
$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', |
}, {section => "loncapa-updates-basearch", |
}, {section => "loncapa-updates-basearch", |
key => 'baseurl=', |
key => 'baseurl=', |
value => "$loninst/$info{$type}{path}/".'$releasever/$basearch', |
value => "$loninst/$info{$type}{path}/$release/".'$basearch', |
}, {section => 'loncapa-updates-basearch', |
}, {section => 'loncapa-updates-basearch', |
key => 'gpgcheck=', |
key => 'gpgcheck=', |
value => $info{$type}{gpchk}, |
value => $info{$type}{gpgchk}, |
}, {section => 'loncapa-updates-$basearch', |
}, {section => 'loncapa-updates-basearch', |
key => 'gpgkey=', |
key => 'gpgkey=', |
value => "$loninst/$info{$type}{gpg}", |
value => "$loninst/$info{$type}{gpg}", |
}, {section => 'loncapa-updates-noarch', |
}, {section => 'loncapa-updates-noarch', |
Line 154 if ($dist =~ /^fedora(\d+)$/) {
|
Line 219 if ($dist =~ /^fedora(\d+)$/) {
|
value => $info{$type}{title}.' $releasever LON-CAPA noarch Updates', |
value => $info{$type}{title}.' $releasever LON-CAPA noarch Updates', |
}, {section => 'loncapa-updates-noarch', |
}, {section => 'loncapa-updates-noarch', |
key => 'baseurl=', |
key => 'baseurl=', |
value => "$loninst/$info{$type}{path}/".'$releasever/noarch', |
value => "$loninst/$info{$type}{path}/$release/noarch", |
}, {section => 'loncapa-updates-noarch', |
}, {section => 'loncapa-updates-noarch', |
key => 'gpgcheck=', |
key => 'gpgcheck=', |
value => $info{$type}{gpchk}, |
value => $info{$type}{gpgchk}, |
}, {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 176 if ($dist =~ /^fedora(\d+)$/) {
|
Line 241 if ($dist =~ /^fedora(\d+)$/) {
|
$yum_status = &update_rhn_source(\%rhn); |
$yum_status = &update_rhn_source(\%rhn); |
} |
} |
} |
} |
} elsif ($dist =~ /^(debian|ubuntu)\d+$/) { |
} elsif ($dist =~ /^(debian|ubuntu)(\d+)$/) { |
|
my ($distname,$distver) = ($1,$2); |
|
if ((($distname eq 'ubuntu') && ($distver > 20)) || |
|
(($distname eq 'debian') && ($distver >= 10))) { |
|
$loninst = 'https://install.loncapa.org'; |
|
$loninst_re = 'https://install\.loncapa\.org'; |
|
} |
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", |
}, |
}, |
|
debian6 => { |
|
regexp => '\s*deb\s+'.$loninst_re.'/debian/?\s+squeeze\s+main', |
|
text => "deb $loninst/debian squeeze main", |
|
}, |
|
debian10 => { |
|
regexp => '\s*deb\s+\[signed\-by=/etc/apt/keyrings/loncapa\.gpg\]\s+'.$loninst_re.'/debian/?\s+buster\s+main', |
|
text => "deb [signed-by=/etc/apt/keyrings/loncapa.gpg] $loninst/debian buster main", |
|
}, |
|
debian11 => { |
|
regexp => '\s*deb\s+\[signed\-by=/etc/apt/keyrings/loncapa\.gpg\]\s+'.$loninst_re.'/debian/?\s+bullseye\s+main', |
|
text => "deb [signed-by=/etc/apt/keyrings/loncapa.gpg] $loninst/debian bullseye main", |
|
}, |
|
debian12 => { |
|
regexp => '\s*deb\s+\[signed\-by=/etc/apt/keyrings/loncapa\.gpg\]\s+'.$loninst_re.'/debian/?\s+bookworm\s+main', |
|
text => "deb [signed-by=/etc/apt/keyrings/loncapa.gpg] $loninst/debian bookworm 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", |
|
}, |
|
ubuntu22 => { |
|
regexp => '\s*deb\s+\[signed\-by=/etc/apt/keyrings/loncapa\.gpg\]\s+'.$loninst_re.'/ubuntu/?\s+jammy\s+main', |
|
text => "deb [signed-by=/etc/apt/keyrings/loncapa.gpg] $loninst/ubuntu jammy main", |
|
}, |
|
ubuntu24 => { |
|
regexp => '\s*deb\s+\[signed\-by=/etc/apt/keyrings/loncapa\.gpg\]\s+'.$loninst_re.'/ubuntu/?\s+noble\s+main', |
|
text => "deb [signed-by=/etc/apt/keyrings/loncapa.gpg] $loninst/ubuntu noble main", |
|
}, |
); |
); |
my $apt_status; |
my $apt_status; |
if (defined($apt_get_source{$dist})) { |
if (defined($apt_get_source{$dist})) { |
$apt_status = &update_apt_source($apt_get_source{$dist},); |
$apt_status = &update_apt_source($distname,$distver,$apt_get_source{$dist}); |
} |
} |
} |
} |
|
|
my $mysql_global_status = |
my $mysqlfile = '/etc/my.cnf'; |
&update_file('/etc/my.cnf', |
my $mysqlconf = [{section =>'mysqld', |
[{section =>'mysqld', |
key =>'wait_timeout=', |
key =>'set-variable=wait_timeout=', |
value =>'31536000'}]; |
value =>'31536000', }]); |
my $nomysqlbackup; |
|
if ($dist =~ /^ubuntu(\d+)$/) { |
|
my $version = $1; |
|
$mysqlfile = '/etc/mysql/my.cnf'; |
|
if ($version > 14) { |
|
$nomysqlbackup = 1; |
|
$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"'}); |
|
} |
|
} |
|
} elsif ($dist =~ /^debian(\d+)$/) { |
|
my $version = $1; |
|
if ($version >= 10) { |
|
$mysqlfile = '/etc/mysql/mariadb.conf.d/50-server.cnf'; |
|
$nomysqlbackup = 1; |
|
} |
|
} |
|
|
|
my $mysql_global_status = &update_file($mysqlfile,$mysqlconf,$nomysqlbackup); |
|
|
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) { |
Line 217 my $mysql_www_status =
|
Line 364 my $mysql_www_status =
|
key =>'password=', |
key =>'password=', |
value =>$loncapa_config->{'lonSqlAccess'}},]); |
value =>$loncapa_config->{'lonSqlAccess'}},]); |
|
|
|
my $needs_inputrc_check; |
|
if ($dist =~ /^debian(\d+)$/) { |
|
if ($1 >= 12) { |
|
$needs_inputrc_check = 1; |
|
} |
|
} elsif ($dist =~ /^ubuntu(\d+)$/) { |
|
if ($1 >= 22) { |
|
$needs_inputrc_check = 1; |
|
} |
|
} elsif ($dist =~ /^(?:rhes|oracle|alma|rocky|centos-stream)(\d+)$/) { |
|
if ($1 >= 9) { |
|
$needs_inputrc_check = 1; |
|
} |
|
} elsif ($dist =~ /^fedora(\d+)$/) { |
|
if ($1 >= 34) { |
|
$needs_inputrc_check = 1; |
|
} |
|
} |
|
|
|
if ($needs_inputrc_check) { |
|
my $bash_www_cnf = '/home/www/.inputrc'; |
|
if (!-e $bash_www_cnf) { |
|
system("touch $bash_www_cnf"); |
|
if (open(my $fh,'>',$bash_www_cnf)) { |
|
print $fh <<'END'; |
|
$if R |
|
set enable-bracketed-paste off |
|
$endif |
|
|
|
$if maxima |
|
set enable-bracketed-paste off |
|
$endif |
|
END |
|
close($fh); |
|
} else { |
|
warn "**** Error: could not open $bash_www_cnf to add 'set enable-bracketed-paste to off'"; |
|
} |
|
my $wwwuid = getpwnam('www'); |
|
my $wwwgid = getgrnam('www'); |
|
if ($wwwuid!=$<) { |
|
chown($wwwuid,$wwwgid,$bash_www_cnf); |
|
} |
|
} else { |
|
my (%bracketed_paste_on,%bracketed_paste_off,@preserve,$condition); |
|
$condition = ''; |
|
if (open(my $fh,'<',$bash_www_cnf)) { |
|
while (my $line=<$fh>) { |
|
chomp($line); |
|
if ($line =~ /^\$if\s+(\w+)\s*$/) { |
|
if ($1 eq 'R') { |
|
$condition = 'r'; |
|
} elsif ($1 eq 'maxima') { |
|
$condition = 'maxima'; |
|
} else { |
|
$condition = 'other'; |
|
} |
|
} elsif ($line =~ /^\$endif\s*$/) { |
|
$condition = ''; |
|
} |
|
if ($line =~ /^\s*set\s+enable\-bracketed\-paste\s+(off|on)\s*$/) { |
|
if ($1 eq 'off') { |
|
if ($condition ne '') { |
|
$bracketed_paste_off{$condition} = 1; |
|
} else { |
|
$bracketed_paste_off{all} = 1; |
|
} |
|
push(@preserve,$line); |
|
} else { |
|
if ($condition ne '') { |
|
$bracketed_paste_on{$condition} = 1; |
|
if (($condition eq 'r') || ($condition eq 'maxima')) { |
|
push(@preserve,' set enable-bracketed-paste off'); |
|
} else { |
|
push(@preserve,$line); |
|
} |
|
} else { |
|
$bracketed_paste_on{all} = 1; |
|
push(@preserve,$line); |
|
} |
|
} |
|
} else { |
|
push(@preserve,$line); |
|
} |
|
} |
|
close($fh); |
|
} |
|
if (($bracketed_paste_on{r} || $bracketed_paste_on{maxima}) || |
|
(!exists($bracketed_paste_off{r}) && !exists($bracketed_paste_on{r}) && |
|
!exists($bracketed_paste_off{maxima}) && !exists($bracketed_paste_on{maxima}))) { |
|
if (open(my $fh,'>',$bash_www_cnf)) { |
|
if (@preserve) { |
|
foreach my $entry (@preserve) { |
|
print $fh "$entry\n"; |
|
} |
|
if (!exists($bracketed_paste_off{r}) && !exists($bracketed_paste_on{r})) { |
|
print $fh <<'END'; |
|
$if R |
|
set enable-bracketed-paste off |
|
$endif |
|
END |
|
} |
|
if (!exists($bracketed_paste_off{r}) && !exists($bracketed_paste_on{r})) { |
|
print $fh <<'END'; |
|
$if maxima |
|
set enable-bracketed-paste off |
|
$endif |
|
END |
|
} |
|
} else { |
|
print $fh <<'END'; |
|
$if R |
|
set enable-bracketed-paste off |
|
$endif |
|
|
|
$if maxima |
|
set enable-bracketed-paste off |
|
$endif |
|
END |
|
} |
|
close($fh); |
|
} else { |
|
warn "**** Error: could not open $bash_www_cnf to add 'set enable-bracketed-paste to off'"; |
|
} |
|
} |
|
} |
|
} |
|
|
my $exitvalue = 0; |
my $exitvalue = 0; |
|
|
if ($mysql_global_status) { $exitvalue = 1; } |
if ($mysql_global_status) { $exitvalue = 1; } |
|
|
exit $exitvalue; |
exit $exitvalue; |
|
|
|
################################################################# |
|
################################################################# |
|
|
|
=pod |
|
|
|
=over 4 |
|
|
|
=item &update_file() |
|
|
|
Calls &parse_config_file for a file and then sends the |
|
retrieved data to &modify_config_file, and checks if |
|
modificatione were made. |
|
|
|
Inputs: filename, newdata (reference to an array of hashed), |
|
nobackup 1, if no backup of existing file (.backup |
|
appended to filename) should be made. |
|
|
|
Output: 0 or 1; o if no modifications exist (and hence no file |
|
needed to be saved, or 1 if modifications made, and call to |
|
&write_config_file to save file, or if filename does not exist. |
|
|
|
=back |
|
|
|
=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 306 sub parse_config_file {
|
Line 610 sub parse_config_file {
|
|
|
=over 4 |
=over 4 |
|
|
=item |
=item &write_config_file() |
|
|
Write a configuration file out based on the internal data structure returned |
Write a configuration file out based on the internal data structure returned |
by &parse_config_file |
by &parse_config_file |
Line 327 sub write_config_file {
|
Line 631 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 774 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 796 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 519 sub update_rhn_source {
|
Line 823 sub update_rhn_source {
|
|
|
=item &update_apt_source() |
=item &update_apt_source() |
|
|
Modifies the source.list file which includes repositories used by apt-get |
Modifies either the sources.list or sources.list.d/loncapa.list |
|
file which include repositories used by apt-get. |
|
|
Inputs: |
Inputs: |
$deb_row - a reference to containing the regular expression |
$distname - distro (without version): debian or ubuntu |
to test for, and the text string to append to the file, if an entry for the |
$distver - distro version, e.g., 12 or 24 |
LON-CAPA Debian/ or Ubuntu repository is missing. |
$deb_row - a reference to 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 Debian/ or Ubuntu repository is missing. |
|
|
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). |
|
|
Line 535 Returns: 0 or 1, indicating if the file
|
Line 842 Returns: 0 or 1, indicating if the file
|
################################################################# |
################################################################# |
################################################################# |
################################################################# |
sub update_apt_source { |
sub update_apt_source { |
my ($deb_row) = @_; |
my ($distname,$distver,$deb_row) = @_; |
return 0 if (ref($deb_row) ne 'HASH'); |
return 0 if (ref($deb_row) ne 'HASH'); |
return 0 if (($deb_row->{regexp} eq '') || ($deb_row->{text} eq '')); |
return 0 if (($deb_row->{regexp} eq '') || ($deb_row->{text} eq '')); |
my $file = '/etc/apt/sources.list'; |
my $file = '/etc/apt/sources.list'; |
|
my $nobackup; |
|
if ((($distname eq 'ubuntu') && ($distver > 20)) || |
|
(($distname eq 'debian') && ($distver >= 10))) { |
|
$file = '/etc/apt/sources.list.d/loncapa.list'; |
|
$nobackup = 1; |
|
} |
return 0 if (! -e $file); |
return 0 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 $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 873 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; |