From 71d2a25c1b1b75eea516a9380a0181fd5d471956 Mon Sep 17 00:00:00 2001 From: David Cantrell Date: Sun, 19 May 2024 21:33:50 +0100 Subject: [PATCH] Add detection for Redhat and its friends and relations --- .github/workflows/redhat.yml | 2 +- MANIFEST | 5 +++++ lib/Devel/AssertOS/Linux/Centos.pm | 35 ++++++++++++++++++++++++++++++ lib/Devel/AssertOS/Linux/Fedora.pm | 35 ++++++++++++++++++++++++++++++ lib/Devel/AssertOS/Linux/RHEL.pm | 35 ++++++++++++++++++++++++++++++ lib/Devel/AssertOS/Linux/Redhat.pm | 31 ++++++++++++++++++++++++++ t/etc-os-release/centos-stream | 13 ----------- t/redhat.t | 27 +++++++++++++++++++++++ 8 files changed, 169 insertions(+), 14 deletions(-) create mode 100644 lib/Devel/AssertOS/Linux/Centos.pm create mode 100644 lib/Devel/AssertOS/Linux/Fedora.pm create mode 100644 lib/Devel/AssertOS/Linux/RHEL.pm create mode 100644 lib/Devel/AssertOS/Linux/Redhat.pm delete mode 100644 t/etc-os-release/centos-stream create mode 100644 t/redhat.t diff --git a/.github/workflows/redhat.yml b/.github/workflows/redhat.yml index d1dce14..4cc86dc 100644 --- a/.github/workflows/redhat.yml +++ b/.github/workflows/redhat.yml @@ -17,5 +17,5 @@ jobs: yes|perl -MCPAN -e 'install Expect' export PERL5OPT=-Mlocal::lib /usr/local/bin/cpanm --installdeps . - perl makefile-expect-driver.pl Linux Unix OSFeatures::POSIXShellRedirection HWCapabilities::Int64 + perl makefile-expect-driver.pl Linux Unix OSFeatures::POSIXShellRedirection HWCapabilities::Int64 Linux::Redhat Linux::RHEL make test diff --git a/MANIFEST b/MANIFEST index 07c9b98..41f4a30 100644 --- a/MANIFEST +++ b/MANIFEST @@ -153,3 +153,8 @@ lib/Devel/AssertOS/Linux/SUSE.pm t/etc-os-release/sles t/suse.t lib/Devel/AssertOS/Linux/SLES.pm +lib/Devel/AssertOS/Linux/Centos.pm +lib/Devel/AssertOS/Linux/Fedora.pm +lib/Devel/AssertOS/Linux/RHEL.pm +lib/Devel/AssertOS/Linux/Redhat.pm +t/redhat.t diff --git a/lib/Devel/AssertOS/Linux/Centos.pm b/lib/Devel/AssertOS/Linux/Centos.pm new file mode 100644 index 0000000..cc66570 --- /dev/null +++ b/lib/Devel/AssertOS/Linux/Centos.pm @@ -0,0 +1,35 @@ +package Devel::AssertOS::Linux::Centos; + +use Devel::CheckOS; +use strict; +use warnings; + +use Devel::CheckOS::Helpers::LinuxOSrelease 'distributor_id'; + +no warnings 'redefine'; + +our $VERSION = '1.0'; + +sub os_is { + my $id = distributor_id; + + Devel::CheckOS::os_is('Linux') && + defined($id) && + $id eq 'centos'; +} + +sub expn { "The operating system is some version of Centos" } + +Devel::CheckOS::die_unsupported() unless ( os_is() ); + +=head1 COPYRIGHT and LICENCE + +Copyright 2024 David Cantrell + +This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively. + +=cut + +1; + + diff --git a/lib/Devel/AssertOS/Linux/Fedora.pm b/lib/Devel/AssertOS/Linux/Fedora.pm new file mode 100644 index 0000000..b816a62 --- /dev/null +++ b/lib/Devel/AssertOS/Linux/Fedora.pm @@ -0,0 +1,35 @@ +package Devel::AssertOS::Linux::Fedora; + +use Devel::CheckOS; +use strict; +use warnings; + +use Devel::CheckOS::Helpers::LinuxOSrelease 'distributor_id'; + +no warnings 'redefine'; + +our $VERSION = '1.0'; + +sub os_is { + my $id = distributor_id; + + Devel::CheckOS::os_is('Linux') && + defined($id) && + $id eq 'fedora'; +} + +sub expn { "The operating system is some version of Fedora" } + +Devel::CheckOS::die_unsupported() unless ( os_is() ); + +=head1 COPYRIGHT and LICENCE + +Copyright 2024 David Cantrell + +This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively. + +=cut + +1; + + diff --git a/lib/Devel/AssertOS/Linux/RHEL.pm b/lib/Devel/AssertOS/Linux/RHEL.pm new file mode 100644 index 0000000..d7fc1f2 --- /dev/null +++ b/lib/Devel/AssertOS/Linux/RHEL.pm @@ -0,0 +1,35 @@ +package Devel::AssertOS::Linux::RHEL; + +use Devel::CheckOS; +use strict; +use warnings; + +use Devel::CheckOS::Helpers::LinuxOSrelease 'distributor_id'; + +no warnings 'redefine'; + +our $VERSION = '1.0'; + +sub os_is { + my $id = distributor_id; + + Devel::CheckOS::os_is('Linux') && + defined($id) && + $id eq 'rhel'; +} + +sub expn { "The operating system is some version of RHEL" } + +Devel::CheckOS::die_unsupported() unless ( os_is() ); + +=head1 COPYRIGHT and LICENCE + +Copyright 2024 David Cantrell + +This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively. + +=cut + +1; + + diff --git a/lib/Devel/AssertOS/Linux/Redhat.pm b/lib/Devel/AssertOS/Linux/Redhat.pm new file mode 100644 index 0000000..bdca31c --- /dev/null +++ b/lib/Devel/AssertOS/Linux/Redhat.pm @@ -0,0 +1,31 @@ +package Devel::AssertOS::Linux::Redhat; + +use Devel::CheckOS; +use strict; +use warnings; + +use Devel::CheckOS::Helpers::LinuxOSrelease 'distributor_id'; + +no warnings 'redefine'; + +our $VERSION = '1.0'; + +sub matches { map { "Linux::$_" } qw(Centos Fedora RHEL) } + +sub os_is { Devel::CheckOS::os_is(matches()) } + +sub expn { "The operating system is some derivative of Redhat - which includes RHEL, Centos, and Fedora" } + +Devel::CheckOS::die_unsupported() unless ( os_is() ); + +=head1 COPYRIGHT and LICENCE + +Copyright 2024 David Cantrell + +This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively. + +=cut + +1; + + diff --git a/t/etc-os-release/centos-stream b/t/etc-os-release/centos-stream deleted file mode 100644 index 796e787..0000000 --- a/t/etc-os-release/centos-stream +++ /dev/null @@ -1,13 +0,0 @@ -NAME="CentOS Stream" -VERSION="9" -ID="centos" -ID_LIKE="rhel fedora" -VERSION_ID="9" -PLATFORM_ID="platform:el9" -PRETTY_NAME="CentOS Stream 9" -ANSI_COLOR="0;31" -CPE_NAME="cpe:/o:centos:centos:9" -HOME_URL="https://centos.org/" -BUG_REPORT_URL="https://bugzilla.redhat.com/" -REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux 9" -REDHAT_SUPPORT_PRODUCT_VERSION="CentOS Stream" diff --git a/t/redhat.t b/t/redhat.t new file mode 100644 index 0000000..e313aab --- /dev/null +++ b/t/redhat.t @@ -0,0 +1,27 @@ +use warnings; +use strict; +use Test::More; +use Devel::CheckOS qw(os_is os_isnt); +use Devel::CheckOS::Helpers::LinuxOSrelease 'distributor_id'; + +local $^O = 'linux'; + +Devel::CheckOS::Helpers::LinuxOSrelease::_set_file('t/etc-os-release/rhel'); +ok(os_is('Linux::RHEL'), "detected RHEL"); +ok(os_is('Linux::Redhat'), "... and also as Redhat"); +ok(os_isnt('Linux::Fedora'), "... but not as Fedora"); +ok(os_isnt('Linux::Centos'), "... or Centos"); + +Devel::CheckOS::Helpers::LinuxOSrelease::_set_file('t/etc-os-release/fedora'); +ok(os_is('Linux::Fedora'), "detected Fedora"); +ok(os_is('Linux::Redhat'), "... and also as Redhat"); +ok(os_isnt('Linux::RHEL'), "... but not as RHEL"); +ok(os_isnt('Linux::Centos'), "... or Centos"); + +Devel::CheckOS::Helpers::LinuxOSrelease::_set_file('t/etc-os-release/centos'); +ok(os_is('Linux::Centos'), "detected Centos"); +ok(os_is('Linux::Redhat'), "... and also as Redhat"); +ok(os_isnt('Linux::Fedora'), "... but not as Fedora"); +ok(os_isnt('Linux::RHEL'), "... or RHEL"); + +done_testing;