From e73a410139e0b212c7c63ec1e2fc4cc14cc5902c Mon Sep 17 00:00:00 2001 From: Owais Kazi Date: Mon, 16 May 2022 11:05:13 -0700 Subject: [PATCH] Used set to make shell scripts more strict (#3278) * Use set to make shell scripts more strict Signed-off-by: Owais Kazi * Change -o pipefail to -e Signed-off-by: Owais Kazi * Set scripts to standard rule Signed-off-by: Owais Kazi --- client/sniffer/src/test/resources/create_test_nodes_info.bash | 2 +- dev-tools/atomic_push.sh | 2 +- dev-tools/signoff-check.sh | 4 +++- distribution/docker/docker-test-entrypoint.sh | 2 ++ distribution/docker/src/docker/bin/docker-entrypoint.sh | 2 +- distribution/packages/src/common/scripts/preinst | 2 ++ distribution/packages/src/common/systemd/systemd-entrypoint | 2 ++ distribution/packages/src/deb/init.d/opensearch | 2 ++ distribution/packages/src/rpm/init.d/opensearch | 2 ++ distribution/src/bin/opensearch | 2 ++ distribution/src/bin/opensearch-keystore | 2 ++ distribution/src/bin/opensearch-node | 1 + distribution/src/bin/opensearch-plugin | 2 ++ distribution/src/bin/opensearch-shard | 2 ++ distribution/src/bin/opensearch-upgrade | 1 + qa/remote-clusters/docker-test-entrypoint.sh | 2 ++ .../krb5kdc-fixture/src/main/resources/provision/addprinc.sh | 2 +- .../krb5kdc-fixture/src/main/resources/provision/hdfs.sh | 2 +- .../src/main/resources/provision/installkdc.sh | 2 +- .../krb5kdc-fixture/src/main/resources/provision/peppa.sh | 2 +- 20 files changed, 32 insertions(+), 8 deletions(-) diff --git a/client/sniffer/src/test/resources/create_test_nodes_info.bash b/client/sniffer/src/test/resources/create_test_nodes_info.bash index e5925b19505..06350be4ba2 100644 --- a/client/sniffer/src/test/resources/create_test_nodes_info.bash +++ b/client/sniffer/src/test/resources/create_test_nodes_info.bash @@ -14,7 +14,7 @@ # when we do rebuild the files they don't jump around too much. That # way the diffs are smaller. -set -e +set -e -o pipefail script_path="$( cd "$(dirname "$0")" ; pwd -P )" work=$(mktemp -d) diff --git a/dev-tools/atomic_push.sh b/dev-tools/atomic_push.sh index d1b735f1537..533fc5f6ed0 100755 --- a/dev-tools/atomic_push.sh +++ b/dev-tools/atomic_push.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -e +set -e -o pipefail if [ "$#" -eq 0 ]; then printf 'Usage: %s ...\n' "$(basename "$0")" diff --git a/dev-tools/signoff-check.sh b/dev-tools/signoff-check.sh index 5fe00c430ca..539301a1cd7 100755 --- a/dev-tools/signoff-check.sh +++ b/dev-tools/signoff-check.sh @@ -1,4 +1,6 @@ -#!/bin/sh +#!/usr/bin/env bash + +set -e -o pipefail ### Script to check for signoff presents on commits diff --git a/distribution/docker/docker-test-entrypoint.sh b/distribution/docker/docker-test-entrypoint.sh index 85a90df003a..1cfc62f6b02 100755 --- a/distribution/docker/docker-test-entrypoint.sh +++ b/distribution/docker/docker-test-entrypoint.sh @@ -1,4 +1,6 @@ #!/usr/bin/env bash +set -e -o pipefail + cd /usr/share/opensearch/bin/ /usr/local/bin/docker-entrypoint.sh | tee > /usr/share/opensearch/logs/console.log diff --git a/distribution/docker/src/docker/bin/docker-entrypoint.sh b/distribution/docker/src/docker/bin/docker-entrypoint.sh index 0d6ca588d87..33c68afce0b 100644 --- a/distribution/docker/src/docker/bin/docker-entrypoint.sh +++ b/distribution/docker/src/docker/bin/docker-entrypoint.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -e +set -e -o pipefail # Files created by Elasticsearch should always be group writable too umask 0002 diff --git a/distribution/packages/src/common/scripts/preinst b/distribution/packages/src/common/scripts/preinst index c13f0796664..31e5b803b16 100644 --- a/distribution/packages/src/common/scripts/preinst +++ b/distribution/packages/src/common/scripts/preinst @@ -10,6 +10,8 @@ # $1=1 : indicates an new install # $1=2 : indicates an upgrade +set -e -o pipefail + err_exit() { echo "$@" >&2 exit 1 diff --git a/distribution/packages/src/common/systemd/systemd-entrypoint b/distribution/packages/src/common/systemd/systemd-entrypoint index 0773bc6f1dc..d9eacdb7812 100644 --- a/distribution/packages/src/common/systemd/systemd-entrypoint +++ b/distribution/packages/src/common/systemd/systemd-entrypoint @@ -3,6 +3,8 @@ # This wrapper script allows SystemD to feed a file containing a passphrase into # the main OpenSearch startup script +set -e -o pipefail + if [ -n "$OPENSEARCH_KEYSTORE_PASSPHRASE_FILE" ] ; then exec /usr/share/opensearch/bin/opensearch "$@" < "$OPENSEARCH_KEYSTORE_PASSPHRASE_FILE" else diff --git a/distribution/packages/src/deb/init.d/opensearch b/distribution/packages/src/deb/init.d/opensearch index e5195d2d54d..681d87df1d3 100755 --- a/distribution/packages/src/deb/init.d/opensearch +++ b/distribution/packages/src/deb/init.d/opensearch @@ -12,6 +12,8 @@ # Description: Starts opensearch using start-stop-daemon ### END INIT INFO +set -e -o pipefail + PATH=/bin:/usr/bin:/sbin:/usr/sbin NAME=opensearch DESC="OpenSearch Server" diff --git a/distribution/packages/src/rpm/init.d/opensearch b/distribution/packages/src/rpm/init.d/opensearch index 12a1470e75a..0cb9bf65796 100644 --- a/distribution/packages/src/rpm/init.d/opensearch +++ b/distribution/packages/src/rpm/init.d/opensearch @@ -16,6 +16,8 @@ # Description: OpenSearch is a very scalable, schema-free and high-performance search solution supporting multi-tenancy and near realtime search. ### END INIT INFO +set -e -o pipefail + # # init.d / servicectl compatibility (openSUSE) # diff --git a/distribution/src/bin/opensearch b/distribution/src/bin/opensearch index 52087ceb8bc..947d1167f79 100755 --- a/distribution/src/bin/opensearch +++ b/distribution/src/bin/opensearch @@ -13,6 +13,8 @@ # # OPENSEARCH_JAVA_OPTS="-Xms8g -Xmx8g" ./bin/opensearch +set -e -o pipefail + source "`dirname "$0"`"/opensearch-env CHECK_KEYSTORE=true diff --git a/distribution/src/bin/opensearch-keystore b/distribution/src/bin/opensearch-keystore index 794d3eb5eba..9f6cb65feee 100755 --- a/distribution/src/bin/opensearch-keystore +++ b/distribution/src/bin/opensearch-keystore @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -e -o pipefail + OPENSEARCH_MAIN_CLASS=org.opensearch.common.settings.KeyStoreCli \ OPENSEARCH_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/keystore-cli \ "`dirname "$0"`"/opensearch-cli \ diff --git a/distribution/src/bin/opensearch-node b/distribution/src/bin/opensearch-node index 210037e933b..b8b231cc43d 100755 --- a/distribution/src/bin/opensearch-node +++ b/distribution/src/bin/opensearch-node @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e -o pipefail OPENSEARCH_MAIN_CLASS=org.opensearch.cluster.coordination.NodeToolCli \ "`dirname "$0"`"/opensearch-cli \ diff --git a/distribution/src/bin/opensearch-plugin b/distribution/src/bin/opensearch-plugin index 64d14e611fd..b58a2695d2e 100755 --- a/distribution/src/bin/opensearch-plugin +++ b/distribution/src/bin/opensearch-plugin @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -e -o pipefail + OPENSEARCH_MAIN_CLASS=org.opensearch.plugins.PluginCli \ OPENSEARCH_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/plugin-cli \ "`dirname "$0"`"/opensearch-cli \ diff --git a/distribution/src/bin/opensearch-shard b/distribution/src/bin/opensearch-shard index 59511ee6864..953c792af16 100755 --- a/distribution/src/bin/opensearch-shard +++ b/distribution/src/bin/opensearch-shard @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -e -o pipefail + OPENSEARCH_MAIN_CLASS=org.opensearch.index.shard.ShardToolCli \ "`dirname "$0"`"/opensearch-cli \ "$@" diff --git a/distribution/src/bin/opensearch-upgrade b/distribution/src/bin/opensearch-upgrade index 4305fae4627..5aae184341b 100755 --- a/distribution/src/bin/opensearch-upgrade +++ b/distribution/src/bin/opensearch-upgrade @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e -o pipefail OPENSEARCH_MAIN_CLASS=org.opensearch.upgrade.UpgradeCli \ OPENSEARCH_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/upgrade-cli \ diff --git a/qa/remote-clusters/docker-test-entrypoint.sh b/qa/remote-clusters/docker-test-entrypoint.sh index e08e388b8c9..18a9363d375 100755 --- a/qa/remote-clusters/docker-test-entrypoint.sh +++ b/qa/remote-clusters/docker-test-entrypoint.sh @@ -1,4 +1,6 @@ #!/usr/bin/env bash +set -e -o pipefail + cd /usr/share/opensearch/bin/ ./opensearch-users useradd rest_user -p test-password -r superuser || true echo "testnode" > /tmp/password diff --git a/test/fixtures/krb5kdc-fixture/src/main/resources/provision/addprinc.sh b/test/fixtures/krb5kdc-fixture/src/main/resources/provision/addprinc.sh index 201c437f00b..2e3bf66d140 100755 --- a/test/fixtures/krb5kdc-fixture/src/main/resources/provision/addprinc.sh +++ b/test/fixtures/krb5kdc-fixture/src/main/resources/provision/addprinc.sh @@ -17,7 +17,7 @@ # specific language governing permissions and limitations # under the License. -set -e +set -e -o pipefail krb5kdc kadmind diff --git a/test/fixtures/krb5kdc-fixture/src/main/resources/provision/hdfs.sh b/test/fixtures/krb5kdc-fixture/src/main/resources/provision/hdfs.sh index 413c1ee29d0..81bc99a0583 100644 --- a/test/fixtures/krb5kdc-fixture/src/main/resources/provision/hdfs.sh +++ b/test/fixtures/krb5kdc-fixture/src/main/resources/provision/hdfs.sh @@ -10,7 +10,7 @@ # GitHub history for details. # -set -e +set -e -o pipefail addprinc.sh "opensearch" #TODO(OpenSearch): fix username diff --git a/test/fixtures/krb5kdc-fixture/src/main/resources/provision/installkdc.sh b/test/fixtures/krb5kdc-fixture/src/main/resources/provision/installkdc.sh index aec2d46073c..111e8dcc5ea 100755 --- a/test/fixtures/krb5kdc-fixture/src/main/resources/provision/installkdc.sh +++ b/test/fixtures/krb5kdc-fixture/src/main/resources/provision/installkdc.sh @@ -29,7 +29,7 @@ # GitHub history for details. # -set -e +set -e -o pipefail # KDC installation steps and considerations based on https://web.mit.edu/kerberos/krb5-latest/doc/admin/install_kdc.html # and helpful input from https://help.ubuntu.com/community/Kerberos diff --git a/test/fixtures/krb5kdc-fixture/src/main/resources/provision/peppa.sh b/test/fixtures/krb5kdc-fixture/src/main/resources/provision/peppa.sh index f70ad575d65..422739d9df9 100644 --- a/test/fixtures/krb5kdc-fixture/src/main/resources/provision/peppa.sh +++ b/test/fixtures/krb5kdc-fixture/src/main/resources/provision/peppa.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -e +set -e -o pipefail addprinc.sh opensearch addprinc.sh HTTP/localhost