-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add online plugin repository and a 'plugin' command to download them, c…
…loses #157
- Loading branch information
Showing
5 changed files
with
519 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/sh | ||
|
||
SCRIPT="$0" | ||
|
||
# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path. | ||
while [ -h "$SCRIPT" ] ; do | ||
ls=`ls -ld "$SCRIPT"` | ||
# Drop everything prior to -> | ||
link=`expr "$ls" : '.*-> \(.*\)$'` | ||
if expr "$link" : '/.*' > /dev/null; then | ||
SCRIPT="$link" | ||
else | ||
SCRIPT=`dirname "$SCRIPT"`/"$link" | ||
fi | ||
done | ||
|
||
# determine elasticsearch home | ||
ES_HOME=`dirname "$SCRIPT"`/.. | ||
|
||
# make ELASTICSEARCH_HOME absolute | ||
ES_HOME=`cd $ES_HOME; pwd` | ||
|
||
|
||
if [ -x $JAVA_HOME/bin/java ]; then | ||
JAVA=$JAVA_HOME/bin/java | ||
else | ||
JAVA=`which java` | ||
fi | ||
|
||
CLASSPATH=$CLASSPATH:$ES_HOME/lib/* | ||
|
||
$JAVA -Delasticsearch -Des.path.home=$ES_HOME -cp $CLASSPATH org.elasticsearch.plugins.PluginManager $* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
@echo off | ||
|
||
SETLOCAL | ||
|
||
if NOT DEFINED JAVA_HOME goto err | ||
|
||
set SCRIPT_DIR=%~dp0 | ||
for %%I in ("%SCRIPT_DIR%..") do set ES_HOME=%%~dpfI | ||
|
||
|
||
set ES_CLASSPATH=$CLASSPATH;"%ES_HOME%/lib/*" | ||
set ES_PARAMS=-Delasticsearch -Des.path.home="%ES_HOME%" | ||
|
||
"%JAVA_HOME%\bin\java" %JAVA_OPTS% %ES_JAVA_OPTS% %ES_PARAMS% -cp "%ES_CLASSPATH%" "org.elasticsearch.plugins.PluginManager" %* | ||
goto finally | ||
|
||
|
||
:err | ||
echo JAVA_HOME environment variable must be set! | ||
pause | ||
|
||
|
||
:finally | ||
|
||
ENDLOCAL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
modules/elasticsearch/src/main/java/org/elasticsearch/plugins/PluginManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.elasticsearch.plugins; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.env.Environment; | ||
import org.elasticsearch.node.internal.InternalSettingsPerparer; | ||
import org.elasticsearch.util.Tuple; | ||
import org.elasticsearch.util.http.HttpDownloadHelper; | ||
import org.elasticsearch.util.settings.Settings; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
|
||
import static org.elasticsearch.util.settings.ImmutableSettings.Builder.*; | ||
|
||
/** | ||
* @author kimchy (shay.banon) | ||
*/ | ||
public class PluginManager { | ||
|
||
private final Environment environment; | ||
|
||
private final String url; | ||
|
||
public PluginManager(Environment environment, String url) { | ||
this.environment = environment; | ||
this.url = url; | ||
} | ||
|
||
public void downloadPlugin(String name) throws IOException { | ||
HttpDownloadHelper downloadHelper = new HttpDownloadHelper(); | ||
|
||
URL pluginUrl = new URL(url + "/" + name + "/elasticsearch-" + name + "-" + Version.number() + ".zip"); | ||
downloadHelper.download(pluginUrl, new File(environment.pluginsFile(), name + ".zip"), new HttpDownloadHelper.VerboseProgress(System.out)); | ||
} | ||
|
||
public static void main(String[] args) { | ||
Tuple<Settings, Environment> initialSettings = InternalSettingsPerparer.prepareSettings(EMPTY_SETTINGS, true); | ||
|
||
if (!initialSettings.v2().pluginsFile().exists()) { | ||
initialSettings.v2().pluginsFile().mkdirs(); | ||
} | ||
|
||
PluginManager pluginManager = new PluginManager(initialSettings.v2(), "http://elasticsearch.googlecode.com/svn/plugins"); | ||
|
||
if (args.length < 1) { | ||
System.out.println("Usage:"); | ||
System.out.println(" - get [list of plugin names]: Downloads all the listed plugins"); | ||
} | ||
String command = args[0]; | ||
if (command.equals("get") || command.equals("-get") || command.equals("-g") || command.equals("--get")) { | ||
if (args.length < 2) { | ||
System.out.println("'get' requires an additional parameter with the plugin name"); | ||
} | ||
for (int i = 1; i < args.length; i++) { | ||
String pluginName = args[i]; | ||
System.out.print("-> Downloading " + pluginName + " "); | ||
try { | ||
pluginManager.downloadPlugin(pluginName); | ||
System.out.println(" DONE"); | ||
} catch (IOException e) { | ||
System.out.println("Failed to download " + pluginName + ", reason: " + e.getMessage()); | ||
} | ||
} | ||
} else { | ||
System.out.println("No command matching '" + command + "' found"); | ||
} | ||
} | ||
} |
Oops, something went wrong.