]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Cleaning up new provisioned hosts after yum upgrade
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 5 Nov 2019 14:26:53 +0000 (15:26 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 5 Nov 2019 14:26:53 +0000 (15:26 +0100)
postinstall-scripts/update-all-packages

index 4e02efb2f585e2f73d69ba484cdb799d398a56a9..e1df7817779776e0aedbc04f1ecea14bfb3216a1 100755 (executable)
@@ -21,7 +21,7 @@ NORMAL=""
 HAS_TTY='y'
 HAS_COLORS="n"
 
-VERSION="0.4"
+VERSION="0.5"
 
 BASENAME="$(basename ${0})"
 BASE_DIR="$(dirname ${0})"
@@ -299,6 +299,41 @@ ok==1 {print "ip_resolve=4"; ok=0}
     debug "Executing: ${cmd}"
     eval ${cmd}
 
+    local stem=
+    local repo_dir="/etc/yum.repos.d"
+    local old_repo_dir="${repo_dir}/.old"
+    local cleaned_old_repo="n"
+    for stem in "oracle-linux-ol7" "public-yum-ol7" ; do
+        local i=0
+        local orig_repo="${repo_dir}/${stem}.repo"
+        local bak_repo="${old_repo_dir}/${stem}.${i}.repo"
+        if [[ -f "${orig_repo}" ]] ; then
+            cleaned_old_repo="y"
+            info "Repo file '${YELLOW}${orig_repo}${NORMAL}' exists, moving it to '${GREEN}${old_repo_dir}${NORMAL}' ..."
+            while [[ -e "${bak_repo}" ]] ; do
+                i=$(( $i + 1 ))
+                bak_repo="${old_repo_dir}/${stem}.${i}.repo"
+            done
+            md="mv ${verbose_opt} \"${orig_repo}\" \"${bak_repo}\""
+            debug "Executing: ${cmd}"
+            eval ${cmd}
+        fi
+    done
+
+    if [[ "${cleaned_old_repo}" == "y" ]] ; then
+        echo
+        info "Cleaning again ..."
+        local cmd="${tool}${verbose_opt} --assumeyes clean all"
+        debug "Executing: ${cmd}"
+        eval ${cmd}
+
+        echo
+        info "Making cache again ..."
+        cmd="${tool}${verbose_opt} --assumeyes makecache"
+        debug "Executing: ${cmd}"
+        eval ${cmd}
+    fi
+
 }
 
 #------------------------------------------------------------------------------