From 0c51b4941436817164b9449d2805667c4597429a Mon Sep 17 00:00:00 2001
From: Xinliang Liu <xinliang.liu@linaro.org>
Date: Thu, 14 Jan 2021 03:33:58 +0000
Subject: [PATCH] Add aarch64 support for rhel

Change-Id: I86ccc56e37b214a45ba620b731b51f58d73471f8
---
 .../rhel-common/pre-install.d/00-rhel-registration         | 7 ++++---
 diskimage_builder/elements/rhel/root.d/10-rhel-cloud-image | 4 +++-
 .../add-aarch64-support-for-rhel-c62a0e02b1ad9033.yaml     | 4 ++++
 3 files changed, 11 insertions(+), 4 deletions(-)
 create mode 100644 releasenotes/notes/add-aarch64-support-for-rhel-c62a0e02b1ad9033.yaml

diff --git a/diskimage_builder/elements/rhel-common/pre-install.d/00-rhel-registration b/diskimage_builder/elements/rhel-common/pre-install.d/00-rhel-registration
index 6afe2fc59..7935c72d0 100755
--- a/diskimage_builder/elements/rhel-common/pre-install.d/00-rhel-registration
+++ b/diskimage_builder/elements/rhel-common/pre-install.d/00-rhel-registration
@@ -9,17 +9,18 @@ set -o pipefail
 
 opts=
 attach_opts=
+arch=$(uname -m)
 
 if [ "${DIB_RELEASE:-7}" == "7" ]; then
     repos="repos --enable rhel-7-server-rpms"
     satellite_repo="rhel-7-server-rh-common-rpms"
 elif [ "${DIB_RELEASE}" == "8" ]; then
     if [ -n "${REG_RELEASE:-}" ]; then
-        repos="repos --enable rhel-8-for-x86_64-appstream-eus-rpms --enable rhel-8-for-x86_64-baseos-eus-rpms"
+        repos="repos --enable rhel-8-for-${arch}-appstream-eus-rpms --enable rhel-8-for-${arch}-baseos-eus-rpms"
     else
-        repos="repos --enable rhel-8-for-x86_64-appstream-rpms --enable rhel-8-for-x86_64-baseos-rpms"
+        repos="repos --enable rhel-8-for-${arch}-appstream-rpms --enable rhel-8-for-${arch}-baseos-rpms"
     fi
-    satellite_repo="satellite-tools-6.5-for-rhel-8-x86_64-rpms"
+    satellite_repo="satellite-tools-6.5-for-rhel-8-${arch}-rpms"
 fi
 
 REG_SAT_CERT=${REG_SAT_CERT:-"katello-ca-consumer-latest.noarch.rpm"}
diff --git a/diskimage_builder/elements/rhel/root.d/10-rhel-cloud-image b/diskimage_builder/elements/rhel/root.d/10-rhel-cloud-image
index b1043d892..8e7a8f355 100755
--- a/diskimage_builder/elements/rhel/root.d/10-rhel-cloud-image
+++ b/diskimage_builder/elements/rhel/root.d/10-rhel-cloud-image
@@ -11,11 +11,13 @@ set -o pipefail
 
 if [[ "amd64 x86_64" =~ "$ARCH" ]]; then
     ARCH="x86_64"
+elif [[ "$ARCH" =~ (arm64|aarch64) ]]; then
+    ARCH="aarch64"
 elif [[ "ppc64le" =~ "$ARCH" ]]; then
     # We don't need to do anything here other than avoid the else clause
     :
 else
-    echo 'rhel root element only supports x86_64 and ppc64le values for $ARCH'
+    echo 'rhel root element only supports x86_64, aarch64 and ppc64le values for $ARCH'
     exit 1
 fi
 
diff --git a/releasenotes/notes/add-aarch64-support-for-rhel-c62a0e02b1ad9033.yaml b/releasenotes/notes/add-aarch64-support-for-rhel-c62a0e02b1ad9033.yaml
new file mode 100644
index 000000000..d4da133c6
--- /dev/null
+++ b/releasenotes/notes/add-aarch64-support-for-rhel-c62a0e02b1ad9033.yaml
@@ -0,0 +1,4 @@
+---
+features:
+  - |
+    Add aarch64 support for ''rhel''.