Oracle Linux 7 – Automatic Script for Restoration of EPEL Repo

Somehow in the past couple months Oracle has stopped shipping the reference for EPEL in their base image for Docker – oraclelinux:7-slim 

This caused an issue for some code I’d written and quite frankly annoyed the crap out of me considering they explicitly added a command in newer versions of their images that allows you to enable the repo without having to manually add it to a file.

So here’s what I did.

  1. I first looked for a current up to date mirror that contains all the yum repositories and their endpoints that are officially maintained by Oracle
  2. Inside the file if you search epel you will be presented with the following:
    • [ol7_developer_EPEL]
      name=Oracle Linux $releasever Development Packages ($basearch)
      baseurl=https://yum.oracle.com/repo/OracleLinux/OL7/developer_EPEL/$basearch/
      gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
      gpgcheck=1
      enabled=0
  3. What I did next was take this whole string and bake it into an “enable” script for bash, the script does the following:
    • Greps every file in /etc/yum.repos.d/ for the string “EPEL”
    • If TRUE, break from for loop and end script
    • If FALSE, write this copied string from above to it’s own file in “/etc/yum.repos.d/” as “oracle-epel.repo” and set appropriate permissions
#!/bin/bash

#Ensure nothing happens outside the directory this script is ran from
cd "$(dirname "$0")"
SCRIPT_DIRECTORY=$(pwd)

EPEL_FILE_CONTENTS='[ol7_developer_EPEL]
name=Oracle Linux $releasever Development Packages ($basearch)
baseurl=https://yum.oracle.com/repo/OracleLinux/OL7/developer_EPEL/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1'

DIRECTORY_YUM_REPO_FILES='/etc/yum.repos.d'
EPEL_FILE_NAME="$DIRECTORY_YUM_REPO_FILES/oracle-epel.repo"
EPEL_FILE_OWNER='root:root'
EPEL_FILE_CHMOD='644'

function misc_stringInFile()
{
    STRING_TO_FIND="$1"
    FILE_TO_SEARCH="$2"

    if grep -iqF "$STRING_TO_FIND" "$FILE_TO_SEARCH";then
        echo "TRUE"
    else
        echo "FALSE"
    fi
}

function checkOracleRepoFiles()
{
    cd "$DIRECTORY_YUM_REPO_FILES"

    echo "DIRECTORY - $DIRECTORY_YUM_REPO_FILES - Checking if EPEL is contained within any of the files..."

    EPEL_IS_IN_FILE="FALSE"

    for VARIABLE_YUM_REPO_FILE in * ; do

        cd "$DIRECTORY_YUM_REPO_FILES"

        if [ -f "./$VARIABLE_YUM_REPO_FILE" ]; then

            echo "DIRECTORY - $DIRECTORY_YUM_REPO_FILES - FILE - $VARIABLE_YUM_REPO_FILE - Checking if EPEL is contained within..."

            EPEL_IS_IN_FILE=$(misc_stringInFile "EPEL" "$VARIABLE_YUM_REPO_FILE")

            if [ "$EPEL_IS_IN_FILE" = "TRUE" ]
            then
                echo "DIRECTORY - $DIRECTORY_YUM_REPO_FILES - FILE - $VARIABLE_YUM_REPO_FILE - TRUE - EPEL was detected..."
                break
            else
                echo "DIRECTORY - $DIRECTORY_YUM_REPO_FILES - FILE - $VARIABLE_YUM_REPO_FILE - FALSE - EPEL was not detected..."
            fi
        fi

    done

    if [ "$EPEL_IS_IN_FILE" = "FALSE" ]
    then
        echo "Adding EPEL Repository File since it wasn't detected in the Oracle Linux Image"
        echo "DIRECTORY - $DIRECTORY_YUM_REPO_FILES - FILE - $VARIABLE_YUM_REPO_FILE - FALSE - EPEL was not detected..."
        echo "$EPEL_FILE_CONTENTS" > "$EPEL_FILE_NAME"
        chmod $EPEL_FILE_CHMOD "$EPEL_FILE_NAME"
        chown $EPEL_FILE_OWNER "$EPEL_FILE_NAME"
    fi
}

checkOracleRepoFiles

Closing thoughts – seriously Oracle wtf, if you are going to have a command dedicated to enabling this repo like “yum-config-manager –enable ol7_developer_EPEL” how about we NOT remove the repo it references in future distributions or at the very bare minimum put a comment in one of the files under “/etc/yum.repos.d” saying, “hey we are removing this in future distributions” or something.

I’m sure there was an internal note or publication somewhere about this but damn if that didn’t annoy me to high heaven when I found out something broke because this was missing.

Ya’ll ignore me, I’m just whiny about this. It didn’t take me more than 30 minutes to an hour to find the problem and write a fix.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s