Skip to content

Commit 3ce2297

Browse files
authored
Reduce CLI scripts to one-liners (#30759)
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.
1 parent dcf0f9f commit 3ce2297

14 files changed

+42
-130
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
set -e -o pipefail
4+
5+
source "`dirname "$0"`"/elasticsearch-env
6+
7+
IFS=';' read -r -a additional_sources <<< "$ES_ADDITIONAL_SOURCES"
8+
for additional_source in "${additional_sources[@]}"
9+
do
10+
source "`dirname "$0"`"/$additional_source
11+
done
12+
13+
exec \
14+
"$JAVA" \
15+
$ES_JAVA_OPTS \
16+
-Des.path.home="$ES_HOME" \
17+
-Des.path.conf="$ES_PATH_CONF" \
18+
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
19+
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
20+
-cp "$ES_CLASSPATH" \
21+
$1 \
22+
"${@:2}"
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
#!/bin/bash
22

3-
source "`dirname "$0"`"/elasticsearch-env
4-
5-
exec \
6-
"$JAVA" \
7-
$ES_JAVA_OPTS \
8-
-Des.path.home="$ES_HOME" \
9-
-Des.path.conf="$ES_PATH_CONF" \
10-
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
11-
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
12-
-cp "$ES_CLASSPATH" \
3+
"`dirname "$0"`"/elasticsearch-cli \
134
org.elasticsearch.common.settings.KeyStoreCli \
145
"$@"
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
#!/bin/bash
22

3-
source "`dirname "$0"`"/elasticsearch-env
4-
5-
exec \
6-
"$JAVA" \
7-
$ES_JAVA_OPTS \
8-
-Des.path.home="$ES_HOME" \
9-
-Des.path.conf="$ES_PATH_CONF" \
10-
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
11-
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
12-
-cp "$ES_CLASSPATH" \
3+
"`dirname "$0"`"/elasticsearch-cli \
134
org.elasticsearch.plugins.PluginCli \
145
"$@"
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
#!/bin/bash
22

3-
source "`dirname "$0"`"/elasticsearch-env
4-
5-
exec \
6-
"$JAVA" \
7-
$ES_JAVA_OPTS \
8-
-Des.path.home="$ES_HOME" \
9-
-Des.path.conf="$ES_PATH_CONF" \
10-
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
11-
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
12-
-cp "$ES_CLASSPATH" \
3+
"`dirname "$0"`"/elasticsearch-cli \
134
org.elasticsearch.index.translog.TranslogToolCli \
145
"$@"

x-pack/plugin/security/src/main/bin/elasticsearch-certgen

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,7 @@
44
# or more contributor license agreements. Licensed under the Elastic License;
55
# you may not use this file except in compliance with the Elastic License.
66

7-
source "`dirname "$0"`"/elasticsearch-env
8-
9-
source "`dirname "$0"`"/x-pack-security-env
10-
11-
exec \
12-
"$JAVA" \
13-
$ES_JAVA_OPTS \
14-
-Des.path.home="$ES_HOME" \
15-
-Des.path.conf="$ES_PATH_CONF" \
16-
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
17-
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
18-
-cp "$ES_CLASSPATH" \
7+
ES_ADDITIONAL_SOURCES="x-pack-env;x-pack-security-env" \
8+
"`dirname "$0"`"/elasticsearch-cli \
199
org.elasticsearch.xpack.core.ssl.CertificateGenerateTool \
2010
"$@"

x-pack/plugin/security/src/main/bin/elasticsearch-certutil

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,7 @@
44
# or more contributor license agreements. Licensed under the Elastic License;
55
# you may not use this file except in compliance with the Elastic License.
66

7-
source "`dirname "$0"`"/elasticsearch-env
8-
9-
source "`dirname "$0"`"/x-pack-security-env
10-
11-
exec \
12-
"$JAVA" \
13-
$ES_JAVA_OPTS \
14-
-Des.path.home="$ES_HOME" \
15-
-Des.path.conf="$ES_PATH_CONF" \
16-
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
17-
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
18-
-cp "$ES_CLASSPATH" \
7+
ES_ADDITIONAL_SOURCES="x-pack-env;x-pack-security-env" \
8+
"`dirname "$0"`"/elasticsearch-cli \
199
org.elasticsearch.xpack.core.ssl.CertificateTool \
2010
"$@"

x-pack/plugin/security/src/main/bin/elasticsearch-migrate

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,7 @@
44
# or more contributor license agreements. Licensed under the Elastic License;
55
# you may not use this file except in compliance with the Elastic License.
66

7-
source "`dirname "$0"`"/elasticsearch-env
8-
9-
source "`dirname "$0"`"/x-pack-security-env
10-
11-
exec \
12-
"$JAVA" \
13-
$ES_JAVA_OPTS \
14-
-Des.path.home="$ES_HOME" \
15-
-Des.path.conf="$ES_PATH_CONF" \
16-
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
17-
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
18-
-cp "$ES_CLASSPATH" \
7+
ES_ADDITIONAL_SOURCES="x-pack-env;x-pack-security-env" \
8+
"`dirname "$0"`"/elasticsearch-cli \
199
org.elasticsearch.xpack.security.authc.esnative.ESNativeRealmMigrateTool \
20-
"$@"
10+
"$@"

x-pack/plugin/security/src/main/bin/elasticsearch-saml-metadata

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,7 @@
44
# or more contributor license agreements. Licensed under the Elastic License;
55
# you may not use this file except in compliance with the Elastic License.
66

7-
source "`dirname "$0"`"/elasticsearch-env
8-
9-
source "`dirname "$0"`"/x-pack-security-env
10-
11-
exec \
12-
"$JAVA" \
13-
$ES_JAVA_OPTS \
14-
-Des.path.home="$ES_HOME" \
15-
-Des.path.conf="$ES_PATH_CONF" \
16-
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
17-
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
18-
-cp "$ES_CLASSPATH" \
7+
ES_ADDITIONAL_SOURCES="x-pack-env;x-pack-security-env" \
8+
"`dirname "$0"`"/elasticsearch-cli \
199
org.elasticsearch.xpack.security.authc.saml.SamlMetadataCommand \
2010
"$@"

x-pack/plugin/security/src/main/bin/elasticsearch-setup-passwords

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,7 @@
44
# or more contributor license agreements. Licensed under the Elastic License;
55
# you may not use this file except in compliance with the Elastic License.
66

7-
source "`dirname "$0"`"/elasticsearch-env
8-
9-
source "`dirname "$0"`"/x-pack-security-env
10-
11-
exec \
12-
"$JAVA" \
13-
$ES_JAVA_OPTS \
14-
-Des.path.home="$ES_HOME" \
15-
-Des.path.conf="$ES_PATH_CONF" \
16-
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
17-
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
18-
-cp "$ES_CLASSPATH" \
7+
ES_ADDITIONAL_SOURCES="x-pack-env;x-pack-security-env" \
8+
"`dirname "$0"`"/elasticsearch-cli \
199
org.elasticsearch.xpack.security.authc.esnative.tool.SetupPasswordTool \
2010
"$@"

x-pack/plugin/security/src/main/bin/elasticsearch-syskeygen

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,7 @@
44
# or more contributor license agreements. Licensed under the Elastic License;
55
# you may not use this file except in compliance with the Elastic License.
66

7-
source "`dirname "$0"`"/elasticsearch-env
8-
9-
source "`dirname "$0"`"/x-pack-security-env
10-
11-
exec \
12-
"$JAVA" \
13-
$ES_JAVA_OPTS \
14-
-Des.path.home="$ES_HOME" \
15-
-Des.path.conf="$ES_PATH_CONF" \
16-
-Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
17-
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
18-
-cp "$ES_CLASSPATH" \
7+
ES_ADDITIONAL_SOURCES="x-pack-env;x-pack-security-env" \
8+
"`dirname "$0"`"/elasticsearch-cli \
199
org.elasticsearch.xpack.security.crypto.tool.SystemKeyTool \
2010
"$@"

0 commit comments

Comments
 (0)