From 44a7eaaaca63ca3b75f65e5d024101258963a6ea Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 26 Sep 2024 18:16:00 +0200 Subject: [PATCH] More tweaking of yum/dnf.conf in postinstall-scripts/update-all-packages --- postinstall-scripts/update-all-packages | 67 ++++++++++++++++--------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/postinstall-scripts/update-all-packages b/postinstall-scripts/update-all-packages index 046eb23..0508345 100755 --- a/postinstall-scripts/update-all-packages +++ b/postinstall-scripts/update-all-packages @@ -142,44 +142,65 @@ do_el_upgrade() { empty_line info "Performing dist upgrade with ${GREEN}${tool}${NORMAL} ..." - info "Tweaking '/etc/yum.conf' ..." local found_ip_resolv="n" local awk_script='' local cleaned_old_repo="n" local logfile= + local cmd= empty_oracle_repo_files || true - if grep '^ip_resolve *= *4' /etc/yum.conf >/dev/null ; then - debug "Usage of IPv4 already configured" - else - - if grep '^ip_resolve[ =]' /etc/yum.conf >/dev/null ; then - found_ip_resolv="y" + for YUM_CONF in '/etc/yum.conf' '/etc/dnf/dnf.conf' ; do + if [[ ! -f "${YUM_CONF}" ]] ; then + debug "File '${CYAN}${YUM_CONF}${NORMAL}' does not exists." + continue + fi + if [[ -L "${YUM_CONF}" ]] ; then + debug "File '${CYAN}${YUM_CONF}${NORMAL}' is a symlink." + continue fi - if [[ "${found_ip_resolv}" == "y" ]] ; then - awk_script='/^[main]/ {ok=1} + + empty_line + info "Tweaking '${CYAN}${YUM_CONF}${NORMAL}' ..." + + if grep '^ip_resolve *= *4' "${YUM_CONF}" >/dev/null ; then + debug "Usage of IPv4 already configured" + else + + if grep '^ip_resolve[ =]' "${YUM_CONF}" >/dev/null ; then + 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} ' - else - awk_script='/^[main]/ {ok=1} + else + awk_script='/^[main]/ {ok=1} ok==1 {print "ip_resolve=4"; ok=0} {print $0} ' + fi + 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\"" + exec_cmd ${cmd} + if [[ -s "${YUM_CONF}.new" ]] ; then + MV "${YUM_CONF}.new" "${YUM_CONF}" + else + RM -f "${YUM_CONF}.new" + fi fi - CP -p /etc/yum.conf /etc/yum.conf.$( date -r /etc/yum.conf +'%Y-%m-%d_%H:%M:%S').bak - if [[ "${SIMULATE}" == "y" ]] ; then - info "Simulating: awk \"${awk_script}\" /etc/yum.conf >/etc/yum.conf.new" - else - debug "Executing: awk \"${awk_script}\" /etc/yum.conf >/etc/yum.conf.new" - awk "${awk_script}" /etc/yum.conf >/etc/yum.conf.new - fi - if [[ -s /etc/yum.conf.new ]] ; then - MV /etc/yum.conf.new /etc/yum.conf - else - RM -f /etc/yum.conf.new + + cmd="sed -i -e '/tsflags=/d' \"${YUM_CONF}\"" + exec_cmd ${cmd} + + if [[ "${VERBOSE}" == "y" ]] ; then + empty_line + info "Content of '${CYAN}${YUM_CONF}${NORMAL}':" + cat "${YUM_CONF}" fi - fi + + done echo info "Cleaning ..." -- 2.39.5