[LON-CAPA-cvs] cvs: loncom /debugging_tools modify_config_files.pl

raeburn raeburn at source.lon-capa.org
Fri Jun 28 08:46:47 EDT 2024


raeburn		Fri Jun 28 12:46:47 2024 EDT

  Modified files:              
    /loncom/debugging_tools	modify_config_files.pl 
  Log:
  - Support Ubuntu 22 and 24, Debian 10, 11 and 12, and update POD
  - Don't create a backup MySQL file when modified MySQL config file is in
    either a mysql.conf.d or mariadb.conf.d directory in /etc/mysql/.
  
  
-------------- next part --------------
Index: loncom/debugging_tools/modify_config_files.pl
diff -u loncom/debugging_tools/modify_config_files.pl:1.23 loncom/debugging_tools/modify_config_files.pl:1.24
--- loncom/debugging_tools/modify_config_files.pl:1.23	Tue Dec 21 15:43:57 2021
+++ loncom/debugging_tools/modify_config_files.pl	Fri Jun 28 12:46:47 2024
@@ -2,7 +2,7 @@
 #
 # The LearningOnline Network
 #
-# $Id: modify_config_files.pl,v 1.23 2021/12/21 15:43:57 raeburn Exp $
+# $Id: modify_config_files.pl,v 1.24 2024/06/28 12:46:47 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -36,26 +36,37 @@
 
 =head1 SYNOPSIS
 
-This script modifies /etc/my.cnf and one of: /etc/yum.conf 
-(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; Oracle Linux; 
-CentOS/RHEL >= 8).
+This script modifies local MySQL configuration file(s), which will be:
+/home/www/.my.cnf and, depending on distro/version also one of:
+/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).
 
 =head1 DESCRIPTION
 
-This script modifies /etc/my.cnf, /etc/yum.conf, /etc/yum.repos.d/loncapa.repo,
-/etc/apt/sources, or /etc/sysconfig/rhn/sources to ensure certain
-parameters are set properly.
+This script will modify /etc/my.cnf, /etc/mysql/my.cnf, 
+/etc/mysql/mysql.conf.d/mysqld.cnf, or
+/etc/mysql/mariadb.conf.d/50-server.cnf,
+and /etc/yum.conf, /etc/yum.repos.d/loncapa.repo,
+/etc/apt/sources.list, /etc/apt/sources.list.d/loncapa.list 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
+/etc/yum.repos.d/loncapa.repo, or /etc/sysconfig/rhn/sources
 and the LON-CAPA apt repositories are added to 
-/etc/apt/sources.list.
+/etc/apt/sources.list or /etc/apt/sources.list.d/loncapa.list.
 
-The /etc/my.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.
+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
 
@@ -225,12 +236,35 @@
             $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 = (
                            debian5 => {
                                         regexp => '\s*deb\s+'.$loninst_re.'/debian/?\s+lenny\s+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 => {
                                         regexp => '\s*deb\s+'.$loninst_re.'/ubuntu/?\s+dapper\s+main',
                                         text   => "deb $loninst/ubuntu dapper main",
@@ -263,10 +297,18 @@
                                         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;
     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});
     }
 }
 
@@ -274,10 +316,12 @@
 my $mysqlconf = [{section =>'mysqld',
                   key     =>'wait_timeout=',
                   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},
@@ -291,9 +335,15 @@
                   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);
+my $mysql_global_status = &update_file($mysqlfile,$mysqlconf,$nomysqlbackup);
 
 my $local_my_cnf = '/home/www/.my.cnf';
 if (! -e $local_my_cnf) {
@@ -315,6 +365,34 @@
 
 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 {
     my ($file,$newdata,$nobackup) = @_;
@@ -400,7 +478,7 @@
 
 =over 4
 
-=item
+=item &write_config_file()
 
 Write a configuration file out based on the internal data structure returned
 by &parse_config_file
@@ -613,12 +691,15 @@
 
 =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:
-$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.
+$distname - distro (without version): debian or ubuntu
+$distver - distro version, e.g., 12 or 24
+$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).
 
@@ -629,15 +710,23 @@
 #################################################################
 #################################################################
 sub update_apt_source {
-    my ($deb_row) = @_;
+    my ($distname,$distver,$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';
+    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);
-    my $backup = $file.'.backup';
-    if (! copy($file,$backup)) {
-        warn "**** Error: Unable to make backup of $file";
-        return 0;
+    unless ($nobackup) {
+        my $backup = $file.'.backup';
+        if (! copy($file,$backup)) {
+            warn "**** Error: Unable to make backup of $file";
+            return 0;
+        }
     }
     my $result = 0;
     my $fh;


More information about the LON-CAPA-cvs mailing list