From 2d7e57c7e1355bbfef89ddb778e523bca4f8083c Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Fri, 25 Aug 2023 18:59:03 +0300 Subject: [PATCH] Add hostname detection using `hostnamectl` command --- web-lib-funcs.pl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index 2b2e47a28..ae80bada8 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -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) {