spec: prevent 'myhostname' from being appended on upgrade

Without that patch, on every package upgrade, a 'myhostname' is forcibly
appended to hosts in nsswitch.conf which is not desirable for some customers.

It is required until authselect change introduction in RHEL.

RHEL-only

Resolves: #2187761
This commit is contained in:
Jacek Migacz 2023-07-07 13:37:00 +02:00
parent a0e2ca72a7
commit b27d491859

View File

@ -1497,32 +1497,32 @@ fi
%{?ldconfig}
function mod_nss() {
if [ -f "$1" ] ; then
# sed-fu to add myhostname to hosts line
grep -E -q '^hosts:.* myhostname' "$1" ||
if [ $1 -eq 1 ] && [ -f "$2" ]; then
# sed-fu to add myhostname to hosts line (only once, on install)
grep -E -q '^hosts:.* myhostname' "$2" ||
sed -i.bak -e '
/^hosts:/ !b
/\<myhostname\>/ b
s/[[:blank:]]*$/ myhostname/
' "$1" &>/dev/null || :
' "$2" &>/dev/null || :
# Add nss-systemd to passwd and group
grep -E -q '^(passwd|group):.* systemd' "$1" ||
# Add nss-systemd to passwd and group (only once, on install)
grep -E -q '^(passwd|group):.* systemd' "$2" ||
sed -i.bak -r -e '
s/^(passwd|group):(.*)/\1: \2 systemd/
' "$1" &>/dev/null || :
' "$2" &>/dev/null || :
fi
}
FILE="$(readlink /etc/nsswitch.conf || echo /etc/nsswitch.conf)"
if [ "$FILE" = "/etc/authselect/nsswitch.conf" ] && authselect check &>/dev/null; then
mod_nss "/etc/authselect/user-nsswitch.conf"
mod_nss $1 "/etc/authselect/user-nsswitch.conf"
authselect apply-changes &> /dev/null || :
else
mod_nss "$FILE"
mod_nss $1 "$FILE"
# also apply the same changes to user-nsswitch.conf to affect
# possible future authselect configuration
mod_nss "/etc/authselect/user-nsswitch.conf"
mod_nss $1 "/etc/authselect/user-nsswitch.conf"
fi
# check if nobody or nfsnobody is defined