# Figure out what OS is running and grab the appropriate repo file # Created: admin # Last Modified: 1-30-2016 #!/bin/bash update_epel_repo() { #check if epel repo is configured and change it to use internal repo echo "Checking existing epel config" if [ ! -f /etc/yum.repos.d/epel.repo.orig ]; then if [ -f /etc/yum.repos.d/epel.repo ]; then mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.orig fi fi wget http://el${OS_VER}repo/repo/Epel.repo -O /etc/yum.repos.d/Epel.repo } set_default_repos() { # Get info about the current system OS_VER=`cat /etc/system-release-cpe |cut -d : -f5 |cut -c1` # should return value of redhat/centos etc DISTRO=`cat /etc/system-release-cpe |cut -d : -f3` # First test against RHEL if [[ "$DISTRO" == redhat ]]; then # disable subscription manager if [ $(subscription-manager config |grep manage_repos |cut -d = -f2) == 0 ]; then echo "Subscription Manager Currently Disabled" else subscription-manager config --rhsm.manage_repos=0 echo "Disabling Subscription Manager" fi wget http://el${OS_VER}repo/repo/Redhat.repo -O /etc/yum.repos.d/Redhat.repo # Then test against centos elif [[ "$DISTRO" == centos ]]; then if [ ! -f /etc/yum.repos.d/CentOS-Base.repo.orig ]; then cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.orig fi wget http://el${OS_VER}repo/repo/CentOS-Base.repo -O /etc/yum.repos.d/CentOS-Base.repo fi } # Only root can run the script if [[ $EUID -ne 0 ]]; then echo "This script must be run as root" 1>&2 exit 1 else #check for wget prior to executing if [ $(command -v wget) ]; then # Setup default repos using custom repo file # Dependant on DISTRO and OS_VER set_default_repos #check if epel repo is setup #add an empty file to fake out the script #touch /etc/yum.repos.d/epel.repo if [ -f /etc/yum.repos.d/epel.repo ]; then #convert existing epel instance update_epel_repo fi else echo "wget is not installed, install it with yum install wget" fi fi