From b550647ad25c8c964d74ff4a8d66c2b6fd8237b3 Mon Sep 17 00:00:00 2001 From: jakub-nt <175944085+jakub-nt@users.noreply.github.com> Date: Wed, 8 Oct 2025 16:07:11 +0200 Subject: [PATCH] Added a shell variable for the OS major version Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com> --- build-scripts/compile-options | 5 ++--- build-scripts/configure | 2 +- build-scripts/detect-environment | 14 ++++++++++---- build-scripts/package | 9 +++------ build-scripts/test-on-testmachine | 6 ++---- deps-packaging/git/cfbuild-git.spec | 2 +- deps-packaging/openssl/cfbuild-openssl.spec | 2 +- deps-packaging/openssl/debian/rules | 2 +- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/build-scripts/compile-options b/build-scripts/compile-options index 2dc2ec85c..a7e416308 100644 --- a/build-scripts/compile-options +++ b/build-scripts/compile-options @@ -33,12 +33,11 @@ export PROJECT # Otherwise, we build it. if [ -z "$SYSTEM_SSL" ]; then # We don't bundle OpenSSL on some redhat-derived systems due to incompatability with libpam and our openssl. - _OS_MAJOR_VERSION="$(echo "$OS_VERSION" | cut -d. -f1)" - if [ "$OS" = "rhel" ] && expr "$_OS_MAJOR_VERSION" ">=" "8" >/dev/null; then + if [ "$OS" = "rhel" ] && [ "$OS_VERSION_MAJOR" -ge "8" ]; then SYSTEM_SSL=1 fi if [ "$OS" = "opensuse" ] || [ "$OS" = "sles" ]; then - if expr "$_OS_MAJOR_VERSION" ">=" "15"; then + if [ "$OS_VERSION_MAJOR" -ge "15" ]; then SYSTEM_SSL=1 fi fi diff --git a/build-scripts/configure b/build-scripts/configure index f37ea8e62..c54b7b64f 100755 --- a/build-scripts/configure +++ b/build-scripts/configure @@ -90,7 +90,7 @@ yes) esac # RHEL 8 requires an SELinux policy -if [ "$OS" = "rhel" ] && [ "${OS_VERSION%\.*}" -gt "7" ]; then +if [ "$OS" = "rhel" ] && [ "$OS_VERSION_MAJOR" -ge "8" ]; then var_append ARGS "--with-selinux-policy" fi diff --git a/build-scripts/detect-environment b/build-scripts/detect-environment index 5c6db9d42..81d0831a7 100644 --- a/build-scripts/detect-environment +++ b/build-scripts/detect-environment @@ -39,11 +39,12 @@ detect_cross_target() { } # This function exports operating system specific variables: -# - OS usually contains a specific distribution (e.g. Debian) -# - OS_VERSION operating system version (but is not always defined) +# - OS usually contains a specific distribution (e.g. Debian) +# - OS_VERSION operating system version (but is not always defined) +# - OS_VERSION_MAJOR the major (first part of) operating system version (defined if OS_VERSION is) # # Furthermore, the following variable is set, but it's not exported: -# - OS_FAMILY usually contains the kernel name (e.g. Linux) +# - OS_FAMILY usually contains the kernel name (e.g. Linux) detect_os() { case "$CROSS_TARGET" in '') @@ -106,8 +107,13 @@ detect_os() { ;; esac + # Extract major version from OS_VERSION (e.g. 16.04 -> 16, 7.0 -> 7, 10.2.3 -> 10) + if [ -n "$OS_VERSION" ]; then + OS_VERSION_MAJOR="${OS_VERSION%%.*}" + fi + log_debug "Detected OS $OS $OS_VERSION" - export OS OS_VERSION + export OS OS_VERSION OS_VERSION_MAJOR } # The uname command does not reveal the specific distribution on Linux. Hence, diff --git a/build-scripts/package b/build-scripts/package index 9a269d439..24c30ebbc 100755 --- a/build-scripts/package +++ b/build-scripts/package @@ -305,15 +305,12 @@ deb) log_debug "Development DEB version: $DEB_VERSION" fi - # Extract major version from OS_VERSION (e.g., 16.04 -> 16, 7.0 -> 7) - # This is appended to package name for OS-specific builds - # TODO: Define this in detect-environment script (CFE-4586) - os_version_major="${OS_VERSION%%.*}" - log_debug "OS version major: $os_version_major" + # The OS major version is appended to package name for OS-specific builds + log_debug "OS version major: $OS_VERSION_MAJOR" # Generate debian changelog with version info log_debug "Generating debian changelog" - sed -e "s/@@VERSION@@/$DEB_VERSION$safe_prefix.$OS$os_version_major/" "$BASEDIR/$PKG/pkg/debian/changelog.in" >"$BASEDIR/$PKG/pkg/debian/changelog" + sed -e "s/@@VERSION@@/$DEB_VERSION$safe_prefix.$OS$OS_VERSION_MAJOR/" "$BASEDIR/$PKG/pkg/debian/changelog.in" >"$BASEDIR/$PKG/pkg/debian/changelog" # Generate debian package maintainer scripts log_debug "Generating debian maintainer scripts" diff --git a/build-scripts/test-on-testmachine b/build-scripts/test-on-testmachine index 64d099d83..d6883942b 100755 --- a/build-scripts/test-on-testmachine +++ b/build-scripts/test-on-testmachine @@ -59,13 +59,11 @@ chroot) ubuntu) # gpg-agent sometimes is spawned on Ubuntu 24 during our tests. # This happens only in chroot. Ignore that. - case "$OS_VERSION" in - 24*) + if [ "$OS_VERSION_MAJOR" = "24" ]; then if ps -o command --pid "$pid" | grep "gpg-agent --homedir /etc/apt/sources.list.d/.gnupg-temp --use-standard-socket --daemon"; then continue fi - ;; - esac + fi ;; esac diff --git a/deps-packaging/git/cfbuild-git.spec b/deps-packaging/git/cfbuild-git.spec index 27a2fcdcb..ff8c1956f 100644 --- a/deps-packaging/git/cfbuild-git.spec +++ b/deps-packaging/git/cfbuild-git.spec @@ -24,7 +24,7 @@ mkdir -p %{_builddir} case "$OS" in rhel|centos) - if [ $(echo $OS_VERSION | cut -d. -f1) = 7 ] + if [ "$OS_VERSION_MAJOR" = "7" ] then # Fixes the following compilation error on rhel 7: # 15:05:28 compat/posix.h:159:24: fatal error: sys/random.h: No such file or directory diff --git a/deps-packaging/openssl/cfbuild-openssl.spec b/deps-packaging/openssl/cfbuild-openssl.spec index 91fe2667e..3945af1e5 100644 --- a/deps-packaging/openssl/cfbuild-openssl.spec +++ b/deps-packaging/openssl/cfbuild-openssl.spec @@ -55,7 +55,7 @@ fi HACK_FLAGS= if [ $OS = centos ] || [ $OS = rhel ] then - if [ `echo $OS_VERSION | cut -d. -f1` = 4 ] + if [ "$OS_VERSION_MAJOR" = "4" ] then HACK_FLAGS=-D_GNU_SOURCE # CentOS 4 issue fi diff --git a/deps-packaging/openssl/debian/rules b/deps-packaging/openssl/debian/rules index 592ba8972..245dfd0ae 100755 --- a/deps-packaging/openssl/debian/rules +++ b/deps-packaging/openssl/debian/rules @@ -27,7 +27,7 @@ build-stamp: fi ;\ \ HACK_FLAGS= ;\ - if [ $$OS = debian ] && [ `echo $$OS_VERSION | cut -d. -f1` = 4 ] ;\ + if [ $$OS = debian ] && [ $$OS_VERSION_MAJOR = 4 ] ;\ then \ HACK_FLAGS=-D_GNU_SOURCE ;\ fi ;\