]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Fixing postinstall-scripts/update-all-packages
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 27 Sep 2024 09:27:52 +0000 (11:27 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 27 Sep 2024 09:27:52 +0000 (11:27 +0200)
postinstall-scripts/update-all-packages

index 0508345d375f10d64d99b9df87b02c488697ab07..7012c1e8eb3d0928470f5311dd33bb4864110b93 100755 (executable)
@@ -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