Annotation of loncom/build/distprobe, revision 1.22

1.1       harris41    1: #!/usr/bin/perl
1.5       matthew     2: #
                      3: # The LearningOnline Network with CAPA
                      4: #
1.22    ! raeburn     5: # $Id: distprobe,v 1.21 2018/10/17 14:33:49 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.1       harris41   32: if (-e '/etc/redhat-release') {
                     33:     open(IN,'</etc/redhat-release');
                     34:     my $versionstring=<IN>;
                     35:     chomp($versionstring);
                     36:     close(IN);
1.5       matthew    37:     if ($versionstring =~ /^Red Hat Linux release ([\d\.]+) /) {
                     38:         $version = $1;
                     39:         if ($version=~/^7\./) {
                     40:             $dist='redhat7';
                     41:         } elsif ($version=~/^8\./) {
                     42:             $dist='redhat8';
                     43:         } elsif ($version=~/^9/) {
                     44:             $dist='redhat9';
                     45:         }
1.13      raeburn    46:     } elsif ($versionstring =~ /Fedora( Core)? release ([\d\.]+) /) {
                     47: 	my $version=$2;
1.7       albertel   48: 	if ($version - int($version) > .9) {
                     49: 	    $dist = 'fedora'.(int($version)+1);
                     50: 	} else {
                     51: 	    $dist = 'fedora'.int($version);
                     52: 	}
1.9       albertel   53:     } elsif ($versionstring =~ /Red Hat Enterprise Linux [AE]S release ([\d\.]+) /) {
1.8       raeburn    54:         $dist = 'rhes'.$1;
1.12      raeburn    55:     } elsif ($versionstring =~ /Red Hat Enterprise Linux Server release (\d+)/) {
                     56:         $dist = 'rhes'.$1;
1.22    ! raeburn    57:     } elsif ($versionstring =~ /Red Hat Enterprise Linux release (\d+)/) {
        !            58:         $dist = 'rhes'.$1;
1.20      raeburn    59:     } elsif ($versionstring =~ /CentOS(?:| Linux) release (\d+)/) {
1.14      raeburn    60:         $dist = 'centos'.$1;
1.19      raeburn    61:     } elsif ($versionstring =~ /Scientific Linux (?:SL )?release ([\d.]+) /) {
1.17      raeburn    62:         my $ver = $1;
                     63:         $ver =~ s/\.\d+$//;
                     64:         $dist = 'scientific'.$ver;
1.5       matthew    65:     } else {
                     66:         warn('Unable to interpret /etc/redhat-release '.
                     67:              'to determine system type');
1.21      raeburn    68:         $unknown = 1;
1.1       harris41   69:     }
1.16      raeburn    70: } elsif (-e '/etc/SuSE-release') {
                     71:     open(IN,'</etc/SuSE-release');
                     72:     my $versionstring=<IN>;
                     73:     chomp($versionstring);
                     74:     close(IN);
                     75:     if ($versionstring =~ /^SUSE LINUX Enterprise Server ([\d\.]+) /i) {
                     76:         $dist='sles'.$1;
                     77:     } elsif ($versionstring =~ /^SuSE Linux ([\d\.]+) /i) {
                     78:         $dist = 'suse'.$1;
                     79:     } elsif ($versionstring =~ /^openSUSE ([\d\.]+) /i) {
                     80:         $dist = 'suse'.$1;
                     81:     } else {
                     82:         warn('Unable to interpret /etc/SuSE-release '.
                     83:              'to determine system type');
1.21      raeburn    84:         $unknown = 1;
1.16      raeburn    85:     }
1.15      raeburn    86: } elsif (-e '/etc/issue') {
                     87:     open(IN,'</etc/issue');
                     88:     my $versionstring=<IN>;
                     89:     chomp($versionstring);
                     90:     close(IN);
                     91:     if ($versionstring =~ /^Ubuntu (\d+)\.\d+/i) {
                     92:         $dist = 'ubuntu'.$1;
                     93:     } elsif ($versionstring =~ /^Debian\s+GNU\/Linux\s+(\d+)\.\d+/i) {
                     94:         $dist = 'debian'.$1;
                     95:     } elsif (-e '/etc/debian_version') {
                     96:         open(IN,'</etc/debian_version');
                     97:         my $version=<IN>;
                     98:         chomp($version);
                     99:         close(IN);
                    100:         if ($version =~  /^(\d+)\.\d+\.?\d*/) {
                    101:             $dist='debian'.$1;
                    102:         } else {
                    103:             warn('Unable to interpret /etc/debian_version '.
                    104:                  'to determine system type');
1.21      raeburn   105:             $unknown = 1;
1.15      raeburn   106:         }
                    107:     }
1.5       matthew   108: } elsif (-e '/etc/debian_version') {
1.1       harris41  109:     open(IN,'</etc/debian_version');
                    110:     my $version=<IN>;
                    111:     chomp($version);
                    112:     close(IN);
1.15      raeburn   113:     if ($version =~  /^(\d+)\.\d+\.?\d*/) {
                    114:         $dist='debian'.$1;
                    115:     } else {
                    116:         warn('Unable to interpret /etc/debian_version '.
                    117:              'to determine system type');
1.21      raeburn   118:         $unknown = 1;
                    119:     }
                    120: }
                    121: if (($dist eq 'default') && (!$unknown)) {
                    122:     if (-e '/etc/os-release') {
                    123:         if (open(IN,'<','/etc/os-release')) {
                    124:             my ($id,$version);
                    125:             while(<IN>) {
                    126:                 chomp();
                    127:                 if (/^ID="(\w+)"/) {
                    128:                     $id=$1;
                    129:                 } elsif (/^VERSION_ID="([\d\.]+)"/) {
                    130:                     $version=$1;
                    131:                 }
                    132:             }
                    133:             close(IN);
                    134:             if ($id eq 'sles') {
                    135:                 my ($major,$minor) = split(/\./,$version);
                    136:                 if ($major =~ /^\d+$/) {
                    137:                     $dist = $id.$major;
                    138:                 }
                    139:             }
                    140:         }
                    141:         if ($dist eq 'default') {
                    142:             warn('Unable to interpret /etc/os-release '.
                    143:                  'to determine system type.');
                    144:             $unknown = 1;
                    145:         }
                    146:     } else {
                    147:         warn('Unknown installation: expecting a debian, ubuntu, suse, sles, redhat, fedora or scientific linux system.')."\n";
1.1       harris41  148:     }
                    149: }
                    150: print $dist;

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