Add hostname detection using hostnamectl command

This commit is contained in:
Ilia Ross
2023-08-25 18:59:03 +03:00
parent 30e6360fa2
commit 2d7e57c7e1

View File

@@ -4250,6 +4250,17 @@ my $m = int($_[0]);
my $skipfile = $_[1];
if (!$main::get_system_hostname[$m]) {
if ($gconfig{'os_type'} ne 'windows') {
# Try hostnamectl command on Linux
if (&has_command("hostnamectl")) {
my $hostname =
&backquote_command("hostnamectl --static");
chop($hostname);
if ($? == 0 && $hostname =~ /\./) {
$hostname =~ s/\..*$// if ($m);
$main::get_system_hostname[$m] = $hostname;
return $hostname;
}
}
# Try some common Linux hostname files first
my $fromfile;
if ($skipfile) {