Skip to content

Commit

Permalink
use /etc/os-release to detect distribution and version
Browse files Browse the repository at this point in the history
Will return e.g. ('debian','12').

Cfr. #1387
  • Loading branch information
pvdputte authored and sni committed Oct 13, 2024
1 parent 59d8398 commit 4ab24b9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,25 @@ sub _get_os {
} else {
die "Unable to detect distribution and version from $release_file\n";
}
} elsif(-e '/etc/os-release') {
my $release_file = '/etc/os-release';
open(my $fh, '<', $release_file) or die("cannot read $release_file: $!");
foreach (<$fh>) {
if (/^ID="?(.*?)"?$/) {
$os = $1;
}
if (/^VERSION_ID="?(.*?)"?$/) {
$version = $1;
$version =~ s/\..*$//gmx; # we only need the major number
}
}
close $fh;

if ($os && $version) {
return($os, 0+$version);
} else {
die "Unable to detect distribution and version from $release_file\n";
}
}

return($os, $version);
Expand Down

0 comments on commit 4ab24b9

Please sign in to comment.