Skip to content

Commit

Permalink
kpatch-build: simplify distro support and add Anolis
Browse files Browse the repository at this point in the history
Rather than adding yet another set of conditionals to handle the Anolis
OS distribution, refactor the SUPPORTED_DISTROS code using an
associative array.  The array is keyed by the short distro name, and
contains the longer distribution description.

Signed-off-by: Wardenjohn<[email protected]>
  • Loading branch information
Wardenjohn authored and zhangyongde.zyd committed Jan 8, 2024
1 parent 8513926 commit 05b33d6
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions kpatch-build/kpatch-build
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ LLD="${CROSS_COMPILE:-}ld.lld"
READELF="${CROSS_COMPILE:-}readelf"
OBJCOPY="${CROSS_COMPILE:-}objcopy"

declare -rA SUPPORTED_DISTROS=(
["anolis"]="Anolis OS"
["centos"]="CentOS"
["debian"]="Debian OS"
["fedora"]="Fedora"
["openEuler"]="OpenEuler"
["photon"]="Photon OS"
["rhel"]="RHEL"
["ubuntu"]="Ubuntu OS")

warn() {
echo "ERROR: $1" >&2
}
Expand Down Expand Up @@ -649,6 +659,14 @@ module_name_string() {
echo "${1//[^a-zA-Z0-9_-]/-}" | cut -c 1-55
}

is_supported_distro(){
[[ -v "SUPPORTED_DISTROS[$1]" ]]
}

print_supported_distro(){
echo "${SUPPORTED_DISTROS[$DISTRO]} distribution detected"
}

usage() {
echo "usage: $(basename "$0") [options] <patch1 ... patchN>" >&2
echo " patchN Input patchfile(s)" >&2
Expand Down Expand Up @@ -865,26 +883,23 @@ fi

[[ -z "$TARGETS" ]] && TARGETS="vmlinux modules"

if [[ "$DISTRO" = fedora ]] || [[ "$DISTRO" = rhel ]] || [[ "$DISTRO" = ol ]] ||
[[ "$DISTRO" = centos ]] || [[ "$DISTRO" = openEuler ]] ||
[[ "$DISTRO" = photon ]]; then

[[ -z "$VMLINUX" ]] && VMLINUX="/usr/lib/debug/lib/modules/$ARCHVERSION/vmlinux"
[[ -e "$VMLINUX" ]] || die "kernel-debuginfo-$ARCHVERSION not installed"
if is_supported_distro "$DISTRO"; then

export PATH="/usr/lib64/ccache:$PATH"
if [[ "$DISTRO" = ubuntu ]] || [[ "$DISTRO" = debian ]]; then
[[ -z "$VMLINUX" ]] && VMLINUX="/usr/lib/debug/boot/vmlinux-$ARCHVERSION"

elif [[ "$DISTRO" = ubuntu ]] || [[ "$DISTRO" = debian ]]; then
[[ -z "$VMLINUX" ]] && VMLINUX="/usr/lib/debug/boot/vmlinux-$ARCHVERSION"
if [[ "$DISTRO" = ubuntu ]]; then
[[ -e "$VMLINUX" ]] || die "linux-image-$ARCHVERSION-dbgsym not installed"

if [[ "$DISTRO" = ubuntu ]]; then
[[ -e "$VMLINUX" ]] || die "linux-image-$ARCHVERSION-dbgsym not installed"
elif [[ "$DISTRO" = debian ]]; then
[[ -e "$VMLINUX" ]] || die "linux-image-$ARCHVERSION-dbg not installed"
fi
else
[[ -z "$VMLINUX" ]] && VMLINUX="/usr/lib/debug/lib/modules/$ARCHVERSION/vmlinux"
[[ -e "$VMLINUX" ]] || die "kernel-debuginfo-$ARCHVERSION not installed"

elif [[ "$DISTRO" = debian ]]; then
[[ -e "$VMLINUX" ]] || die "linux-image-$ARCHVERSION-dbg not installed"
export PATH="/usr/lib64/ccache:$PATH"
fi

export PATH="/usr/lib/ccache:$PATH"
fi
save_env

Expand All @@ -906,14 +921,9 @@ elif [[ -e "$KERNEL_SRCDIR"/.config ]] && [[ -e "$VERSIONFILE" ]] && [[ "$(cat "
echo "Using cache at $KERNEL_SRCDIR"

else
if [[ "$DISTRO" = fedora ]] || [[ "$DISTRO" = rhel ]] || [[ "$DISTRO" = ol ]] || [[ "$DISTRO" = centos ]] || [[ "$DISTRO" = openEuler ]] || [[ "$DISTRO" = photon ]]; then

[[ "$DISTRO" = fedora ]] && echo "Fedora distribution detected"
[[ "$DISTRO" = rhel ]] && echo "RHEL distribution detected"
[[ "$DISTRO" = ol ]] && echo "Oracle Linux distribution detected"
[[ "$DISTRO" = centos ]] && echo "CentOS distribution detected"
[[ "$DISTRO" = openEuler ]] && echo "OpenEuler distribution detected"
[[ "$DISTRO" = photon ]] && echo "Photon OS distribution detected"
if is_supported_distro "$DISTRO"; then

print_supported_distro "$DISTRO"

clean_cache

Expand Down

0 comments on commit 05b33d6

Please sign in to comment.