From 4190647a9fe8e991b3671dbb02d785b6ef3e6cc1 Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Wed, 10 Jan 2024 20:02:49 -0500 Subject: [PATCH] Updates variable names and comparison logic Signed-off-by: Darshit Chanpura --- .../pkg/build_templates/opensearch/deb/debian/preinst | 11 +++++++---- .../opensearch/rpm/opensearch.rpm.spec | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/scripts/pkg/build_templates/opensearch/deb/debian/preinst b/scripts/pkg/build_templates/opensearch/deb/debian/preinst index 49057f5252..4569c62cea 100755 --- a/scripts/pkg/build_templates/opensearch/deb/debian/preinst +++ b/scripts/pkg/build_templates/opensearch/deb/debian/preinst @@ -31,13 +31,16 @@ fi # 2. Currently, the demo config setup is defined to run, in postinst, if `opensearch-security` is present. Cannot apply the same check here since the plugins folder is not available yet. # Check if this is an upgrade by checking whether opensearch already exists -OPENSEARCH_INSTALLED=$(dpkg -l | grep opensearch) +set +e +dpkg -s opensearch +OPENSEARCH_INSTALLED=$? # 0 when installed, 1 when installed +set -e OPENSEARCH_REQUIRED_VERSION="2.12.0" -COMPARE_VERSION=`echo $OPENSEARCH_REQUIRED_VERSION $OPENSEARCH_VERSION | tr ' ' '\n' | sort -V | uniq | head -n 1` +MINIMUM_OF_TWO_VERSIONS=`echo $OPENSEARCH_REQUIRED_VERSION $OPENSEARCH_VERSION | tr ' ' '\n' | sort -V | uniq | head -n 1` -if [ -n "$OPENSEARCH_INSTALLED" ] && [ $OPENSEARCH_VERSION != CHANGE_VERSION ]; then - if [ "$COMPARE_VERSION" == "$OPENSEARCH_REQUIRED_VERSION" ] && [ -z "$OPENSEARCH_INITIAL_ADMIN_PASSWORD" ]; then +if [ $OPENSEARCH_INSTALLED = 1 ] && [ $OPENSEARCH_VERSION != CHANGE_VERSION ]; then + if [ $MINIMUM_OF_TWO_VERSIONS = $OPENSEARCH_REQUIRED_VERSION ] && [ -z "$OPENSEARCH_INITIAL_ADMIN_PASSWORD" ]; then echo "ERROR: Opensearch 2.12 and later requires the env variable OPENSEARCH_INITIAL_ADMIN_PASSWORD to be defined to setup the opensearch-security demo configuration" exit 1 fi diff --git a/scripts/pkg/build_templates/opensearch/rpm/opensearch.rpm.spec b/scripts/pkg/build_templates/opensearch/rpm/opensearch.rpm.spec index 9ff55f2c27..0f400752bf 100644 --- a/scripts/pkg/build_templates/opensearch/rpm/opensearch.rpm.spec +++ b/scripts/pkg/build_templates/opensearch/rpm/opensearch.rpm.spec @@ -96,14 +96,17 @@ fi # 2. Currently, the demo config setup is defined to run, in postinst, if `opensearch-security` is present. Cannot apply the same check here since the plugins folder is not available yet. # Check if this is an upgrade by checking whether opensearch already exists -OPENSEARCH_INSTALLED=$(rpm -qa || yum list installed | grep opensearch) +set +e +rpm -q opensearch || yum list installed opensearch +OPENSEARCH_INSTALLED=$? # 0 when installed, 1 when installed +set -e OPENSEARCH_REQUIRED_VERSION="2.12.0" OPENSEARCH_VERSION=%{_version} -COMPARE_VERSION=`echo $OPENSEARCH_REQUIRED_VERSION $OPENSEARCH_VERSION | tr ' ' '\n' | sort -V | uniq | head -n 1` +MINIMUM_OF_TWO_VERSIONS=`echo $OPENSEARCH_REQUIRED_VERSION $OPENSEARCH_VERSION | tr ' ' '\n' | sort -V | uniq | head -n 1` -if [ -n "$OPENSEARCH_INSTALLED" ] && [ $OPENSEARCH_VERSION != CHANGE_VERSION ]; then - if [ "$COMPARE_VERSION" == "$OPENSEARCH_REQUIRED_VERSION" ] && [ -z "$OPENSEARCH_INITIAL_ADMIN_PASSWORD" ]; then +if [ $OPENSEARCH_INSTALLED = 1 ] && [ $OPENSEARCH_VERSION != CHANGE_VERSION ]; then + if [ $MINIMUM_OF_TWO_VERSIONS = $OPENSEARCH_REQUIRED_VERSION ] && [ -z "$OPENSEARCH_INITIAL_ADMIN_PASSWORD" ]; then echo "ERROR: Opensearch 2.12 and later requires the env variable OPENSEARCH_INITIAL_ADMIN_PASSWORD to be defined to setup the opensearch-security demo configuration" exit 1 fi