Annotation of loncom/build/distprobe, revision 1.25

1.1       harris41    1: #!/usr/bin/perl
1.5       matthew     2: #
                      3: # The LearningOnline Network with CAPA
                      4: #
1.25    ! raeburn     5: # $Id: distprobe,v 1.24 2021/03/18 21:40:03 raeburn Exp $
1.5       matthew     6: #
                      7: # Copyright Michigan State University Board of Trustees
                      8: #
                      9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                     10: #
                     11: # LON-CAPA is free software; you can redistribute it and/or modify
                     12: # it under the terms of the GNU General Public License as published by
                     13: # the Free Software Foundation; either version 2 of the License, or
                     14: # (at your option) any later version.
                     15: #
                     16: # LON-CAPA is distributed in the hope that it will be useful,
                     17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     19: # GNU General Public License for more details.
                     20: #
                     21: # You should have received a copy of the GNU General Public License
                     22: # along with LON-CAPA; if not, write to the Free Software
                     23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     24: #
                     25: # /home/httpd/html/adm/gpl.txt
                     26: #
                     27: # http://www.lon-capa.org/
                     28: #
1.1       harris41   29: 
                     30: my $dist='default';
1.21      raeburn    31: my $unknown;
1.23      raeburn    32: if (-e '/etc/oracle-release') {
                     33:     open(IN,'</etc/oracle-release');
                     34:     my $versionstring=<IN>;
                     35:     chomp($versionstring);
                     36:     close(IN);
                     37:     if ($versionstring =~ /^Oracle Linux Server release (\d+)/) {
                     38:         $dist = 'oracle'.$1;
                     39:     }
                     40: } elsif (-e '/etc/redhat-release') {
1.1       harris41   41:     open(IN,'</etc/redhat-release');
                     42:     my $versionstring=<IN>;
                     43:     chomp($versionstring);
                     44:     close(IN);
1.5       matthew    45:     if ($versionstring =~ /^Red Hat Linux release ([\d\.]+) /) {
                     46:         $version = $1;
                     47:         if ($version=~/^7\./) {
                     48:             $dist='redhat7';
                     49:         } elsif ($version=~/^8\./) {
                     50:             $dist='redhat8';
                     51:         } elsif ($version=~/^9/) {
                     52:             $dist='redhat9';
                     53:         }
1.13      raeburn    54:     } elsif ($versionstring =~ /Fedora( Core)? release ([\d\.]+) /) {
                     55: 	my $version=$2;
1.7       albertel   56: 	if ($version - int($version) > .9) {
                     57: 	    $dist = 'fedora'.(int($version)+1);
                     58: 	} else {
                     59: 	    $dist = 'fedora'.int($version);
                     60: 	}
1.9       albertel   61:     } elsif ($versionstring =~ /Red Hat Enterprise Linux [AE]S release ([\d\.]+) /) {
1.8       raeburn    62:         $dist = 'rhes'.$1;
1.12      raeburn    63:     } elsif ($versionstring =~ /Red Hat Enterprise Linux Server release (\d+)/) {
                     64:         $dist = 'rhes'.$1;
1.22      raeburn    65:     } elsif ($versionstring =~ /Red Hat Enterprise Linux release (\d+)/) {
                     66:         $dist = 'rhes'.$1;
1.24      raeburn    67:     } elsif ($versionstring =~ /CentOS(?:| Linux| Stream) release (\d+)/) {
1.14      raeburn    68:         $dist = 'centos'.$1;
1.19      raeburn    69:     } elsif ($versionstring =~ /Scientific Linux (?:SL )?release ([\d.]+) /) {
1.17      raeburn    70:         my $ver = $1;
                     71:         $ver =~ s/\.\d+$//;
                     72:         $dist = 'scientific'.$ver;
1.25    ! raeburn    73:     } elsif ($versionstring =~ /Rocky Linux release ([\d.]+)/) {
        !            74:         my $ver = $1;
        !            75:         $ver =~ s/\.\d+$//;
        !            76:         $dist = 'rocky'.$ver;
        !            77:     } elsif ($versionstring =~ /AlmaLinux release ([\d.]+)/) {
        !            78:         my $ver = $1;
        !            79:         $ver =~ s/\.\d+$//;
        !            80:         $dist = 'alma'.$ver;
1.5       matthew    81:     } else {
                     82:         warn('Unable to interpret /etc/redhat-release '.
                     83:              'to determine system type');
1.21      raeburn    84:         $unknown = 1;
1.1       harris41   85:     }
1.16      raeburn    86: } elsif (-e '/etc/SuSE-release') {
                     87:     open(IN,'</etc/SuSE-release');
                     88:     my $versionstring=<IN>;
                     89:     chomp($versionstring);
                     90:     close(IN);
                     91:     if ($versionstring =~ /^SUSE LINUX Enterprise Server ([\d\.]+) /i) {
                     92:         $dist='sles'.$1;
                     93:     } elsif ($versionstring =~ /^SuSE Linux ([\d\.]+) /i) {
                     94:         $dist = 'suse'.$1;
                     95:     } elsif ($versionstring =~ /^openSUSE ([\d\.]+) /i) {
                     96:         $dist = 'suse'.$1;
                     97:     } else {
                     98:         warn('Unable to interpret /etc/SuSE-release '.
                     99:              'to determine system type');
1.21      raeburn   100:         $unknown = 1;
1.16      raeburn   101:     }
1.15      raeburn   102: } elsif (-e '/etc/issue') {
                    103:     open(IN,'</etc/issue');
                    104:     my $versionstring=<IN>;
                    105:     chomp($versionstring);
                    106:     close(IN);
                    107:     if ($versionstring =~ /^Ubuntu (\d+)\.\d+/i) {
                    108:         $dist = 'ubuntu'.$1;
                    109:     } elsif ($versionstring =~ /^Debian\s+GNU\/Linux\s+(\d+)\.\d+/i) {
                    110:         $dist = 'debian'.$1;
                    111:     } elsif (-e '/etc/debian_version') {
                    112:         open(IN,'</etc/debian_version');
                    113:         my $version=<IN>;
                    114:         chomp($version);
                    115:         close(IN);
                    116:         if ($version =~  /^(\d+)\.\d+\.?\d*/) {
                    117:             $dist='debian'.$1;
                    118:         } else {
                    119:             warn('Unable to interpret /etc/debian_version '.
                    120:                  'to determine system type');
1.21      raeburn   121:             $unknown = 1;
1.15      raeburn   122:         }
                    123:     }
1.5       matthew   124: } elsif (-e '/etc/debian_version') {
1.1       harris41  125:     open(IN,'</etc/debian_version');
                    126:     my $version=<IN>;
                    127:     chomp($version);
                    128:     close(IN);
1.15      raeburn   129:     if ($version =~  /^(\d+)\.\d+\.?\d*/) {
                    130:         $dist='debian'.$1;
                    131:     } else {
                    132:         warn('Unable to interpret /etc/debian_version '.
                    133:              'to determine system type');
1.21      raeburn   134:         $unknown = 1;
                    135:     }
                    136: }
                    137: if (($dist eq 'default') && (!$unknown)) {
                    138:     if (-e '/etc/os-release') {
                    139:         if (open(IN,'<','/etc/os-release')) {
                    140:             my ($id,$version);
                    141:             while(<IN>) {
                    142:                 chomp();
                    143:                 if (/^ID="(\w+)"/) {
                    144:                     $id=$1;
                    145:                 } elsif (/^VERSION_ID="([\d\.]+)"/) {
                    146:                     $version=$1;
                    147:                 }
                    148:             }
                    149:             close(IN);
                    150:             if ($id eq 'sles') {
                    151:                 my ($major,$minor) = split(/\./,$version);
                    152:                 if ($major =~ /^\d+$/) {
                    153:                     $dist = $id.$major;
                    154:                 }
                    155:             }
                    156:         }
                    157:         if ($dist eq 'default') {
                    158:             warn('Unable to interpret /etc/os-release '.
                    159:                  'to determine system type.');
                    160:             $unknown = 1;
                    161:         }
                    162:     } else {
                    163:         warn('Unknown installation: expecting a debian, ubuntu, suse, sles, redhat, fedora or scientific linux system.')."\n";
1.1       harris41  164:     }
                    165: }
                    166: print $dist;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>