Linux-Distribution-0.21000755000000000000 011721510130 15526 5ustar00unknownunknown000000000000Linux-Distribution-0.21/Build.PL000444000000000000 121011721507557 17174 0ustar00unknownunknown000000000000use strict; use Module::Build; #created by eumm-migrate.pl unless (lc $^O eq "linux") { die "OS unsupported\n"; } my $build = Module::Build->new( 'auto_configure_requires' => 0, 'dist_author' => 'Alexandr Ciornii ', 'module_name' => 'Linux::Distribution', 'meta_merge' => { 'resources' => { 'repository' => 'https://github.com/chorny/Linux-Distribution' } }, 'requires' => { 'perl' => '5.006', }, 'build_requires' => { 'Test::More' => 0, }, 'license' => 'perl', 'dist_version_from' => 'lib/Linux/Distribution.pm' ); $build->create_build_script(); Linux-Distribution-0.21/Changes000444000000000000 264111721507267 17202 0ustar00unknownunknown000000000000* 2011-02-23 version 0.21 Added OS and version detection for Oracle Enterprise Linux Fixed version detection for Fedora (reported by tlhackqueATyahoo.com, RT#69671) Fixed OS and version detection for CentOS6 (RT#69847) Added version detection for Scientific Linux * 2010-12-05 version 0.20 Fixed version detection for Gentoo CentOS detection (modified patch from XSAWYERX) Start writing distribution-oriented tests Build.PL added * 2008-11-02 version 0.14_01 Remove bareword filehandles and 2-arg open Will not install if not on Linux Modernize Makefile.PL Fix for 5.10 Pardus support (by BURAK, RT#27357) Fix Fedora recognition (reported by sagarshahATsofthome.net, RT#11996) * 2005-02-16 Added support for Redflag. * 2006-01-16 Thanks to Judith Lebzelter now the module gets advantage of the LSB's /etc/lsb-release file. Added support for Ubuntu and version information retrieval for gentoo, debian, suse, fedora, redhat and slackware. * 2005-03-10 Added support for yoper, arch-linux and libranet. * 2005-03-09 Cleaned code. * 2005-03-08 Version 0.03. Added support for Adamantix and Trustix. * 2005-03-07 Reduced needed perl version to 5.6.0. Removed copyright line from pod documentation. * 2005-03-06 Version 0.02. * 2005-03-06 Added support for immunix, conectiva, tinysofa and va-linux. * 2005-03-06 Updated changelog * 2005-03-06 20:14:28 +0100 Version 0.01. Linux-Distribution-0.21/Makefile.PL000444000000000000 116011721510124 17636 0ustar00unknownunknown000000000000use 5.006000; use ExtUtils::MakeMaker; unless (lc $^O eq "linux") { die "OS unsupported\n"; } WriteMakefile( NAME => 'Linux::Distribution', VERSION_FROM => 'lib/Linux/Distribution.pm', # finds $VERSION PREREQ_PM => { 'Test::More' => 0, }, ABSTRACT_FROM => 'lib/Linux/Distribution.pm', # retrieve abstract from module AUTHOR => 'Alexandr Ciornii ', #Alberto Re ($ExtUtils::MakeMaker::VERSION ge '6.48'? ('LICENSE' => 'perl', 'MIN_PERL_VERSION' => 5.006,) : ()), PL_FILES => {}, ); Linux-Distribution-0.21/MANIFEST000444000000000000 104511721507563 17034 0ustar00unknownunknown000000000000Build.PL Changes lib/Linux/Distribution.pm Makefile.PL MANIFEST META.yml Module meta-data (added by MakeMaker) README t/centos.t t/centos/files t/centos/redhat-release t/centos6.t t/centos6/centos-release t/centos6/files t/fedora15.t t/fedora15/fedora-release t/fedora15/files t/fedora15/redhat-release t/Linux-Distribution.t t/oel6.t t/oel6/enterprise-release t/oel6/files t/oel6/redhat-release t/rhel6.t t/rhel6/files t/rhel6/redhat-release t/scientific6.t t/scientific6/files t/scientific6/redhat-release META.json Linux-Distribution-0.21/META.json000444000000000000 210611721510127 17311 0ustar00unknownunknown000000000000{ "abstract" : "Perl extension to detect on which Linux distribution we are running.", "author" : [ "Alexandr Ciornii " ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.38, CPAN::Meta::Converter version 2.112150", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Linux-Distribution", "prereqs" : { "build" : { "requires" : { "Test::More" : 0 } }, "runtime" : { "requires" : { "perl" : "5.006" } } }, "provides" : { "Linux::Distribution" : { "file" : "lib/Linux/Distribution.pm", "version" : "0.21" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "url" : "https://github.com/chorny/Linux-Distribution" } }, "version" : "0.21" } Linux-Distribution-0.21/META.yml000444000000000000 122111721510127 17136 0ustar00unknownunknown000000000000--- abstract: Perl extension to detect on which Linux distribution we are running. author: - 'Alexandr Ciornii ' build_requires: Test::More: 0 dynamic_config: 1 generated_by: 'Module::Build version 0.38, CPAN::Meta::Converter version 2.112150' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Linux-Distribution provides: Linux::Distribution: file: lib/Linux/Distribution.pm version: 0.21 requires: perl: 5.006 resources: license: http://dev.perl.org/licenses/ repository: https://github.com/chorny/Linux-Distribution version: 0.21 Linux-Distribution-0.21/README000444000000000000 254611721506553 16570 0ustar00unknownunknown000000000000Linux-Distribution version 0.21 =============================== This is a simple module that tries to detect on what linux distribution we are running by looking for release's files in /etc. It now looks for 'lsb-release' first as that should be the most cor- rect and adds ubuntu support. Secondly, it will look for the distro specific files. It currently recognizes slackware, debian, suse, fedora, redhat, turbolinux, yellowdog, knoppix, mandrake, conectiva, immunix, tinysofa, va-linux, trustix, adamantix, yoper, arch-linux, libranet, gentoo, ubuntu, scientific, oracle enterprise linux, and redflag. It has function to get the version for debian, suse, fedora, redhat, gentoo, slackware, scientific, oracle enterprise linux, redflag and ubuntu(lsb). People running unsupported distro's are greatly encouraged to submit patches :-) INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module has no dependencies. COPYRIGHT AND LICENCE Copyright (C) 2006 by Alberto Re (c) 2008-2012 Alexandr Ciornii This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available. Linux-Distribution-0.21/lib000755000000000000 011721510130 16274 5ustar00unknownunknown000000000000Linux-Distribution-0.21/lib/Linux000755000000000000 011721510130 17373 5ustar00unknownunknown000000000000Linux-Distribution-0.21/lib/Linux/Distribution.pm000444000000000000 1731711721506226 22611 0ustar00unknownunknown000000000000package Linux::Distribution; use 5.006000; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw( distribution_name distribution_version ); our $VERSION = '0.21'; our $release_files_directory='/etc'; our $standard_release_file = 'lsb-release'; our %release_files = ( 'gentoo-release' => 'gentoo', 'fedora-release' => 'fedora', 'centos-release' => 'centos', 'enterprise-release' => 'oracle enterprise linux', 'turbolinux-release' => 'turbolinux', 'mandrake-release' => 'mandrake', 'mandrakelinux-release' => 'mandrakelinux', 'debian_version' => 'debian', 'debian_release' => 'debian', 'SuSE-release' => 'suse', 'knoppix-version' => 'knoppix', 'yellowdog-release' => 'yellowdog', 'slackware-version' => 'slackware', 'slackware-release' => 'slackware', 'redflag-release' => 'redflag', 'redhat-release' => 'redhat', 'redhat_version' => 'redhat', 'conectiva-release' => 'conectiva', 'immunix-release' => 'immunix', 'tinysofa-release' => 'tinysofa', 'trustix-release' => 'trustix', 'adamantix_version' => 'adamantix', 'yoper-release' => 'yoper', 'arch-release' => 'arch', 'libranet_version' => 'libranet', 'va-release' => 'va-linux', 'pardus-release' => 'pardus', ); our %version_match = ( 'gentoo' => 'Gentoo Base System release (.*)', 'debian' => '(.+)', 'suse' => 'VERSION = (.*)', 'fedora' => 'Fedora(?: Core)? release (\d+) \(', 'redflag' => 'Red Flag (?:Desktop|Linux) (?:release |\()(.*?)(?: \(.+)?\)', 'redhat' => 'Red Hat(?: Enterprise)? Linux(?: Server)? release (.*) \(', 'oracle enterprise linux' => 'Enterprise Linux Server release (.+) \(', 'slackware' => '^Slackware (.+)$', 'pardus' => '^Pardus (.+)$', 'centos' => '^CentOS(?: Linux)? release (.+)(?:\s\(Final\))', 'scientific' => '^Scientific Linux release (.+) \(', ); if ($^O ne 'linux') { # require Carp; # Carp::croak('you are trying to use a linux specific module on a different OS'); } sub new { my %self = ( 'DISTRIB_ID' => '', 'DISTRIB_RELEASE' => '', 'DISTRIB_CODENAME' => '', 'DISTRIB_DESCRIPTION' => '', 'release_file' => '', 'pattern' => '' ); return bless \%self; } sub distribution_name { my $self = shift || new(); my $distro; if ($distro = $self->_get_lsb_info()){ return $distro if ($distro); } foreach (qw(enterprise-release fedora-release)) { if (-f "$release_files_directory/$_" && !-l "$release_files_directory/$_"){ if (-f "$release_files_directory/$_" && !-l "$release_files_directory/$_"){ $self->{'DISTRIB_ID'} = $release_files{$_}; $self->{'release_file'} = $_; return $self->{'DISTRIB_ID'}; } } } foreach (keys %release_files) { if (-f "$release_files_directory/$_" && !-l "$release_files_directory/$_"){ if (-f "$release_files_directory/$_" && !-l "$release_files_directory/$_"){ if ( $release_files{$_} eq 'redhat' ) { foreach my $rhel_deriv ('centos','scientific',) { $self->{'pattern'} = $version_match{$rhel_deriv}; $self->{'release_file'}='redhat-release'; if ( $self->_get_file_info() ) { $self->{'DISTRIB_ID'} = $rhel_deriv; $self->{'release_file'} = $_; return $self->{'DISTRIB_ID'}; } } $self->{'pattern'}=''; } $self->{'release_file'} = $_; $self->{'DISTRIB_ID'} = $release_files{$_}; return $self->{'DISTRIB_ID'}; } } } undef } sub distribution_version { my $self = shift || new(); my $release; return $release if ($release = $self->_get_lsb_info('DISTRIB_RELEASE')); if (! $self->{'DISTRIB_ID'}){ $self->distribution_name() or die 'No version because no distro.'; } $self->{'pattern'} = $version_match{$self->{'DISTRIB_ID'}}; $release = $self->_get_file_info(); $self->{'DISTRIB_RELEASE'} = $release; return $release; } sub _get_lsb_info { my $self = shift; my $field = shift || 'DISTRIB_ID'; my $tmp = $self->{'release_file'}; if ( -r "$release_files_directory/" . $standard_release_file ) { $self->{'release_file'} = $standard_release_file; $self->{'pattern'} = $field . '=(.+)'; my $info = $self->_get_file_info(); if ($info){ $self->{$field} = $info; return $info } } $self->{'release_file'} = $tmp; $self->{'pattern'} = ''; undef; } sub _get_file_info { my $self = shift; open my $fh, '<', "$release_files_directory/" . $self->{'release_file'} or die 'Cannot open file: '.$release_files_directory.'/' . $self->{'release_file'}; my $info = ''; local $_; while (<$fh>){ chomp $_; ($info) = $_ =~ m/$self->{'pattern'}/; return "\L$info" if $info; } undef; } 1; __END__ =head1 NAME Linux::Distribution - Perl extension to detect on which Linux distribution we are running. =head1 SYNOPSIS use Linux::Distribution qw(distribution_name distribution_version); if(my $distro = distribution_name) { my $version = distribution_version(); print "you are running $distro, version $version\n"; } else { print "distribution unknown\n"; } Or else do it OO: use Linux::Distribution qw(distribution_name distribution_version); my $linux = Linux::Distribution->new; if(my $distro = $linux->distribution_name()) { my $version = $linux->distribution_version(); print "you are running $distro, version $version\n"; } else { print "distribution unknown\n"; } =head1 DESCRIPTION This is a simple module that tries to guess on what linux distribution we are running by looking for release's files in /etc. It now looks for 'lsb-release' first as that should be the most correct and adds ubuntu support. Secondly, it will look for the distro specific files. It currently recognizes slackware, debian, suse, fedora, redhat, turbolinux, yellowdog, knoppix, mandrake, conectiva, immunix, tinysofa, va-linux, trustix, adamantix, yoper, arch-linux, libranet, gentoo, ubuntu, scientific, oracle enterprise linux and redflag. It has function to get the version for debian, suse, fedora, redhat, gentoo, slackware, scientific, oracle enterprise linux, redflag and ubuntu(lsb). People running unsupported distro's are greatly encouraged to submit patches :-) =head2 EXPORT None by default. =head1 TODO Add the capability of recognize the version of the distribution for all recognized distributions. =head1 AUTHORS Alexandr Ciornii Ealexchorny@gmail.comE, L Alberto Re, Ealberto@accidia.netE Judith Lebzelter, Ejudith@osdl.orgE =head1 COPYRIGHT AND LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available. =cut Linux-Distribution-0.21/t000755000000000000 011721510130 15771 5ustar00unknownunknown000000000000Linux-Distribution-0.21/t/centos.t000444000000000000 55111721506226 17602 0ustar00unknownunknown000000000000use 5.006000; use strict; use warnings; use Test::More tests => 2; use lib '../lib/'; use Linux::Distribution; local $Linux::Distribution::release_files_directory='t/centos/'; my $linux = Linux::Distribution->new; my $distro = $linux->distribution_name(); is($distro,'centos'); my $version = $linux->distribution_version(); is ($version,'5.5'); Linux-Distribution-0.21/t/centos6.t000444000000000000 55211721506226 17671 0ustar00unknownunknown000000000000use 5.006000; use strict; use warnings; use Test::More tests => 2; use lib '../lib/'; use Linux::Distribution; local $Linux::Distribution::release_files_directory='t/centos6/'; my $linux = Linux::Distribution->new; my $distro = $linux->distribution_name(); is($distro,'centos'); my $version = $linux->distribution_version(); is ($version,'6.0'); Linux-Distribution-0.21/t/fedora15.t000444000000000000 55211721506226 17716 0ustar00unknownunknown000000000000use 5.006000; use strict; use warnings; use Test::More tests => 2; use lib '../lib/'; use Linux::Distribution; local $Linux::Distribution::release_files_directory='t/fedora15/'; my $linux = Linux::Distribution->new; my $distro = $linux->distribution_name(); is($distro,'fedora'); my $version = $linux->distribution_version(); is ($version,'15'); Linux-Distribution-0.21/t/Linux-Distribution.t000444000000000000 173411721506226 22107 0ustar00unknownunknown000000000000# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl Linux-Distribution.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test::More tests => 2; BEGIN { use_ok('Linux::Distribution') }; if(isnt(Linux::Distribution::distribution_name(), undef, 'Checking your distro...')) { diag('It seems that we are running on '.Linux::Distribution::distribution_name.' version '.(Linux::Distribution::distribution_version || 'unknown')) } else { diag ('Please report your Linux dist to dist maintainer'); if (-e '/etc/lsb-release') { diag ('lsb-release exists') ; open my $fh,'<','/etc/lsb-release'; my $content=join('',<$fh>); diag($content); } } ######################### # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script. Linux-Distribution-0.21/t/oel6.t000444000000000000 57011721506226 17155 0ustar00unknownunknown000000000000use 5.006000; use strict; use warnings; use Test::More tests => 2; use lib '../lib/'; use Linux::Distribution; local $Linux::Distribution::release_files_directory='t/oel6/'; my $linux = Linux::Distribution->new; my $distro = $linux->distribution_name(); is($distro,'oracle enterprise linux'); my $version = $linux->distribution_version(); is ($version,'5.6'); Linux-Distribution-0.21/t/rhel6.t000444000000000000 55011721506226 17326 0ustar00unknownunknown000000000000use 5.006000; use strict; use warnings; use Test::More tests => 2; use lib '../lib/'; use Linux::Distribution; local $Linux::Distribution::release_files_directory='t/rhel6/'; my $linux = Linux::Distribution->new; my $distro = $linux->distribution_name(); is($distro,'redhat'); my $version = $linux->distribution_version(); is ($version,'6.1'); Linux-Distribution-0.21/t/scientific6.t000444000000000000 56211721506226 20517 0ustar00unknownunknown000000000000use 5.006000; use strict; use warnings; use Test::More tests => 2; use lib '../lib/'; use Linux::Distribution; local $Linux::Distribution::release_files_directory='t/scientific6/'; my $linux = Linux::Distribution->new; my $distro = $linux->distribution_name(); is($distro,'scientific'); my $version = $linux->distribution_version(); is ($version,'6.1'); Linux-Distribution-0.21/t/centos000755000000000000 011721510130 17264 5ustar00unknownunknown000000000000Linux-Distribution-0.21/t/centos/files000444000000000000 7711721506226 20425 0ustar00unknownunknown000000000000exists: redhat-release do not: redhat_version lsb-release Linux-Distribution-0.21/t/centos/redhat-release000444000000000000 3411721506226 22201 0ustar00unknownunknown000000000000CentOS release 5.5 (Final) Linux-Distribution-0.21/t/centos6000755000000000000 011721510130 17352 5ustar00unknownunknown000000000000Linux-Distribution-0.21/t/centos6/centos-release000444000000000000 4211721506226 22312 0ustar00unknownunknown000000000000CentOS Linux release 6.0 (Final) Linux-Distribution-0.21/t/centos6/files000444000000000000 7711721506226 20513 0ustar00unknownunknown000000000000exists: centos-release do not: redhat_version lsb-release Linux-Distribution-0.21/t/fedora15000755000000000000 011721510130 17377 5ustar00unknownunknown000000000000Linux-Distribution-0.21/t/fedora15/fedora-release000444000000000000 3611721506226 22307 0ustar00unknownunknown000000000000Fedora release 15 (Lovelock) Linux-Distribution-0.21/t/fedora15/files000444000000000000 11711721506226 20553 0ustar00unknownunknown000000000000exists: redhat-release fedora-release do not: redhat_version lsb-release Linux-Distribution-0.21/t/fedora15/redhat-release000444000000000000 3611721506226 22316 0ustar00unknownunknown000000000000Fedora release 15 (Lovelock) Linux-Distribution-0.21/t/oel6000755000000000000 011721510130 16636 5ustar00unknownunknown000000000000Linux-Distribution-0.21/t/oel6/enterprise-release000444000000000000 10111721506226 22477 0ustar00unknownunknown000000000000Enterprise Linux Enterprise Linux Server release 5.6 (Carthage) Linux-Distribution-0.21/t/oel6/files000444000000000000 12311721506226 20007 0ustar00unknownunknown000000000000exists: enterprise-release redhat-release do not: redhat_version lsb-release Linux-Distribution-0.21/t/oel6/redhat-release000444000000000000 6711721506226 21561 0ustar00unknownunknown000000000000Red Hat Enterprise Linux Server release 5.6 (Tikanga) Linux-Distribution-0.21/t/rhel6000755000000000000 011721510127 17017 5ustar00unknownunknown000000000000Linux-Distribution-0.21/t/rhel6/files000444000000000000 7711721506226 20152 0ustar00unknownunknown000000000000exists: redhat-release do not: redhat_version lsb-release Linux-Distribution-0.21/t/rhel6/redhat-release000444000000000000 7211721506226 21730 0ustar00unknownunknown000000000000Red Hat Enterprise Linux Server release 6.1 (Santiago) Linux-Distribution-0.21/t/scientific6000755000000000000 011721510130 20177 5ustar00unknownunknown000000000000Linux-Distribution-0.21/t/scientific6/files000444000000000000 7711721506226 21340 0ustar00unknownunknown000000000000exists: redhat-release do not: redhat_version lsb-release Linux-Distribution-0.21/t/scientific6/redhat-release000444000000000000 4711721506226 23120 0ustar00unknownunknown000000000000Scientific Linux release 6.1 (Carbon)