From 4143fa0092fe4cafee10b24a97d3ad0b41ab7a30 Mon Sep 17 00:00:00 2001
From: Zang Ruochen <zangrc.fnst@cn.fujitsu.com>
Date: Wed, 7 Aug 2019 03:24:39 +0900
Subject: [PATCH] kpatch-build: allow overriding of distro name

It is sometimes useful to have ability to override
distro name, for example during cross-compilation
build when livepatch modules will be ran on the
target which differs from host.

This patch adds a new --distro option which
implements all needed functionality

Upstream-Status: Pending

Signed-off-by: Ruslan Bilovol <rbilovol@cisco.com>
---
 kpatch-build/kpatch-build | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build
index 39933fc..c0258a2 100755
--- a/kpatch-build/kpatch-build
+++ b/kpatch-build/kpatch-build
@@ -413,12 +413,13 @@ usage() {
 	echo "		                   specify current version of module" >&2
 	echo "		--cross-compile    Specify the prefix used for all executables" >&2
 	echo "		                   used during compilation" >&2
+	echo "		--distro           Override distro name" >&2
 	echo "		--skip-cleanup     Skip post-build cleanup" >&2
 	echo "		--skip-gcc-check   Skip gcc version matching check" >&2
 	echo "		                   (not recommended)" >&2
 }
 
-options="$(getopt -o ha:r:s:c:v:j:t:n:o:de: -l "help,archversion:,sourcerpm:,sourcedir:,config:,vmlinux:,jobs:,target:,name:,output:,oot-module:,debug,cross-compile:,skip-gcc-check,skip-cleanup" -- "$@")" || die "getopt failed"
+options="$(getopt -o ha:r:s:c:v:j:t:n:o:de: -l "help,archversion:,sourcerpm:,sourcedir:,config:,vmlinux:,jobs:,target:,name:,output:,oot-module:,debug,cross-compile:,distro:,skip-gcc-check,skip-cleanup" -- "$@")" || die "getopt failed"
 
 eval set -- "$options"
 
@@ -485,6 +486,10 @@ while [[ $# -gt 0 ]]; do
 		KPATCH_CROSS_COMPILE="$2"
 		shift
 		;;
+	--distro)
+		DISTRO="$2"
+		shift
+		;;
 	--skip-cleanup)
 		echo "Skipping cleanup"
 		SKIPCLEANUP=1
@@ -613,7 +613,7 @@ fi
 # Don't check external file.
 # shellcheck disable=SC1090
 [[ -f "$RELEASE_FILE" ]] && source "$RELEASE_FILE"
-DISTRO="$ID"
+DISTRO="${DISTRO:-${ID}}"
 if [[ "$DISTRO" = fedora ]] || [[ "$DISTRO" = rhel ]] || [[ "$DISTRO" = ol ]] || [[ "$DISTRO" = centos ]]; then
 	[[ -z "$VMLINUX" ]] && VMLINUX="/usr/lib/debug/lib/modules/$ARCHVERSION/vmlinux"
 	[[ -e "$VMLINUX" ]] || die "kernel-debuginfo-$ARCHVERSION not installed"
-- 
2.7.4

