From 8e822768f96945cf5cbe911992513aa244177676 Mon Sep 17 00:00:00 2001
From: Ian Wienand <iwienand@redhat.com>
Date: Thu, 2 Mar 2017 11:11:55 +1100
Subject: [PATCH] Add flag to disable EPEL

Add DIB_EPEL_DISABLED flag that allows installation of the EPEL repo,
but to have it disabled by default.  This will help when you have
unavoidable EPEL dependencies, but want to make sure you only pull
specific things in with "--enablerepo" calls when installing those
packages.

Change-Id: Iedf6167a7cd69418255ebbee095aea04c50d73fd
---
 diskimage_builder/elements/epel/README.rst             | 10 ++++++++++
 .../elements/epel/pre-install.d/05-rpm-epel-release    |  4 ++++
 2 files changed, 14 insertions(+)

diff --git a/diskimage_builder/elements/epel/README.rst b/diskimage_builder/elements/epel/README.rst
index 50464d484..a00571c84 100644
--- a/diskimage_builder/elements/epel/README.rst
+++ b/diskimage_builder/elements/epel/README.rst
@@ -1,9 +1,13 @@
 ====
 epel
 ====
+
 This element installs the Extra Packages for Enterprise Linux (EPEL)
 repository GPG key as well as configuration for yum.
 
+Note this element only works with platforms that have EPEL support
+such as CentOS and RHEL
+
 DIB_EPEL_MIRROR:
    :Required: No
    :Default: None
@@ -11,3 +15,9 @@ DIB_EPEL_MIRROR:
                  before running bin/disk-image-create. This URL should point to
                  the directory containing the ``5/6/7`` directories.
    :Example: ``DIB\_EPEL\_MIRROR=http://dl.fedoraproject.org/pub/epel``
+
+DIB_EPEL_DISABLED:
+   :Required: No
+   :Default: 0
+   :Description: To disable the EPEL repo (but leave it available if
+                 used with an explicit ``--enablerepo``) set this to 1
diff --git a/diskimage_builder/elements/epel/pre-install.d/05-rpm-epel-release b/diskimage_builder/elements/epel/pre-install.d/05-rpm-epel-release
index 5aa35624d..0a4a37dae 100755
--- a/diskimage_builder/elements/epel/pre-install.d/05-rpm-epel-release
+++ b/diskimage_builder/elements/epel/pre-install.d/05-rpm-epel-release
@@ -36,6 +36,10 @@ else
     rpm -q epel-release || yum install -y $URL/$PKG_NAME
 fi
 
+if [ ${DIB_EPEL_DISABLED:-0} -ne 0 ]; then
+    yum-config-manager --disable epel
+fi
+
 DIB_EPEL_MIRROR=${DIB_EPEL_MIRROR:-}
 [ -n "$DIB_EPEL_MIRROR" ] || exit 0