HEX
Server: Apache/2.4.6 () OpenSSL/1.0.2k-fips PHP/8.3.8
System: Linux gateway.rmc-logistics.net 4.1.12-124.48.6.el7uek.x86_64 #2 SMP Tue Mar 16 14:57:50 PDT 2021 x86_64
User: apache (48)
PHP: 8.3.8
Disabled: NONE
Upload Files
File: //usr/bin/ol_yum_configure.sh
#!/bin/bash

# Copyright (C) 2018 Oracle. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, version 2.  This program is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
# Public License for more details.  You should have received a copy of the GNU
# General Public License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 021110-1307, USA.
#============================================================================
# This script identify and installs packages required to setup new set of 
# yum repository definition files based on current yum repository configuration
#
# Usage:
#
#  ol_yum_configure.sh
#
#============================================================================

restore()
{
for file in /etc/yum.repos.d/*-ol7.repo
do
  mv "$file" "${file}.disabled"
done

   mv /etc/yum.repos.d/public-yum-ol7.repo.sav /etc/yum.repos.d/public-yum-ol7.repo
   cleanup
}

cleanup()
{
   rm -f "$REPOLIST_FILE" "$REPOLIST_FILE_NEW" "$RUN_FILE"
   
}

trap 'restore' SIGHUP SIGINT SIGTERM
trap 'cleanup' EXIT

UserId=$(id -u)
if [ "$UserId" != 0 ]; then
   echo This script should to be run as root user
   exit
fi
if [ ! -f /etc/yum.repos.d/public-yum-ol7.repo ]; then
  echo "Missing /etc/yum.repos.d/public-yum-ol7.repo. Exiting "
  exit
fi

PACKAGE_LIST="ceph php nodejs epel gluster oci-included ksplice spacewalk.*server spacewalk.*client mysql software openstack oraclelinux_developer patch developer oracle golang"
REPOLIST_FILE=$(mktemp /tmp/oracle_enable_repolist.XXXXXX) || exit 1
REPOLIST_FILE_NEW=$(mktemp /tmp/oracle_enable_repolist_new.XXXXXX) || exit 1
RUN_FILE=/etc/yum.repos.d/.ol_yum_configure

touch $RUN_FILE


yum-config-manager | grep "^\[.*ol7.*\]" | grep -v -E "x86_64|aarch64" | sed -e 's/^\[//;s/\]$//' > "$REPOLIST_FILE"

PACKAGE_TO_INSTALL=
SPCWLK_SERVER=no
OCI_ONLY=no
for pkg in $PACKAGE_LIST
do
   PACKAGE_NAME=
   if grep -i "$pkg" "$REPOLIST_FILE" > /dev/null ; then
     case "$pkg" in
       ksplice) OCI_ONLY=yes
                PACKAGE_NAME=${pkg}-release-el7
       ;;
       patch) OCI_ONLY=yes
             PACKAGE_NAME=oraclelinux-patchonly-release-el7
       ;;
       developer) if grep -i -E "$pkg$|${pkg} |${pkg}_UEKR5|${pkg}_kvm" "$REPOLIST_FILE" > /dev/null ; then
                  PACKAGE_NAME=oraclelinux-developer-release-el7
                fi
       ;;
      'spacewalk.*server') PACKAGE_NAME=oracle-spacewalk-server-release-el7
                           SPCWLK_SERVER=yes
       ;;
      'spacewalk.*client') PACKAGE_NAME=oracle-spacewalk-client-release-el7
       ;;
       software) PACKAGE_NAME=oracle-softwarecollection-release-el7
       ;;
       ceph|php|golang|nodejs|epel|openstack|gluster) PACKAGE_NAME=oracle-${pkg}-release-el7
       ;;
       *) PACKAGE_NAME=${pkg}-release-el7
       ;;
      esac
            
   PACKAGE_TO_INSTALL="$PACKAGE_TO_INSTALL $PACKAGE_NAME"
   fi
done
if [  -n "$PACKAGE_TO_INSTALL" ]; then
RPM_INSTALL=no
if [ $SPCWLK_SERVER = yes ]; then
 PACKAGE_TO_INSTALL=${PACKAGE_TO_INSTALL//spacewalk-client-release-el7//}
fi
COMMAND="yum -y install "
for pkg in $PACKAGE_TO_INSTALL
do
  if rpm -qa | grep "$pkg" > /dev/null; then
     echo "$pkg" already installed
 else
    COMMAND="$COMMAND $pkg"
    RPM_INSTALL=yes
 fi
done

   if [ $RPM_INSTALL = yes ]; then
     if [ -f /var/run/yum.pid ]; then
       echo "Another yum command (PID:$(</var/run/yum.pid)) holding a yum lock. Try running $0 later."
       exit
     fi
     if [ $OCI_ONLY = yes ]; then
        if  grep ol7_oci_included /etc/yum.repos.d/public-yum-ol7.repo  ; then
          yum-config-manager --enable ol7_oci_included
        fi
     fi
     echo "$PACKAGE_TO_INSTALL"
     $COMMAND
     if [ $? != 0 ]; then
       echo "Installation aborted. Exiting...."
       cleanup
       exit 
     fi
   fi
fi

#DisabledRepoFiles=$(ls -1 /etc/yum.repos.d/*-ol7.repo.disabled)
yum-config-manager | grep "^\[.*ol7.*\]" | grep -v -E "x86_64|aarch64" | sed -e 's/^\[//;s/\]$//' > "$REPOLIST_FILE"

mv /etc/yum.repos.d/public-yum-ol7.repo  /etc/yum.repos.d/public-yum-ol7.repo.sav
for file in /etc/yum.repos.d/*-ol7.repo.disabled
do
  mv "$file" "${file//.disabled/}"
done

yum-config-manager | grep "^\[.*ol7.*\]" | grep -v -E "x86_64|aarch64" | sed -e 's/^\[//;s/\]$//' > "$REPOLIST_FILE_NEW"

while read -r repo
do
   if grep "$repo" "$REPOLIST_FILE" > /dev/null ; then
     echo  Repository "$repo" already enabled
   else
     echo Disabling Repository "$repo"
     yum-config-manager --disable "$repo" > /dev/null
   fi
done < "$REPOLIST_FILE_NEW"

IncompletedRepoFiles=$(ls -1 /etc/yum.repos.d/*-ol7.repo.incomplete 2> /dev/null)
if [ -n "$IncompletedRepoFiles" ]; then 
for file in /etc/yum.repos.d/*-ol7.repo.incomplete
do
  if [ ! -f "${file//.incomplete/}" ]; then
    mv "$file" "${file//.incomplete/}"
  fi
done
fi