!37 Add fallback to hostname determination

From: @hugel 
Reviewed-by: @shenyangyang01 
Signed-off-by: @shenyangyang01
This commit is contained in:
openeuler-ci-bot 2025-02-07 01:46:20 +00:00 committed by Gitee
commit f2fced005e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,32 @@
From ddd74b5d971a734c7e88cda3764f7e059f163b51 Mon Sep 17 00:00:00 2001
From: Pavel Zhukov <pzhukov@redhat.com>
Date: Jul 14 2021 10:26:33 +0000
Subject: Add fallback to hostname determination
Use hostname in case if hostnamectl is not available/not functional.
fallback to uname in case if both hostname and hostnamectl are
missed (in containers)
Reference:https://pagure.io/setup/c/ddd74b5d971a734c7e88cda3764f7e059f163b51
Conflict:Adjusting the command execution sequence and add a prompt.
---
diff --git a/profile b/profile
index 783fe17..542add4 100644
--- a/profile
+++ b/profile
@@ -42,7 +42,10 @@ else
pathmunge /usr/sbin after
fi
-HOSTNAME=`/usr/bin/hostnamectl --transient 2>/dev/null`
+HOSTNAME=$(/usr/bin/hostname 2>/dev/null) || \
+HOSTNAME=$(/usr/bin/uname -n 2>/dev/null) || \
+HOSTNAME=$(/usr/bin/hostnamectl --transient 2>/dev/null) || echo "System commands: hostname uname and hostnamectl, which do not exist."
+
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
export HISTCONTROL=ignoreboth
--
2.27.0

View File

@ -1,13 +1,14 @@
Summary: A set of system configuration and setup files
Name: setup
Version: 2.13.7
Release: 3
Release: 4
License: Public Domain
Group: System Environment/Base
URL: https://pagure.io/setup/
Source0: http://releases.pagure.org/%{name}/%{name}-%{version}.tar.bz2
Patch0: support-filesystems-xfs.patch
Patch1: source-cshlocal-when-login.patch
Patch2: Add-fallback-to-hostname-determination.patch
BuildArch: noarch
BuildRequires: systemd
BuildRequires: bash tcsh perl-interpreter
@ -117,6 +118,9 @@ end
%{_tmpfilesdir}/%{name}.conf
%changelog
* Thu Feb 6 2025 hugel <gengqihu2@h-partners.com> - 2.13.7-4
- Add fallback to hostname determination
* Fri May 6 2022 konglidong <konglidong@uniontech.com> - 2.13.7-3
- modify bogus date in %changelog