File:  [LON-CAPA] / loncom / build / distprobe
Revision 1.21: download - view: text, annotated - select for diffs
Wed Oct 17 14:33:49 2018 UTC (5 years, 7 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Support SLES 15.

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

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