Annotation of loncom/build/distprobe, revision 1.21

1.1       harris41    1: #!/usr/bin/perl
1.5       matthew     2: #
                      3: # The LearningOnline Network with CAPA
                      4: #
1.21    ! raeburn     5: # $Id: distprobe,v 1.20 2011/07/21 21:28:29 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.20      raeburn    57:     } elsif ($versionstring =~ /CentOS(?:| Linux) release (\d+)/) {
1.14      raeburn    58:         $dist = 'centos'.$1;
1.19      raeburn    59:     } elsif ($versionstring =~ /Scientific Linux (?:SL )?release ([\d.]+) /) {
1.17      raeburn    60:         my $ver = $1;
                     61:         $ver =~ s/\.\d+$//;
                     62:         $dist = 'scientific'.$ver;
1.5       matthew    63:     } else {
                     64:         warn('Unable to interpret /etc/redhat-release '.
                     65:              'to determine system type');
1.21    ! raeburn    66:         $unknown = 1;
1.1       harris41   67:     }
1.16      raeburn    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');
1.21    ! raeburn    82:         $unknown = 1;
1.16      raeburn    83:     }
1.15      raeburn    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');
1.21    ! raeburn   103:             $unknown = 1;
1.15      raeburn   104:         }
                    105:     }
1.5       matthew   106: } elsif (-e '/etc/debian_version') {
1.1       harris41  107:     open(IN,'</etc/debian_version');
                    108:     my $version=<IN>;
                    109:     chomp($version);
                    110:     close(IN);
1.15      raeburn   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');
1.21    ! raeburn   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";
1.1       harris41  146:     }
                    147: }
                    148: print $dist;

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