]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Truncating strange Yum repos before executing initial Puppet run
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 26 Nov 2019 16:35:25 +0000 (17:35 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 26 Nov 2019 16:35:25 +0000 (17:35 +0100)
postinstall-scripts/init-puppet

index a7971ee40fd61710dfe20c69de1774a61dd60ed0..db6695af05f5dbf3a05bece94e00f4f72d75bf13 100755 (executable)
@@ -397,6 +397,91 @@ 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"
+    debug "Checking '${CYAN}${orig_repo}${NORMAL}' ..."
+
+    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
+
+        if [[ -f "/etc/oracle-release" ]] ; then
+            info "Creating empty '${GREEN}${orig_repo}${NORMAL}' ..."
+            cmd="cp /dev/null \"${orig_repo}\""
+            debug "Executing: ${cmd}"
+            eval ${cmd}
+            return 0
+        else
+            return 1
+        fi
+    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
+
+        echo
+        info "Cleaning YUM ..."
+        local cmd="${tool}${verbose_opt} --assumeyes clean all"
+        debug "Executing: ${cmd}"
+        eval ${cmd}
+
+        echo
+        info "Making YUM cache ..."
+        cmd="${tool}${verbose_opt} --assumeyes makecache"
+        debug "Executing: ${cmd}"
+        eval ${cmd}
+
+        return 0
+    fi
+
+    return 1
+
+}
+
 #------------------------------------------------------------------------------
 check_os() {
 
@@ -621,6 +706,7 @@ main() {
     generate_puppetconf
     generate_facts
 
+    empty_oracle_repo_files || true
     run_agent
 
 }