Skip to content

Commit

Permalink
Reduce CLI scripts to one-liners (#30759)
Browse files Browse the repository at this point in the history
This commit reduces the Linux CLI scripts to one-liners by moving all of
the redundant logic to an elasticsearch-cli script. This commit is only
the Linux side, a follow-up will do this for Windows too.
  • Loading branch information
jasontedor authored May 21, 2018
1 parent dcf0f9f commit 3ce2297
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 130 deletions.
22 changes: 22 additions & 0 deletions distribution/src/bin/elasticsearch-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -e -o pipefail

source "`dirname "$0"`"/elasticsearch-env

IFS=';' read -r -a additional_sources <<< "$ES_ADDITIONAL_SOURCES"
for additional_source in "${additional_sources[@]}"
do
source "`dirname "$0"`"/$additional_source
done

exec \
"$JAVA" \
$ES_JAVA_OPTS \
-Des.path.home="$ES_HOME" \
-Des.path.conf="$ES_PATH_CONF" \
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
-cp "$ES_CLASSPATH" \
$1 \
"${@:2}"
11 changes: 1 addition & 10 deletions distribution/src/bin/elasticsearch-keystore
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
#!/bin/bash

source "`dirname "$0"`"/elasticsearch-env

exec \
"$JAVA" \
$ES_JAVA_OPTS \
-Des.path.home="$ES_HOME" \
-Des.path.conf="$ES_PATH_CONF" \
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
-cp "$ES_CLASSPATH" \
"`dirname "$0"`"/elasticsearch-cli \
org.elasticsearch.common.settings.KeyStoreCli \
"$@"
11 changes: 1 addition & 10 deletions distribution/src/bin/elasticsearch-plugin
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
#!/bin/bash

source "`dirname "$0"`"/elasticsearch-env

exec \
"$JAVA" \
$ES_JAVA_OPTS \
-Des.path.home="$ES_HOME" \
-Des.path.conf="$ES_PATH_CONF" \
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
-cp "$ES_CLASSPATH" \
"`dirname "$0"`"/elasticsearch-cli \
org.elasticsearch.plugins.PluginCli \
"$@"
11 changes: 1 addition & 10 deletions distribution/src/bin/elasticsearch-translog
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
#!/bin/bash

source "`dirname "$0"`"/elasticsearch-env

exec \
"$JAVA" \
$ES_JAVA_OPTS \
-Des.path.home="$ES_HOME" \
-Des.path.conf="$ES_PATH_CONF" \
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
-cp "$ES_CLASSPATH" \
"`dirname "$0"`"/elasticsearch-cli \
org.elasticsearch.index.translog.TranslogToolCli \
"$@"
14 changes: 2 additions & 12 deletions x-pack/plugin/security/src/main/bin/elasticsearch-certgen
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@
# or more contributor license agreements. Licensed under the Elastic License;
# you may not use this file except in compliance with the Elastic License.

source "`dirname "$0"`"/elasticsearch-env

source "`dirname "$0"`"/x-pack-security-env

exec \
"$JAVA" \
$ES_JAVA_OPTS \
-Des.path.home="$ES_HOME" \
-Des.path.conf="$ES_PATH_CONF" \
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
-cp "$ES_CLASSPATH" \
ES_ADDITIONAL_SOURCES="x-pack-env;x-pack-security-env" \
"`dirname "$0"`"/elasticsearch-cli \
org.elasticsearch.xpack.core.ssl.CertificateGenerateTool \
"$@"
14 changes: 2 additions & 12 deletions x-pack/plugin/security/src/main/bin/elasticsearch-certutil
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@
# or more contributor license agreements. Licensed under the Elastic License;
# you may not use this file except in compliance with the Elastic License.

source "`dirname "$0"`"/elasticsearch-env

source "`dirname "$0"`"/x-pack-security-env

exec \
"$JAVA" \
$ES_JAVA_OPTS \
-Des.path.home="$ES_HOME" \
-Des.path.conf="$ES_PATH_CONF" \
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
-cp "$ES_CLASSPATH" \
ES_ADDITIONAL_SOURCES="x-pack-env;x-pack-security-env" \
"`dirname "$0"`"/elasticsearch-cli \
org.elasticsearch.xpack.core.ssl.CertificateTool \
"$@"
16 changes: 3 additions & 13 deletions x-pack/plugin/security/src/main/bin/elasticsearch-migrate
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@
# or more contributor license agreements. Licensed under the Elastic License;
# you may not use this file except in compliance with the Elastic License.

source "`dirname "$0"`"/elasticsearch-env

source "`dirname "$0"`"/x-pack-security-env

exec \
"$JAVA" \
$ES_JAVA_OPTS \
-Des.path.home="$ES_HOME" \
-Des.path.conf="$ES_PATH_CONF" \
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
-cp "$ES_CLASSPATH" \
ES_ADDITIONAL_SOURCES="x-pack-env;x-pack-security-env" \
"`dirname "$0"`"/elasticsearch-cli \
org.elasticsearch.xpack.security.authc.esnative.ESNativeRealmMigrateTool \
"$@"
"$@"
14 changes: 2 additions & 12 deletions x-pack/plugin/security/src/main/bin/elasticsearch-saml-metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@
# or more contributor license agreements. Licensed under the Elastic License;
# you may not use this file except in compliance with the Elastic License.

source "`dirname "$0"`"/elasticsearch-env

source "`dirname "$0"`"/x-pack-security-env

exec \
"$JAVA" \
$ES_JAVA_OPTS \
-Des.path.home="$ES_HOME" \
-Des.path.conf="$ES_PATH_CONF" \
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
-cp "$ES_CLASSPATH" \
ES_ADDITIONAL_SOURCES="x-pack-env;x-pack-security-env" \
"`dirname "$0"`"/elasticsearch-cli \
org.elasticsearch.xpack.security.authc.saml.SamlMetadataCommand \
"$@"
14 changes: 2 additions & 12 deletions x-pack/plugin/security/src/main/bin/elasticsearch-setup-passwords
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@
# or more contributor license agreements. Licensed under the Elastic License;
# you may not use this file except in compliance with the Elastic License.

source "`dirname "$0"`"/elasticsearch-env

source "`dirname "$0"`"/x-pack-security-env

exec \
"$JAVA" \
$ES_JAVA_OPTS \
-Des.path.home="$ES_HOME" \
-Des.path.conf="$ES_PATH_CONF" \
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
-cp "$ES_CLASSPATH" \
ES_ADDITIONAL_SOURCES="x-pack-env;x-pack-security-env" \
"`dirname "$0"`"/elasticsearch-cli \
org.elasticsearch.xpack.security.authc.esnative.tool.SetupPasswordTool \
"$@"
14 changes: 2 additions & 12 deletions x-pack/plugin/security/src/main/bin/elasticsearch-syskeygen
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@
# or more contributor license agreements. Licensed under the Elastic License;
# you may not use this file except in compliance with the Elastic License.

source "`dirname "$0"`"/elasticsearch-env

source "`dirname "$0"`"/x-pack-security-env

exec \
"$JAVA" \
$ES_JAVA_OPTS \
-Des.path.home="$ES_HOME" \
-Des.path.conf="$ES_PATH_CONF" \
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
-cp "$ES_CLASSPATH" \
ES_ADDITIONAL_SOURCES="x-pack-env;x-pack-security-env" \
"`dirname "$0"`"/elasticsearch-cli \
org.elasticsearch.xpack.security.crypto.tool.SystemKeyTool \
"$@"
14 changes: 2 additions & 12 deletions x-pack/plugin/security/src/main/bin/elasticsearch-users
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@
# or more contributor license agreements. Licensed under the Elastic License;
# you may not use this file except in compliance with the Elastic License.

source "`dirname "$0"`"/elasticsearch-env

source "`dirname "$0"`"/x-pack-security-env

exec \
"$JAVA" \
$ES_JAVA_OPTS \
-Des.path.home="$ES_HOME" \
-Des.path.conf="$ES_PATH_CONF" \
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
-cp "$ES_CLASSPATH" \
ES_ADDITIONAL_SOURCES="x-pack-env;x-pack-security-env" \
"`dirname "$0"`"/elasticsearch-cli \
org.elasticsearch.xpack.security.authc.file.tool.UsersTool \
"$@"
2 changes: 0 additions & 2 deletions x-pack/plugin/security/src/main/bin/x-pack-security-env
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@
# or more contributor license agreements. Licensed under the Elastic License;
# you may not use this file except in compliance with the Elastic License.

source "`dirname "$0"`"/x-pack-env

# include x-pack-security jars in classpath
ES_CLASSPATH="$ES_CLASSPATH:$ES_HOME/modules/x-pack-security/*"
13 changes: 2 additions & 11 deletions x-pack/plugin/watcher/src/main/bin/elasticsearch-croneval
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@
# or more contributor license agreements. Licensed under the Elastic License;
# you may not use this file except in compliance with the Elastic License.

source "`dirname "$0"`"/elasticsearch-env

source "`dirname "$0"`"/x-pack-watcher-env

exec \
"$JAVA" \
$ES_JAVA_OPTS \
-Des.path.home="$ES_HOME" \
-Des.path.conf="$ES_PATH_CONF" \
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
-cp "$ES_CLASSPATH" \
ES_ADDITIONAL_SOURCES="x-pack-env;x-pack-watcher-env" \
"`dirname "$0"`"/elasticsearch-cli \
org.elasticsearch.xpack.watcher.trigger.schedule.tool.CronEvalTool \
"$@"
2 changes: 0 additions & 2 deletions x-pack/plugin/watcher/src/main/bin/x-pack-watcher-env
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@
# or more contributor license agreements. Licensed under the Elastic License;
# you may not use this file except in compliance with the Elastic License.

source "`dirname "$0"`"/x-pack-env

# include x-pack-security jars in classpath
ES_CLASSPATH="$ES_CLASSPATH:$ES_HOME/modules/x-pack-watcher/*"

0 comments on commit 3ce2297

Please sign in to comment.