From fde2a44c3f240340558fc05ee24edb92d3362803 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 27 Sep 2024 11:27:52 +0200 Subject: [PATCH] Fixing postinstall-scripts/update-all-packages --- postinstall-scripts/update-all-packages | 35 ++++++++++++++++--------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/postinstall-scripts/update-all-packages b/postinstall-scripts/update-all-packages index 0508345..7012c1e 100755 --- a/postinstall-scripts/update-all-packages +++ b/postinstall-scripts/update-all-packages @@ -143,8 +143,8 @@ do_el_upgrade() { empty_line info "Performing dist upgrade with ${GREEN}${tool}${NORMAL} ..." - local found_ip_resolv="n" - local awk_script='' + local found_ip_resolv= + local awk_script local cleaned_old_repo="n" local logfile= local cmd= @@ -163,6 +163,7 @@ do_el_upgrade() { empty_line info "Tweaking '${CYAN}${YUM_CONF}${NORMAL}' ..." + found_ip_resolv= if grep '^ip_resolve *= *4' "${YUM_CONF}" >/dev/null ; then debug "Usage of IPv4 already configured" @@ -172,26 +173,36 @@ do_el_upgrade() { found_ip_resolv="y" fi - if [[ "${found_ip_resolv}" == "y" ]] ; then - awk_script='/^[main]/ {ok=1} -ok==1 && /^ip_resolve/ {print "ip_resolve=4"; ok=0; next} -{print $0} ' + awk_script=$( mktemp /tmp/yum.dnf-resolv.XXXXXXXX.awk ) + debug "AWK script: '${CYAN}${awk_script}${NORMAL}'" + + if [[ "${found_ip_resolv}" ]] ; then + cat > "${awk_script}" <<-EOF + /^[main]/ {ok=1} + ok==1 && /^ip_resolve/ {print "ip_resolve=4"; ok=0; next} + {print \$0} + EOF else - awk_script='/^[main]/ {ok=1} -ok==1 {print "ip_resolve=4"; ok=0} -{print $0} ' + cat > "${awk_script}" <<-EOF + /^[main]/ {ok=1} + ok==1 {print "ip_resolve=4"; ok=0} + {print \$0} + EOF fi + debug "Content AWK script:\n$( cat "${awk_script}" )" + empty_line CP -p "${YUM_CONF}" "${YUM_CONF}.$( date -r ${YUM_CONF} +'%Y-%m-%d_%H:%M:%S').bak" - cmd="awk \"${awk_script}\" \"${YUM_CONF}\" > \"${YUM_CONF}.new\"" + cmd="awk -f \"${awk_script}\" \"${YUM_CONF}\" > \"${YUM_CONF}.new\"" exec_cmd ${cmd} if [[ -s "${YUM_CONF}.new" ]] ; then MV "${YUM_CONF}.new" "${YUM_CONF}" else RM -f "${YUM_CONF}.new" fi + RM_force "${awk_script}" fi - cmd="sed -i -e '/tsflags=/d' \"${YUM_CONF}\"" + cmd="sed -i -e '/tsflags *=/d' \"${YUM_CONF}\"" exec_cmd ${cmd} if [[ "${VERBOSE}" == "y" ]] ; then @@ -331,4 +342,4 @@ main "$@" exit 0 -# vim: list +# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list -- 2.39.5