From b27d491859cc354eac2d6e0563e0f5e0feb40c5c Mon Sep 17 00:00:00 2001 From: Jacek Migacz Date: Fri, 7 Jul 2023 13:37:00 +0200 Subject: [PATCH] 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 --- systemd.spec | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/systemd.spec b/systemd.spec index ff01e9d..1ddf849 100644 --- a/systemd.spec +++ b/systemd.spec @@ -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 /\/ 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