From 40879dae3b6655a4447b92fec4012e0f1f2e5bc1 Mon Sep 17 00:00:00 2001
From: Ian Wienand <iwienand@redhat.com>
Date: Mon, 6 Aug 2018 12:51:18 +1000
Subject: [PATCH] Support puppet5 for bionic

In our wheel build jobs, we try to install puppet with this script on
bionic nodes.  However, there is no <5 puppet distributions for
bionic.

This detects bionic and installs from puppetlabs (note the name seems
different as it's not pc1 any more)

Change-Id: Ica34b7525bab53f8a6d161401f7fb9a2dbe37bc3
---
 install_modules.sh |  4 +++-
 install_puppet.sh  | 15 +++++++++++----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/install_modules.sh b/install_modules.sh
index 8b048f7cd0..f281d2fc0d 100755
--- a/install_modules.sh
+++ b/install_modules.sh
@@ -21,7 +21,9 @@ export PUPPET_VERSION=$(puppet_version)
 
 if [ "$PUPPET_VERSION" == "3" ] ; then
     export MODULE_PATH=/etc/puppet/modules
-elif [ "$PUPPET_VERSION" == "4" ] ; then
+elif [ "$PUPPET_VERSION" == "4" ] || [ "$PUPPET_VERSION" == "5" ]; then
+    # Using puppetlabs builds for wider compatability across distros
+    # than system packages provide.
     export MODULE_PATH=/etc/puppetlabs/code/modules
 else
     echo "ERROR: unsupported puppet version $PUPPET_VERSION"
diff --git a/install_puppet.sh b/install_puppet.sh
index 91013bc901..f4bd6e445b 100755
--- a/install_puppet.sh
+++ b/install_puppet.sh
@@ -24,10 +24,6 @@ SETUP_PIP=${SETUP_PIP:-true}
 # Distro identification functions
 #  note, can't rely on lsb_release for these as we're bare-bones and
 #  it may not be installed yet)
-
-
-PUPPET_VERSION=${PUPPET_VERSION:-3}
-
 function is_fedora {
     [ -f /usr/bin/yum ] && cat /etc/*release | grep -q -e "Fedora"
 }
@@ -57,6 +53,13 @@ if is_fedora && [[ $(lsb_release -rs) -ge 22 ]]; then
     YUM=dnf
 fi
 
+# Set the puppet version
+if cat /etc/os-release | grep -qi bionic; then
+    # bionic only supports puppet 5
+    PUPPET_VERSION=${PUPPET_VERSION:-5}
+else
+    PUPPET_VERSION=${PUPPET_VERSION:-3}
+fi
 
 #
 # Distro specific puppet installs
@@ -216,6 +219,10 @@ function setup_puppet_ubuntu {
         puppetpkg=puppet-agent
         PUPPET_VERSION=4.*
         FACTER_VERSION=3.*
+    elif [ "$PUPPET_VERSION" == "5" ] ; then
+        puppet_deb=puppet5-release-bionic.deb
+        PUPPET_VERSION=5.*
+        FACTER_VERSION=3.*
     else
         echo "Unsupported puppet version ${PUPPET_VERSION}"
         exit 1