Annotation of loncom/build/distprobe, revision 1.23

1.1       harris41    1: #!/usr/bin/perl
1.5       matthew     2: #
                      3: # The LearningOnline Network with CAPA
                      4: #
1.23    ! raeburn     5: # $Id: distprobe,v 1.22 2019/05/27 01:26:31 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.20      raeburn    67:     } elsif ($versionstring =~ /CentOS(?:| Linux) 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.5       matthew    73:     } else {
                     74:         warn('Unable to interpret /etc/redhat-release '.
                     75:              'to determine system type');
1.21      raeburn    76:         $unknown = 1;
1.1       harris41   77:     }
1.16      raeburn    78: } elsif (-e '/etc/SuSE-release') {
                     79:     open(IN,'</etc/SuSE-release');
                     80:     my $versionstring=<IN>;
                     81:     chomp($versionstring);
                     82:     close(IN);
                     83:     if ($versionstring =~ /^SUSE LINUX Enterprise Server ([\d\.]+) /i) {
                     84:         $dist='sles'.$1;
                     85:     } elsif ($versionstring =~ /^SuSE Linux ([\d\.]+) /i) {
                     86:         $dist = 'suse'.$1;
                     87:     } elsif ($versionstring =~ /^openSUSE ([\d\.]+) /i) {
                     88:         $dist = 'suse'.$1;
                     89:     } else {
                     90:         warn('Unable to interpret /etc/SuSE-release '.
                     91:              'to determine system type');
1.21      raeburn    92:         $unknown = 1;
1.16      raeburn    93:     }
1.15      raeburn    94: } elsif (-e '/etc/issue') {
                     95:     open(IN,'</etc/issue');
                     96:     my $versionstring=<IN>;
                     97:     chomp($versionstring);
                     98:     close(IN);
                     99:     if ($versionstring =~ /^Ubuntu (\d+)\.\d+/i) {
                    100:         $dist = 'ubuntu'.$1;
                    101:     } elsif ($versionstring =~ /^Debian\s+GNU\/Linux\s+(\d+)\.\d+/i) {
                    102:         $dist = 'debian'.$1;
                    103:     } elsif (-e '/etc/debian_version') {
                    104:         open(IN,'</etc/debian_version');
                    105:         my $version=<IN>;
                    106:         chomp($version);
                    107:         close(IN);
                    108:         if ($version =~  /^(\d+)\.\d+\.?\d*/) {
                    109:             $dist='debian'.$1;
                    110:         } else {
                    111:             warn('Unable to interpret /etc/debian_version '.
                    112:                  'to determine system type');
1.21      raeburn   113:             $unknown = 1;
1.15      raeburn   114:         }
                    115:     }
1.5       matthew   116: } elsif (-e '/etc/debian_version') {
1.1       harris41  117:     open(IN,'</etc/debian_version');
                    118:     my $version=<IN>;
                    119:     chomp($version);
                    120:     close(IN);
1.15      raeburn   121:     if ($version =~  /^(\d+)\.\d+\.?\d*/) {
                    122:         $dist='debian'.$1;
                    123:     } else {
                    124:         warn('Unable to interpret /etc/debian_version '.
                    125:              'to determine system type');
1.21      raeburn   126:         $unknown = 1;
                    127:     }
                    128: }
                    129: if (($dist eq 'default') && (!$unknown)) {
                    130:     if (-e '/etc/os-release') {
                    131:         if (open(IN,'<','/etc/os-release')) {
                    132:             my ($id,$version);
                    133:             while(<IN>) {
                    134:                 chomp();
                    135:                 if (/^ID="(\w+)"/) {
                    136:                     $id=$1;
                    137:                 } elsif (/^VERSION_ID="([\d\.]+)"/) {
                    138:                     $version=$1;
                    139:                 }
                    140:             }
                    141:             close(IN);
                    142:             if ($id eq 'sles') {
                    143:                 my ($major,$minor) = split(/\./,$version);
                    144:                 if ($major =~ /^\d+$/) {
                    145:                     $dist = $id.$major;
                    146:                 }
                    147:             }
                    148:         }
                    149:         if ($dist eq 'default') {
                    150:             warn('Unable to interpret /etc/os-release '.
                    151:                  'to determine system type.');
                    152:             $unknown = 1;
                    153:         }
                    154:     } else {
                    155:         warn('Unknown installation: expecting a debian, ubuntu, suse, sles, redhat, fedora or scientific linux system.')."\n";
1.1       harris41  156:     }
                    157: }
                    158: print $dist;

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