]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Cleaning up yum repository
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 21 Nov 2019 16:27:02 +0000 (17:27 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 21 Nov 2019 16:27:02 +0000 (17:27 +0100)
postinstall-scripts/update-all-packages

index e1df7817779776e0aedbc04f1ecea14bfb3216a1..69a9b1520e5cf9b3b9590a7aa256ade779e83e08 100755 (executable)
@@ -21,7 +21,7 @@ NORMAL=""
 HAS_TTY='y'
 HAS_COLORS="n"
 
-VERSION="0.5"
+VERSION="0.6"
 
 BASENAME="$(basename ${0})"
 BASE_DIR="$(dirname ${0})"
@@ -240,6 +240,68 @@ check_for_root() {
 
 }
 
+#------------------------------------------------------------------------------
+empty_repo_file() {
+
+    local stem="$1"
+    local repo_dir="/etc/yum.repos.d"
+    local old_repo_dir="${repo_dir}/.old"
+    local i=0
+
+    local orig_repo="${repo_dir}/${stem}.repo"
+    local bak_repo="${old_repo_dir}/${stem}.${i}.repo"
+
+    local verbose_opt=""
+    if [[ "${VERBOSE}" == "y" ]] ; then
+         verbose_opt=" --verbose"
+    fi
+
+    if [[ -f "${orig_repo}" && -s "${orig_repo}" ]] ; then
+        info "Repo file '${YELLOW}${orig_repo}${NORMAL}' exists and has a size greater than zero."
+        while [[ -e "${bak_repo}" ]] ; do
+            i=$(( $i + 1 ))
+            bak_repo="${old_repo_dir}/${stem}.${i}.repo"
+        done
+
+        info "Copying '${YELLOW}${orig_repo}${NORMAL}' to '${GREEN}${old_repo_dir}${NORMAL}' ..."
+        cmd="cp -p ${verbose_opt} \"${orig_repo}\" \"${bak_repo}\""
+        debug "Executing: ${cmd}"
+        eval ${cmd}
+
+        info "Truncating '${YELLOW}${orig_repo}${NORMAL}' ..."
+        cmd="cp /dev/null \"${orig_repo}\""
+        debug "Executing: ${cmd}"
+        eval ${cmd}
+
+    else
+        return 1
+    fi
+
+    return 0
+
+}
+
+#------------------------------------------------------------------------------
+empty_oracle_repo_files() {
+
+    local -a stems=("oracle-linux-ol7" "uek-ol7" "virt-ol7" "public-yum-ol7")
+    local cleaned_old_repo="n"
+    local stem=
+
+    for stem in "${stems[@]}" ; do
+        if empty_repo_file "${stem}" ; then
+            cleaned_old_repo="y"
+        fi
+    done
+
+    if [[ "${cleaned_old_repo}" == "y" ]] ; then
+        return 0
+    fi
+
+    return 1
+
+}
+
 #------------------------------------------------------------------------------
 do_el_upgrade() {
 
@@ -250,6 +312,9 @@ do_el_upgrade() {
 
     local found_ip_resolv="n"
     local awk_script=''
+    local cleaned_old_repo="n"
+
+    empty_oracle_repo_files
 
     if grep '^ip_resolve *= *4' /etc/yum.conf >/dev/null ; then
         debug "Usage of IPv4 already configured"
@@ -299,40 +364,19 @@ 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
+    empty_oracle_repo_files
 
-    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 "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
+    echo
+    info "Making cache again ..."
+    cmd="${tool}${verbose_opt} --assumeyes makecache"
+    debug "Executing: ${cmd}"
+    eval ${cmd}
 
 }