You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by th...@apache.org on 2014/10/31 17:56:23 UTC
svn commit: r1635812 - in /lucene/dev/trunk/solr/bin: solr solr.cmd
Author: thelabdude
Date: Fri Oct 31 16:56:22 2014
New Revision: 1635812
URL: http://svn.apache.org/r1635812
Log:
SOLR-6662: better validation when parsing command-line options that expect a value
Modified:
lucene/dev/trunk/solr/bin/solr
lucene/dev/trunk/solr/bin/solr.cmd
Modified: lucene/dev/trunk/solr/bin/solr
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/bin/solr?rev=1635812&r1=1635811&r2=1635812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/bin/solr (original)
+++ lucene/dev/trunk/solr/bin/solr Fri Oct 31 16:56:22 2014
@@ -342,7 +342,7 @@ function stop_solr() {
DIR="$1"
SOLR_PORT="$2"
- STOP_PORT="79${SOLR_PORT: -2}"
+ STOP_PORT=`expr $SOLR_PORT - 1000`
STOP_KEY="$3"
SOLR_PID="$4"
@@ -408,7 +408,7 @@ if [ "$SCRIPT_CMD" == "healthcheck" ]; t
while true; do
case $1 in
-c|-collection)
- if [ "${2:0:1}" == "-" ]; then
+ if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Expected collection name but found $2 instead!"
exit 1
fi
@@ -416,7 +416,7 @@ if [ "$SCRIPT_CMD" == "healthcheck" ]; t
shift 2
;;
-z|-zkhost)
- if [ "${2:0:1}" == "-" ]; then
+ if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Expected a ZooKeeper connection string but found $2 instead!"
exit 1
fi
@@ -472,7 +472,7 @@ if [[ "$SCRIPT_CMD" == "create_core" ||
while true; do
case $1 in
-n|-name)
- if [ "${2:0:1}" == "-" ]; then
+ if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Expected $CREATE_TYPE name but found $2 instead!"
exit 1
fi
@@ -480,7 +480,7 @@ if [[ "$SCRIPT_CMD" == "create_core" ||
shift 2
;;
-c|-configset)
- if [ "${2:0:1}" == "-" ]; then
+ if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Expected configset name but found $2 instead!"
exit 1
fi
@@ -488,7 +488,7 @@ if [[ "$SCRIPT_CMD" == "create_core" ||
shift 2
;;
-shards)
- if [ "${2:0:1}" == "-" ]; then
+ if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Expected shard count but found $2 instead!"
exit 1
fi
@@ -496,7 +496,7 @@ if [[ "$SCRIPT_CMD" == "create_core" ||
shift 2
;;
-replicationFactor)
- if [ "${2:0:1}" == "-" ]; then
+ if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Expected replication factor but found $2 instead!"
exit 1
fi
@@ -549,7 +549,6 @@ if [[ "$SCRIPT_CMD" == "create_core" ||
STATUS_INFO=`run_tool status -solr http://localhost:$CREATE_PORT/solr | tr -d ' '`
IS_CLOUD=`echo $STATUS_INFO | grep $'"cloud":' | tr -d ' '`
- echo $IS_CLOUD
if [ "$IS_CLOUD" != "" ]; then
if [ "$SCRIPT_CMD" == "create_core" ]; then
echo -e "\nERROR: Solr running on port $CREATE_PORT is running in SolrCloud mode, please use create_collection command instead.\n"
@@ -593,7 +592,7 @@ if [ $# -gt 0 ]; then
shift
;;
-d|-dir)
- if [ "${2:0:1}" == "-" ]; then
+ if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Expected directory but found $2 instead!"
exit 1
fi
@@ -607,7 +606,7 @@ if [ $# -gt 0 ]; then
shift 2
;;
-s|-solr.home)
- if [ "${2:0:1}" == "-" ]; then
+ if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Expected directory but found $2 instead!"
exit 1
fi
@@ -616,7 +615,7 @@ if [ $# -gt 0 ]; then
shift 2
;;
-e|-example)
- if [ "${2:0:1}" == "-" ]; then
+ if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Expected example name but found $2 instead!"
exit 1
fi
@@ -628,7 +627,7 @@ if [ $# -gt 0 ]; then
shift
;;
-h|-host)
- if [ "${2:0:1}" == "-" ]; then
+ if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Expected hostname but found $2 instead!"
exit 1
fi
@@ -636,7 +635,7 @@ if [ $# -gt 0 ]; then
shift 2
;;
-m|-memory)
- if [ "${2:0:1}" == "-" ]; then
+ if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Expected memory setting but found $2 instead!"
exit 1
fi
@@ -644,7 +643,7 @@ if [ $# -gt 0 ]; then
shift 2
;;
-p|-port)
- if [ "${2:0:1}" == "-" ]; then
+ if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Expected port number but found $2 instead!"
exit 1
fi
@@ -652,7 +651,7 @@ if [ $# -gt 0 ]; then
shift 2
;;
-z|-zkhost)
- if [ "${2:0:1}" == "-" ]; then
+ if [[ "$2" == "" || "${2:0:1}" == "-" ]]; then
print_usage "$SCRIPT_CMD" "Expected ZooKeeper connection string but found $2 instead!"
exit 1
fi
@@ -853,7 +852,7 @@ if [ "$SOLR_PORT" == "" ]; then
fi
if [ "$STOP_PORT" == "" ]; then
- STOP_PORT="79${SOLR_PORT: -2}"
+ STOP_PORT=`expr $SOLR_PORT - 1000`
fi
if [[ "$SCRIPT_CMD" == "start" ]]; then
@@ -985,7 +984,7 @@ fi
function launch_solr() {
run_in_foreground="$1"
- stop_port="79${SOLR_PORT: -2}"
+ stop_port="$STOP_PORT"
SOLR_ADDL_ARGS="$2"
@@ -1088,7 +1087,7 @@ if [ "$EXAMPLE" != "cloud" ]; then
"$JAVA" -Durl=http://localhost:$SOLR_PORT/solr/$EXAMPLE/update -jar $SOLR_TIP/example/exampledocs/post.jar $SOLR_TIP/example/exampledocs/*.xml
fi
- echo -e "\nSolr $EXAMPLE launched successfully. Direct your Web browser to http://localhost:$SOLR_PORT/solr to visit the Solr Admin UI\n"
+ echo -e "\nSolr $EXAMPLE example launched successfully. Direct your Web browser to http://localhost:$SOLR_PORT/solr to visit the Solr Admin UI\n"
fi
else
#
Modified: lucene/dev/trunk/solr/bin/solr.cmd
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/bin/solr.cmd?rev=1635812&r1=1635811&r2=1635812&view=diff
==============================================================================
--- lucene/dev/trunk/solr/bin/solr.cmd (original)
+++ lucene/dev/trunk/solr/bin/solr.cmd Fri Oct 31 16:56:22 2014
@@ -278,6 +278,10 @@ goto parse_args
:set_server_dir
set "arg=%~2"
+IF "%arg%"=="" (
+ set SCRIPT_ERROR=Directory name is required!
+ goto invalid_cmd_line
+)
set firstChar=%arg:~0,1%
IF "%firstChar%"=="-" (
set SCRIPT_ERROR=Expected directory but found %2 instead!
@@ -297,6 +301,11 @@ goto parse_args
:set_solr_home_dir
set "arg=%~2"
+IF "%arg%"=="" (
+ set SCRIPT_ERROR=Directory name is required!
+ goto invalid_cmd_line
+)
+
set firstChar=%arg:~0,1%
IF "%firstChar%"=="-" (
set SCRIPT_ERROR=Expected directory but found %2 instead!
@@ -310,6 +319,11 @@ goto parse_args
:set_example
set "arg=%~2"
+IF "%arg%"=="" (
+ set SCRIPT_ERROR=Example name is required!
+ goto invalid_cmd_line
+)
+
set firstChar=%arg:~0,1%
IF "%firstChar%"=="-" (
set SCRIPT_ERROR=Expected example name but found %2 instead!
@@ -324,6 +338,11 @@ goto parse_args
:set_memory
set "arg=%~2"
+IF "%arg%"=="" (
+ set SCRIPT_ERROR=Memory setting is required!
+ goto invalid_cmd_line
+)
+
set firstChar=%arg:~0,1%
IF "%firstChar%"=="-" (
set SCRIPT_ERROR=Expected memory setting but found %2 instead!
@@ -337,6 +356,11 @@ goto parse_args
:set_host
set "arg=%~2"
+IF "%arg%"=="" (
+ set SCRIPT_ERROR=Hostname is required!
+ goto invalid_cmd_line
+)
+
set firstChar=%arg:~0,1%
IF "%firstChar%"=="-" (
set SCRIPT_ERROR=Expected hostname but found %2 instead!
@@ -350,6 +374,11 @@ goto parse_args
:set_port
set "arg=%~2"
+IF "%arg%"=="" (
+ set SCRIPT_ERROR=Port is required!
+ goto invalid_cmd_line
+)
+
set firstChar=%arg:~0,1%
IF "%firstChar%"=="-" (
set SCRIPT_ERROR=Expected port but found %2 instead!
@@ -363,9 +392,14 @@ goto parse_args
:set_stop_key
set "arg=%~2"
+IF "%arg%"=="" (
+ set SCRIPT_ERROR=Stop key is required!
+ goto invalid_cmd_line
+)
+
set firstChar=%arg:~0,1%
IF "%firstChar%"=="-" (
- set SCRIPT_ERROR=Expected port but found %2 instead!
+ set SCRIPT_ERROR=Expected stop key but found %2 instead!
goto invalid_cmd_line
)
set STOP_KEY=%~2
@@ -381,6 +415,11 @@ goto parse_args
:set_zookeeper
set "arg=%~2"
+IF "%arg%"=="" (
+ set SCRIPT_ERROR=ZooKeeper connection string is required!
+ goto invalid_cmd_line
+)
+
set firstChar=%arg:~0,1%
IF "%firstChar%"=="-" (
set SCRIPT_ERROR=Expected ZooKeeper connection string but found %2 instead!
@@ -638,7 +677,9 @@ IF "%EXAMPLE%"=="techproducts" (
)
@echo.
-@echo Solr %EXAMPLE% launched successfully.
+IF NOT "%EXAMPLE%"=="" (
+ @echo Solr %EXAMPLE% example launched successfully.
+)
@echo Direct your Web browser to http://localhost:%SOLR_PORT%/solr to visit the Solr Admin UI
@echo.