Browse Source

ZOOKEEPER-3766: Clean up bash scripts

ZOOKEEPER-3766: Clean up bash scripts
For ZOOKEEPER-3766:
* Export CLASSPATH in scripts and remove `-cp $CLASSPATH` uses, so that
  java picks up the classpath from the environment, to avoid absurdly
  long command lines in process listings (this should also fix an issue
  with older versions of pgrep/pkill, such as that installed on RHEL8;
  see https://bugzilla.redhat.com/show_bug.cgi?id=1782309 for details)
* Add a new `classpath` command to print the CLASSPATH environment
  variable in the form `CLASSPATH=$CLASSPATH` from the script, so that
  the script's view of the CLASSPATH environment can easily be inspected
  when troubleshooting java processes
Also fix other code quality issues in all bash scripts:
* Add CI checks for shfmt and shellcheck for all bash scripts
* Standardize "shebang" lines
* Standardize license header formatting
* Format using shfmt tool and address all shellcheck problems
* Remove unnecessary quoting and use of curly braces
* Standardize on double square braces to avoid unpredictable use of
  /usr/bin/\[ instead of built-in bash braces
* Remove a useless check of `$?` in bin/zkServer-initialize.sh
* Remove an impossible to reach exit from bin/zkServer-initialize.sh
* Remove an impossible to fail check of `$?` after nohup is executed in
  bin/zkServer.sh (nohup with a trailing `&` always returns a zero exit
  code for success, even if the command fails; if it fails it fails
  undetectibly in the background)
* Avoid using sed for regex, and use built-in bash regex instead
* Delete some old scripts (some of which are broken anyway) that don't
  appear to be used anywhere, and don't seem to have any current need
* Bump rat plugin version for https in license and add license to
  .gitattributes to make rat plugin happy again
Reviewers: tisonkun, anmolnar
Author: ctubbsii
Closes #2224 from ctubbsii/cleanup-scripts
Christopher Tubbs 1 month ago
parent
commit
69d95a256d
34 changed files with 1208 additions and 2583 deletions
  1. 19 0
      .gitattributes
  2. 58 0
      .github/workflows/scripts.yaml
  3. 31 27
      bin/zkCleanup.sh
  4. 31 22
      bin/zkCli.sh
  5. 61 71
      bin/zkEnv.sh
  6. 83 79
      bin/zkServer-initialize.sh
  7. 162 170
      bin/zkServer.sh
  8. 26 21
      bin/zkSnapShotToolkit.sh
  9. 26 19
      bin/zkSnapshotComparer.sh
  10. 26 22
      bin/zkSnapshotRecursiveSummaryToolkit.sh
  11. 26 21
      bin/zkTxnLogToolkit.sh
  12. 37 35
      dev/docker/run.sh
  13. 1 0
      pom.xml
  14. 29 0
      tools/ci/install-shfmt.sh
  15. 28 0
      tools/ci/run-shellcheck.sh
  16. 26 0
      tools/ci/run-shfmt.sh
  17. 24 21
      tools/sonar/code-coverage.sh
  18. 21 20
      zookeeper-client/zookeeper-client-c/ssl/gencerts.sh
  19. 127 162
      zookeeper-client/zookeeper-client-c/tests/zkServer.sh
  20. 37 27
      zookeeper-contrib/zookeeper-contrib-loggraph/src/main/resources/loggraph-dev.sh
  21. 34 34
      zookeeper-contrib/zookeeper-contrib-loggraph/src/main/resources/loggraph.sh
  22. 54 47
      zookeeper-contrib/zookeeper-contrib-rest/rest.sh
  23. 49 55
      zookeeper-contrib/zookeeper-contrib-rest/src/test/zkServer.sh
  24. 24 20
      zookeeper-contrib/zookeeper-contrib-zkpython/src/test/run_tests.sh
  25. 48 61
      zookeeper-contrib/zookeeper-contrib-zkpython/src/test/zkServer.sh
  26. 20 16
      zookeeper-contrib/zookeeper-contrib-zooinspector/zooInspector-dev.sh
  27. 18 17
      zookeeper-contrib/zookeeper-contrib-zooinspector/zooInspector.sh
  28. 41 45
      zookeeper-recipes/zookeeper-recipes-lock/src/main/c/tests/zkServer.sh
  29. 41 45
      zookeeper-recipes/zookeeper-recipes-queue/src/main/c/tests/zkServer.sh
  30. 0 22
      zookeeper-server/src/main/resources/lastRevision.bat
  31. 0 22
      zookeeper-server/src/main/resources/lastRevision.sh
  32. 0 614
      zookeeper-server/src/test/resources/test-github-pr.sh
  33. 0 647
      zookeeper-server/src/test/resources/test-patch.sh
  34. 0 221
      zookeeper-server/src/test/resources/test-scripts.sh

+ 19 - 0
.gitattributes

@@ -1,3 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
 # Auto detect text files and perform LF normalization
 # Auto detect text files and perform LF normalization
 *        text=auto
 *        text=auto
 
 

+ 58 - 0
.github/workflows/scripts.yaml

@@ -0,0 +1,58 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# This workflow enforces quality checks on bash scripts in the project
+
+name: ScriptQA
+
+on:
+  push:
+    branches: [ '*' ]
+  pull_request:
+    branches: [ '*' ]
+
+permissions:
+  contents: read
+
+jobs:
+  shfmt:
+    name: shfmt
+    timeout-minutes: 3
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/checkout@v4
+    - name: Show the first log message
+      run: git log -n1
+    - name: Install shfmt
+      run: tools/ci/install-shfmt.sh
+    - name: Checking formatting of all scripts
+      run: tools/ci/run-shfmt.sh
+
+  shellcheck:
+    name: ShellCheck
+    timeout-minutes: 3
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/checkout@v4
+    - name: Show the first log message
+      run: git log -n1
+    - name: Install shfmt
+      run: tools/ci/install-shfmt.sh
+    - name: Running shellcheck on all scripts
+      run: tools/ci/run-shellcheck.sh

+ 31 - 27
bin/zkCleanup.sh

@@ -1,19 +1,22 @@
-#!/usr/bin/env bash
-
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+#! /usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
 
 
 #
 #
 # This script cleans up old transaction logs and snapshots
 # This script cleans up old transaction logs and snapshots
@@ -27,12 +30,14 @@
 
 
 # use POSIX interface, symlink is followed automatically
 # use POSIX interface, symlink is followed automatically
 ZOOBIN="${BASH_SOURCE-$0}"
 ZOOBIN="${BASH_SOURCE-$0}"
-ZOOBIN="$(dirname "${ZOOBIN}")"
-ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)"
+ZOOBIN="$(dirname "$ZOOBIN")"
+ZOOBINDIR="$(cd "$ZOOBIN" && pwd)"
 
 
-if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then
+if [[ -e "$ZOOBIN/../libexec/zkEnv.sh" ]]; then
+  # shellcheck source=bin/zkEnv.sh
   . "$ZOOBINDIR"/../libexec/zkEnv.sh
   . "$ZOOBINDIR"/../libexec/zkEnv.sh
 else
 else
+  # shellcheck source=bin/zkEnv.sh
   . "$ZOOBINDIR"/zkEnv.sh
   . "$ZOOBINDIR"/zkEnv.sh
 fi
 fi
 
 
@@ -41,13 +46,12 @@ ZOODATALOGDIR="$(grep "^[[:space:]]*dataLogDir=" "$ZOOCFG" | sed -e 's/.*=//')"
 
 
 ZOO_LOG_FILE=zookeeper-$USER-cleanup-$HOSTNAME.log
 ZOO_LOG_FILE=zookeeper-$USER-cleanup-$HOSTNAME.log
 
 
-if [ "x$ZOODATALOGDIR" = "x" ]
-then
-"$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.log.file=${ZOO_LOG_FILE}" \
-     -cp "$CLASSPATH" $JVMFLAGS \
-     org.apache.zookeeper.server.PurgeTxnLog "$ZOODATADIR" $*
+# shellcheck disable=SC2206
+flags=($JVMFLAGS)
+if [[ -z $ZOODATALOGDIR ]]; then
+  "$JAVA" "-Dzookeeper.log.dir=$ZOO_LOG_DIR" "-Dzookeeper.log.file=$ZOO_LOG_FILE" "${flags[@]}" \
+    org.apache.zookeeper.server.PurgeTxnLog "$ZOODATADIR" "$@"
 else
 else
-"$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.log.file=${ZOO_LOG_FILE}" \
-     -cp "$CLASSPATH" $JVMFLAGS \
-     org.apache.zookeeper.server.PurgeTxnLog "$ZOODATALOGDIR" "$ZOODATADIR" $*
+  "$JAVA" "-Dzookeeper.log.dir=$ZOO_LOG_DIR" "-Dzookeeper.log.file=$ZOO_LOG_FILE" "${flags[@]}" \
+    org.apache.zookeeper.server.PurgeTxnLog "$ZOODATALOGDIR" "$ZOODATADIR" "$@"
 fi
 fi

+ 31 - 22
bin/zkCli.sh

@@ -1,19 +1,22 @@
-#!/usr/bin/env bash
-
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+#! /usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
 
 
 #
 #
 # This script cleans up old transaction logs and snapshots
 # This script cleans up old transaction logs and snapshots
@@ -27,17 +30,23 @@
 
 
 # use POSIX interface, symlink is followed automatically
 # use POSIX interface, symlink is followed automatically
 ZOOBIN="${BASH_SOURCE-$0}"
 ZOOBIN="${BASH_SOURCE-$0}"
-ZOOBIN="$(dirname "${ZOOBIN}")"
-ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)"
+ZOOBIN="$(dirname "$ZOOBIN")"
+ZOOBINDIR="$(cd "$ZOOBIN" && pwd)"
 
 
-if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then
+if [[ -e "$ZOOBIN/../libexec/zkEnv.sh" ]]; then
+  # shellcheck source=bin/zkEnv.sh
   . "$ZOOBINDIR"/../libexec/zkEnv.sh
   . "$ZOOBINDIR"/../libexec/zkEnv.sh
 else
 else
+  # shellcheck source=bin/zkEnv.sh
   . "$ZOOBINDIR"/zkEnv.sh
   . "$ZOOBINDIR"/zkEnv.sh
 fi
 fi
 
 
 ZOO_LOG_FILE=zookeeper-$USER-cli-$HOSTNAME.log
 ZOO_LOG_FILE=zookeeper-$USER-cli-$HOSTNAME.log
 
 
-"$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.log.file=${ZOO_LOG_FILE}" \
-     -cp "$CLASSPATH" $CLIENT_JVMFLAGS $JVMFLAGS \
-     org.apache.zookeeper.ZooKeeperMain "$@"
+# shellcheck disable=SC2206
+clientflags=($CLIENT_JVMFLAGS)
+# shellcheck disable=SC2206
+flags=($JVMFLAGS)
+"$JAVA" "-Dzookeeper.log.dir=$ZOO_LOG_DIR" "-Dzookeeper.log.file=$ZOO_LOG_FILE" \
+  "${clientflags[@]}" "${flags[@]}" \
+  org.apache.zookeeper.ZooKeeperMain "$@"

+ 61 - 71
bin/zkEnv.sh

@@ -1,19 +1,22 @@
-#!/usr/bin/env bash
-
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
+#! /usr/bin/env bash
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
 
 # This script should be sourced into other zookeeper
 # This script should be sourced into other zookeeper
 # scripts to setup the env variables
 # scripts to setup the env variables
@@ -26,101 +29,88 @@
 # '--config' option in the command line.
 # '--config' option in the command line.
 
 
 ZOOBINDIR="${ZOOBINDIR:-/usr/bin}"
 ZOOBINDIR="${ZOOBINDIR:-/usr/bin}"
-ZOOKEEPER_PREFIX="${ZOOBINDIR}/.."
+ZOOKEEPER_PREFIX="$ZOOBINDIR/.."
 
 
 #check to see if the conf dir is given as an optional argument
 #check to see if the conf dir is given as an optional argument
-if [ $# -gt 1 ]
-then
-    if [ "--config" = "$1" ]
-	  then
-	      shift
-	      confdir=$1
-	      shift
-	      ZOOCFGDIR=$confdir
-    fi
+if [[ $# -gt 1 ]]; then
+  if [[ "--config" == "$1" ]]; then
+    shift
+    ZOOCFGDIR=$1
+    shift
+  fi
 fi
 fi
 
 
-if [ "x$ZOOCFGDIR" = "x" ]
-then
-  if [ -e "${ZOOKEEPER_PREFIX}/conf" ]; then
+if [[ -z $ZOOCFGDIR ]]; then
+  if [[ -e "$ZOOKEEPER_PREFIX/conf" ]]; then
     ZOOCFGDIR="$ZOOBINDIR/../conf"
     ZOOCFGDIR="$ZOOBINDIR/../conf"
   else
   else
     ZOOCFGDIR="$ZOOBINDIR/../etc/zookeeper"
     ZOOCFGDIR="$ZOOBINDIR/../etc/zookeeper"
   fi
   fi
 fi
 fi
 
 
-if [ -f "${ZOOCFGDIR}/zookeeper-env.sh" ]; then
-  . "${ZOOCFGDIR}/zookeeper-env.sh"
+if [[ -f "$ZOOCFGDIR/zookeeper-env.sh" ]]; then
+  # shellcheck source=bin/zkEnv.sh
+  . "$ZOOCFGDIR/zookeeper-env.sh"
 fi
 fi
 
 
-if [ "x$ZOOCFG" = "x" ]
-then
-    ZOOCFG="zoo.cfg"
-fi
+ZOOCFG=${ZOOCFG:-zoo.cfg}
 
 
 ZOOCFG="$ZOOCFGDIR/$ZOOCFG"
 ZOOCFG="$ZOOCFGDIR/$ZOOCFG"
 
 
-if [ -f "$ZOOCFGDIR/java.env" ]
-then
-    . "$ZOOCFGDIR/java.env"
+if [[ -f "$ZOOCFGDIR/java.env" ]]; then
+  # shellcheck source=bin/zkEnv.sh
+  . "$ZOOCFGDIR/java.env"
 fi
 fi
 
 
-if [ "x${ZOO_LOG_DIR}" = "x" ]
-then
-    ZOO_LOG_DIR="$ZOOKEEPER_PREFIX/logs"
-fi
+ZOO_LOG_DIR=${ZOO_LOG_DIR:-$ZOOKEEPER_PREFIX/logs}
 
 
-if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]];  then
-    JAVA="$JAVA_HOME/bin/java"
+if [[ -n $JAVA_HOME ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
+  JAVA="$JAVA_HOME/bin/java"
 elif type -p java; then
 elif type -p java; then
-    JAVA=java
+  # ignore unused; used this file is sourced
+  # shellcheck disable=SC2034
+  JAVA=java
 else
 else
-    echo "Error: JAVA_HOME is not set and java could not be found in PATH." 1>&2
-    exit 1
+  echo "Error: JAVA_HOME is not set and java could not be found in PATH." 1>&2
+  exit 1
 fi
 fi
 
 
 #add the zoocfg dir to classpath
 #add the zoocfg dir to classpath
 CLASSPATH="$ZOOCFGDIR:$CLASSPATH"
 CLASSPATH="$ZOOCFGDIR:$CLASSPATH"
 
 
-for i in "$ZOOBINDIR"/../zookeeper-server/src/main/resources/lib/*.jar
-do
-    CLASSPATH="$i:$CLASSPATH"
+for i in "$ZOOBINDIR"/../zookeeper-server/src/main/resources/lib/*.jar; do
+  CLASSPATH="$i:$CLASSPATH"
 done
 done
 
 
 #make it work in the binary package
 #make it work in the binary package
 #(use array for LIBPATH to account for spaces within wildcard expansion)
 #(use array for LIBPATH to account for spaces within wildcard expansion)
-if ls "${ZOOKEEPER_PREFIX}"/share/zookeeper/zookeeper-*.jar > /dev/null 2>&1; then 
-  LIBPATH=("${ZOOKEEPER_PREFIX}"/share/zookeeper/*.jar)
+if ls "$ZOOKEEPER_PREFIX"/share/zookeeper/zookeeper-*.jar &>/dev/null; then
+  LIBPATH=("$ZOOKEEPER_PREFIX"/share/zookeeper/*.jar)
 else
 else
   #release tarball format
   #release tarball format
-  for i in "$ZOOBINDIR"/../zookeeper-*.jar
-  do
+  for i in "$ZOOBINDIR"/../zookeeper-*.jar; do
     CLASSPATH="$i:$CLASSPATH"
     CLASSPATH="$i:$CLASSPATH"
   done
   done
-  LIBPATH=("${ZOOBINDIR}"/../lib/*.jar)
+  LIBPATH=("$ZOOBINDIR"/../lib/*.jar)
 fi
 fi
 
 
-for i in "${LIBPATH[@]}"
-do
-    CLASSPATH="$i:$CLASSPATH"
+for i in "${LIBPATH[@]}"; do
+  CLASSPATH="$i:$CLASSPATH"
 done
 done
 
 
 #make it work for developers
 #make it work for developers
-for d in "$ZOOBINDIR"/../build/lib/*.jar
-do
-   CLASSPATH="$d:$CLASSPATH"
+for d in "$ZOOBINDIR"/../build/lib/*.jar; do
+  CLASSPATH="$d:$CLASSPATH"
 done
 done
 
 
 #make it work for developers
 #make it work for developers
-for d in "$ZOOBINDIR"/../zookeeper-server/target/lib/*.jar
-do
-   CLASSPATH="$d:$CLASSPATH"
+for d in "$ZOOBINDIR"/../zookeeper-server/target/lib/*.jar; do
+  CLASSPATH="$d:$CLASSPATH"
 done
 done
 
 
 #make it work for developers
 #make it work for developers
-for d in "$ZOOBINDIR"/../zookeeper-metrics-providers/zookeeper-prometheus-metrics/target/lib/*.jar
-do
-   CLASSPATH="$d:$CLASSPATH"
+for d in "$ZOOBINDIR"/../zookeeper-metrics-providers/zookeeper-prometheus-metrics/target/lib/*.jar; do
+  CLASSPATH="$d:$CLASSPATH"
 done
 done
 
 
 #make it work for developers
 #make it work for developers
@@ -132,17 +122,17 @@ CLASSPATH="$ZOOBINDIR/../zookeeper-server/target/classes:$CLASSPATH"
 #make it work for developers
 #make it work for developers
 CLASSPATH="$ZOOBINDIR/../zookeeper-metrics-providers/zookeeper-prometheus-metrics/target/classes:$CLASSPATH"
 CLASSPATH="$ZOOBINDIR/../zookeeper-metrics-providers/zookeeper-prometheus-metrics/target/classes:$CLASSPATH"
 
 
-case "`uname`" in
-    CYGWIN*|MINGW*) cygwin=true ;;
-    *) cygwin=false ;;
+case "$(uname)" in
+  CYGWIN* | MINGW*) cygwin=true ;;
+  *) cygwin=false ;;
 esac
 esac
 
 
-if $cygwin
-then
-    CLASSPATH=`cygpath -wp "$CLASSPATH"`
+if $cygwin; then
+  CLASSPATH=$(cygpath -wp "$CLASSPATH")
 fi
 fi
 
 
 #echo "CLASSPATH=$CLASSPATH"
 #echo "CLASSPATH=$CLASSPATH"
+export CLASSPATH
 
 
 # default heap for zookeeper server
 # default heap for zookeeper server
 ZK_SERVER_HEAP="${ZK_SERVER_HEAP:-1000}"
 ZK_SERVER_HEAP="${ZK_SERVER_HEAP:-1000}"

+ 83 - 79
bin/zkServer-initialize.sh

@@ -1,19 +1,22 @@
-#!/usr/bin/env bash
-
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
+#! /usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
 
 #
 #
 # If this scripted is run out of /usr/bin or some other system bin directory
 # If this scripted is run out of /usr/bin or some other system bin directory
@@ -23,12 +26,14 @@
 
 
 # use POSIX interface, symlink is followed automatically
 # use POSIX interface, symlink is followed automatically
 ZOOBIN="${BASH_SOURCE-$0}"
 ZOOBIN="${BASH_SOURCE-$0}"
-ZOOBIN="$(dirname "${ZOOBIN}")"
-ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)"
+ZOOBIN="$(dirname "$ZOOBIN")"
+ZOOBINDIR="$(cd "$ZOOBIN" && pwd)"
 
 
-if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then
+if [[ -e "$ZOOBIN/../libexec/zkEnv.sh" ]]; then
+  # shellcheck source=bin/zkEnv.sh
   . "$ZOOBINDIR"/../libexec/zkEnv.sh
   . "$ZOOBINDIR"/../libexec/zkEnv.sh
 else
 else
+  # shellcheck source=bin/zkEnv.sh
   . "$ZOOBINDIR"/zkEnv.sh
   . "$ZOOBINDIR"/zkEnv.sh
 fi
 fi
 
 
@@ -47,94 +52,93 @@ usage() {
   exit 1
   exit 1
 }
 }
 
 
-if [ $? != 0 ] ; then
-    usage
-    exit 1
-fi
-
 initialize() {
 initialize() {
-    if [ ! -e "$ZOOCFG" ]; then
-        echo "Unable to find config file at $ZOOCFG"
-        exit 1
-    fi
-
-    ZOO_DATADIR="$(grep "^[[:space:]]*dataDir" "$ZOOCFG" | sed -e 's/.*=//')"
-    ZOO_DATALOGDIR="$(grep "^[[:space:]]*dataLogDir" "$ZOOCFG" | sed -e 's/.*=//')"
-
-    if [ -z "$ZOO_DATADIR" ]; then
-        echo "Unable to determine dataDir from $ZOOCFG"
-        exit 1
-    fi
-
-    if [ $FORCE ]; then
-        echo "Force enabled, data/txnlog directories will be re-initialized"
-    else
-        # we create if version-2 exists (ie real data), not the
-        # parent. See comments in following section for more insight
-        if [ -d "$ZOO_DATADIR/version-2" ]; then
-            echo "ZooKeeper data directory already exists at $ZOO_DATADIR (or use --force to force re-initialization)"
-            exit 1
-        fi
-
-        if [ -n "$ZOO_DATALOGDIR" ] && [ -d "$ZOO_DATALOGDIR/version-2" ]; then
-            echo "ZooKeeper txnlog directory already exists at $ZOO_DATALOGDIR (or use --force to force re-initialization)"
-            exit 1
-        fi
-    fi
+  if [[ ! -e $ZOOCFG ]]; then
+    echo "Unable to find config file at $ZOOCFG"
+    exit 1
+  fi
 
 
-    # remove the child files that we're (not) interested in, not the
-    # parent. this allows for parent to be installed separately, and
-    # permissions to be set based on overarching requirements. by
-    # default we'll use the permissions of the user running this
-    # script for the files contained by the parent. note also by using
-    # -p the parent(s) will be created if it doesn't already exist
-    rm -rf "$ZOO_DATADIR/myid" 2>/dev/null >/dev/null
-    rm -rf "$ZOO_DATADIR/version-2" 2>/dev/null >/dev/null
-    mkdir -p "$ZOO_DATADIR/version-2"
+  ZOO_DATADIR="$(grep "^[[:space:]]*dataDir" "$ZOOCFG" | sed -e 's/.*=//')"
+  ZOO_DATALOGDIR="$(grep "^[[:space:]]*dataLogDir" "$ZOOCFG" | sed -e 's/.*=//')"
 
 
-    if [ -n "$ZOO_DATALOGDIR" ]; then
-        rm -rf "$ZOO_DATALOGDIR/myid" 2>/dev/null >/dev/null
-        rm -rf "$ZOO_DATALOGDIR/version-2" 2>/dev/null >/dev/null
-        mkdir -p "$ZOO_DATALOGDIR/version-2"
+  if [[ -z $ZOO_DATADIR ]]; then
+    echo "Unable to determine dataDir from $ZOOCFG"
+    exit 1
+  fi
+
+  if [[ $FORCE -eq 1 ]]; then
+    echo "Force enabled, data/txnlog directories will be re-initialized"
+  else
+    # we create if version-2 exists (ie real data), not the
+    # parent. See comments in following section for more insight
+    if [[ -d "$ZOO_DATADIR/version-2" ]]; then
+      echo "ZooKeeper data directory already exists at $ZOO_DATADIR (or use --force to force re-initialization)"
+      exit 1
     fi
     fi
 
 
-    if [ $MYID ]; then
-        echo "Using myid of $MYID"
-        echo $MYID > "$ZOO_DATADIR/myid"
-    else
-        echo "No myid provided, be sure to specify it in $ZOO_DATADIR/myid if using non-standalone"
+    if [[ -n $ZOO_DATALOGDIR ]] && [[ -d "$ZOO_DATALOGDIR/version-2" ]]; then
+      echo "ZooKeeper txnlog directory already exists at $ZOO_DATALOGDIR (or use --force to force re-initialization)"
+      exit 1
     fi
     fi
-
-    touch "$ZOO_DATADIR/initialize"
+  fi
+
+  # remove the child files that we're (not) interested in, not the
+  # parent. this allows for parent to be installed separately, and
+  # permissions to be set based on overarching requirements. by
+  # default we'll use the permissions of the user running this
+  # script for the files contained by the parent. note also by using
+  # -p the parent(s) will be created if it doesn't already exist
+  rm -rf "$ZOO_DATADIR/myid" 2>/dev/null >/dev/null
+  rm -rf "$ZOO_DATADIR/version-2" 2>/dev/null >/dev/null
+  mkdir -p "$ZOO_DATADIR/version-2"
+
+  if [[ -n $ZOO_DATALOGDIR ]]; then
+    rm -rf "$ZOO_DATALOGDIR/myid" 2>/dev/null >/dev/null
+    rm -rf "$ZOO_DATALOGDIR/version-2" 2>/dev/null >/dev/null
+    mkdir -p "$ZOO_DATALOGDIR/version-2"
+  fi
+
+  if [[ -n $MYID ]]; then
+    echo "Using myid of $MYID"
+    echo "$MYID" >"$ZOO_DATADIR/myid"
+  else
+    echo "No myid provided, be sure to specify it in $ZOO_DATADIR/myid if using non-standalone"
+  fi
+
+  touch "$ZOO_DATADIR/initialize"
 }
 }
 
 
-while [ ! -z "$1" ]; do
+while [[ -n $1 ]]; do
   case "$1" in
   case "$1" in
     --configfile)
     --configfile)
-      ZOOCFG=$2; shift 2
+      ZOOCFG=$2
+      shift 2
       ;;
       ;;
     --configfile=?*)
     --configfile=?*)
-      ZOOCFG=${1#*=}; shift 1
+      ZOOCFG=${1#*=}
+      shift 1
       ;;
       ;;
     --myid)
     --myid)
-      MYID=$2; shift 2
+      MYID=$2
+      shift 2
       ;;
       ;;
     --myid=?*)
     --myid=?*)
-      MYID=${1#*=}; shift 1
+      MYID=${1#*=}
+      shift 1
       ;;
       ;;
     --force)
     --force)
-      FORCE=1; shift 1
+      FORCE=1
+      shift 1
       ;;
       ;;
     -h)
     -h)
       usage
       usage
-      ;; 
+      ;;
     --help)
     --help)
       usage
       usage
-      ;; 
+      ;;
     *)
     *)
       echo "Unknown option: $1"
       echo "Unknown option: $1"
       usage
       usage
-      exit 1 
       ;;
       ;;
   esac
   esac
 done
 done

+ 162 - 170
bin/zkServer.sh

@@ -1,19 +1,22 @@
-#!/usr/bin/env bash
-
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
+#! /usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
 
 #
 #
 # If this scripted is run out of /usr/bin or some other system bin directory
 # If this scripted is run out of /usr/bin or some other system bin directory
@@ -21,15 +24,16 @@
 # relative to the canonical path of this script.
 # relative to the canonical path of this script.
 #
 #
 
 
-
 # use POSIX interface, symlink is followed automatically
 # use POSIX interface, symlink is followed automatically
 ZOOBIN="${BASH_SOURCE-$0}"
 ZOOBIN="${BASH_SOURCE-$0}"
-ZOOBIN="$(dirname "${ZOOBIN}")"
-ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)"
+ZOOBIN="$(dirname "$ZOOBIN")"
+ZOOBINDIR="$(cd "$ZOOBIN" && pwd)"
 
 
-if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then
+if [[ -e "$ZOOBIN/../libexec/zkEnv.sh" ]]; then
+  # shellcheck source=bin/zkEnv.sh
   . "$ZOOBINDIR"/../libexec/zkEnv.sh
   . "$ZOOBINDIR"/../libexec/zkEnv.sh
 else
 else
+  # shellcheck source=bin/zkEnv.sh
   . "$ZOOBINDIR"/zkEnv.sh
   . "$ZOOBINDIR"/zkEnv.sh
 fi
 fi
 
 
@@ -37,252 +41,240 @@ fi
 # up the JVM to accept JMX remote management:
 # up the JVM to accept JMX remote management:
 # http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html
 # http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html
 # by default we allow local JMX connections
 # by default we allow local JMX connections
-if [ "x$JMXLOCALONLY" = "x" ]
-then
-    JMXLOCALONLY=false
+if [[ -z $JMXLOCALONLY ]]; then
+  JMXLOCALONLY=false
 fi
 fi
 
 
-if [ "x$JMXDISABLE" = "x" ] || [ "$JMXDISABLE" = 'false' ]
-then
+if [[ -z $JMXDISABLE ]] || [[ $JMXDISABLE == 'false' ]]; then
   echo "ZooKeeper JMX enabled by default" >&2
   echo "ZooKeeper JMX enabled by default" >&2
-  if [ "x$JMXPORT" = "x" ]
-  then
+  if [[ -z $JMXPORT ]]; then
     # for some reason these two options are necessary on jdk6 on Ubuntu
     # for some reason these two options are necessary on jdk6 on Ubuntu
     #   accord to the docs they are not necessary, but otw jconsole cannot
     #   accord to the docs they are not necessary, but otw jconsole cannot
     #   do a local attach
     #   do a local attach
-    ZOOMAIN="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=$JMXLOCALONLY org.apache.zookeeper.server.quorum.QuorumPeerMain"
+    ZOOMAIN=("-Dcom.sun.management.jmxremote" "-Dcom.sun.management.jmxremote.local.only=$JMXLOCALONLY" "org.apache.zookeeper.server.quorum.QuorumPeerMain")
   else
   else
-    if [ "x$JMXAUTH" = "x" ]
-    then
+    if [[ -z $JMXAUTH ]]; then
       JMXAUTH=false
       JMXAUTH=false
     fi
     fi
-    if [ "x$JMXSSL" = "x" ]
-    then
+    if [[ -z $JMXSSL ]]; then
       JMXSSL=false
       JMXSSL=false
     fi
     fi
-    if [ "x$JMXLOG4J" = "x" ]
-    then
+    if [[ -z $JMXLOG4J ]]; then
       JMXLOG4J=true
       JMXLOG4J=true
     fi
     fi
     echo "ZooKeeper remote JMX Port set to $JMXPORT" >&2
     echo "ZooKeeper remote JMX Port set to $JMXPORT" >&2
     echo "ZooKeeper remote JMX authenticate set to $JMXAUTH" >&2
     echo "ZooKeeper remote JMX authenticate set to $JMXAUTH" >&2
     echo "ZooKeeper remote JMX ssl set to $JMXSSL" >&2
     echo "ZooKeeper remote JMX ssl set to $JMXSSL" >&2
     echo "ZooKeeper remote JMX log4j set to $JMXLOG4J" >&2
     echo "ZooKeeper remote JMX log4j set to $JMXLOG4J" >&2
-    if [ "x$JMXHOSTNAME" = "x" ]
-    then
-      ZOOMAIN="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=$JMXPORT -Dcom.sun.management.jmxremote.authenticate=$JMXAUTH -Dcom.sun.management.jmxremote.ssl=$JMXSSL -Dzookeeper.jmx.log4j.disable=$JMXLOG4J org.apache.zookeeper.server.quorum.QuorumPeerMain"
+    if [[ -z $JMXHOSTNAME ]]; then
+      ZOOMAIN=("-Dcom.sun.management.jmxremote" "-Dcom.sun.management.jmxremote.port=$JMXPORT" "-Dcom.sun.management.jmxremote.authenticate=$JMXAUTH" "-Dcom.sun.management.jmxremote.ssl=$JMXSSL" "-Dzookeeper.jmx.log4j.disable=$JMXLOG4J" "org.apache.zookeeper.server.quorum.QuorumPeerMain")
     else
     else
       echo "ZooKeeper remote JMX Hostname set to $JMXHOSTNAME" >&2
       echo "ZooKeeper remote JMX Hostname set to $JMXHOSTNAME" >&2
-      ZOOMAIN="-Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=$JMXHOSTNAME -Dcom.sun.management.jmxremote.port=$JMXPORT -Dcom.sun.management.jmxremote.authenticate=$JMXAUTH -Dcom.sun.management.jmxremote.ssl=$JMXSSL -Dzookeeper.jmx.log4j.disable=$JMXLOG4J org.apache.zookeeper.server.quorum.QuorumPeerMain"
+      ZOOMAIN=("-Dcom.sun.management.jmxremote" "-Djava.rmi.server.hostname=$JMXHOSTNAME" "-Dcom.sun.management.jmxremote.port=$JMXPORT" "-Dcom.sun.management.jmxremote.authenticate=$JMXAUTH" "-Dcom.sun.management.jmxremote.ssl=$JMXSSL" "-Dzookeeper.jmx.log4j.disable=$JMXLOG4J" "org.apache.zookeeper.server.quorum.QuorumPeerMain")
     fi
     fi
   fi
   fi
 else
 else
-    echo "JMX disabled by user request" >&2
-    ZOOMAIN="org.apache.zookeeper.server.quorum.QuorumPeerMain"
+  echo "JMX disabled by user request" >&2
+  ZOOMAIN=("org.apache.zookeeper.server.quorum.QuorumPeerMain")
 fi
 fi
 
 
-if [ "x$SERVER_JVMFLAGS" != "x" ]
-then
-    JVMFLAGS="$SERVER_JVMFLAGS $JVMFLAGS"
+if [[ -n $SERVER_JVMFLAGS ]]; then
+  JVMFLAGS="$SERVER_JVMFLAGS $JVMFLAGS"
 fi
 fi
+# shellcheck disable=SC2206
+flags=($JVMFLAGS)
+# shellcheck disable=SC2206
+clientflags=($CLIENT_JVMFLAGS)
 
 
-if [ "x$2" != "x" ]
-then
-    ZOOCFG="$ZOOCFGDIR/$2"
+if [[ -n $2 ]]; then
+  ZOOCFG="$ZOOCFGDIR/$2"
 fi
 fi
 
 
 # if we give a more complicated path to the config, don't screw around in $ZOOCFGDIR
 # if we give a more complicated path to the config, don't screw around in $ZOOCFGDIR
-if [ "x$(dirname "$ZOOCFG")" != "x$ZOOCFGDIR" ]
-then
-    ZOOCFG="$2"
+if [[ "$(dirname "$ZOOCFG")" != "$ZOOCFGDIR" ]]; then
+  ZOOCFG="$2"
 fi
 fi
 
 
-if $cygwin
-then
-    ZOOCFG=`cygpath -wp "$ZOOCFG"`
-    # cygwin has a "kill" in the shell itself, gets confused
-    KILL=/bin/kill
+if $cygwin; then
+  ZOOCFG=$(cygpath -wp "$ZOOCFG")
+  # cygwin has a "kill" in the shell itself, gets confused
+  KILL='/bin/kill'
 else
 else
-    KILL=kill
+  KILL='kill'
 fi
 fi
 
 
 echo "Using config: $ZOOCFG" >&2
 echo "Using config: $ZOOCFG" >&2
 
 
 case "$OSTYPE" in
 case "$OSTYPE" in
-*solaris*)
-  GREP=/usr/xpg4/bin/grep
-  ;;
-*)
-  GREP=grep
-  ;;
+  *solaris*)
+    GREP='/usr/xpg4/bin/grep'
+    ;;
+  *)
+    GREP='grep'
+    ;;
 esac
 esac
 ZOO_DATADIR="$($GREP "^[[:space:]]*dataDir" "$ZOOCFG" | sed -e 's/.*=//')"
 ZOO_DATADIR="$($GREP "^[[:space:]]*dataDir" "$ZOOCFG" | sed -e 's/.*=//')"
-ZOO_DATADIR="$(echo -e "${ZOO_DATADIR}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
+ZOO_DATADIR="$(echo -e "$ZOO_DATADIR" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
 ZOO_DATALOGDIR="$($GREP "^[[:space:]]*dataLogDir" "$ZOOCFG" | sed -e 's/.*=//')"
 ZOO_DATALOGDIR="$($GREP "^[[:space:]]*dataLogDir" "$ZOOCFG" | sed -e 's/.*=//')"
 
 
 # iff autocreate is turned off and the datadirs don't exist fail
 # iff autocreate is turned off and the datadirs don't exist fail
 # immediately as we can't create the PID file, etc..., anyway.
 # immediately as we can't create the PID file, etc..., anyway.
-if [ -n "$ZOO_DATADIR_AUTOCREATE_DISABLE" ]; then
-    if [ ! -d "$ZOO_DATADIR/version-2" ]; then
-        echo "ZooKeeper data directory is missing at $ZOO_DATADIR fix the path or run initialize"
-        exit 1
-    fi
+if [[ -n $ZOO_DATADIR_AUTOCREATE_DISABLE ]]; then
+  if [[ ! -d "$ZOO_DATADIR/version-2" ]]; then
+    echo "ZooKeeper data directory is missing at $ZOO_DATADIR fix the path or run initialize"
+    exit 1
+  fi
 
 
-    if [ -n "$ZOO_DATALOGDIR" ] && [ ! -d "$ZOO_DATALOGDIR/version-2" ]; then
-        echo "ZooKeeper txnlog directory is missing at $ZOO_DATALOGDIR fix the path or run initialize"
-        exit 1
-    fi
-    ZOO_DATADIR_AUTOCREATE="-Dzookeeper.datadir.autocreate=false"
+  if [[ -n $ZOO_DATALOGDIR ]] && [[ ! -d "$ZOO_DATALOGDIR/version-2" ]]; then
+    echo "ZooKeeper txnlog directory is missing at $ZOO_DATALOGDIR fix the path or run initialize"
+    exit 1
+  fi
+  flags=("-Dzookeeper.datadir.autocreate=false" "${flags[@]}")
 fi
 fi
 
 
-if [ -z "$ZOOPIDFILE" ]; then
-    if [ ! -d "$ZOO_DATADIR" ]; then
-        mkdir -p "$ZOO_DATADIR"
-    fi
-    ZOOPIDFILE="$ZOO_DATADIR/zookeeper_server.pid"
+if [[ -z $ZOOPIDFILE ]]; then
+  if [[ ! -d $ZOO_DATADIR ]]; then
+    mkdir -p "$ZOO_DATADIR"
+  fi
+  ZOOPIDFILE="$ZOO_DATADIR/zookeeper_server.pid"
 else
 else
-    # ensure it exists, otw stop will fail
-    mkdir -p "$(dirname "$ZOOPIDFILE")"
+  # ensure it exists, otw stop will fail
+  mkdir -p "$(dirname "$ZOOPIDFILE")"
 fi
 fi
 
 
-if [ ! -w "$ZOO_LOG_DIR" ] ; then
-mkdir -p "$ZOO_LOG_DIR"
+if [[ ! -w $ZOO_LOG_DIR ]]; then
+  mkdir -p "$ZOO_LOG_DIR"
 fi
 fi
 
 
 ZOO_LOG_FILE=${ZOO_LOG_FILE:-zookeeper-$USER-server-$HOSTNAME.log}
 ZOO_LOG_FILE=${ZOO_LOG_FILE:-zookeeper-$USER-server-$HOSTNAME.log}
 _ZOO_DAEMON_OUT="$ZOO_LOG_DIR/zookeeper-$USER-server-$HOSTNAME.out"
 _ZOO_DAEMON_OUT="$ZOO_LOG_DIR/zookeeper-$USER-server-$HOSTNAME.out"
 
 
 case $1 in
 case $1 in
-start)
-    echo  -n "Starting zookeeper ... "
-    if [ -f "$ZOOPIDFILE" ]; then
-      if kill -0 `cat "$ZOOPIDFILE"` > /dev/null 2>&1; then
-         echo $command already running as process `cat "$ZOOPIDFILE"`.
-         exit 1
+  start)
+    echo -n "Starting zookeeper ... "
+    if [[ -f $ZOOPIDFILE ]]; then
+      if kill -0 "$(cat "$ZOOPIDFILE")" &>/dev/null; then
+        echo "already running as process $(cat "$ZOOPIDFILE")."
+        exit 1
       fi
       fi
     fi
     fi
-    nohup "$JAVA" $ZOO_DATADIR_AUTOCREATE "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" \
-    "-Dzookeeper.log.file=${ZOO_LOG_FILE}" \
-    -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError='kill -9 %p' \
-    -cp "$CLASSPATH" $JVMFLAGS $ZOOMAIN "$ZOOCFG" > "$_ZOO_DAEMON_OUT" 2>&1 < /dev/null &
-    if [ $? -eq 0 ]
-    then
-      case "$OSTYPE" in
+    nohup "$JAVA" "-Dzookeeper.log.dir=$ZOO_LOG_DIR" \
+      "-Dzookeeper.log.file=$ZOO_LOG_FILE" \
+      -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError='kill -9 %p' \
+      "${flags[@]}" "${ZOOMAIN[@]}" "$ZOOCFG" &>"$_ZOO_DAEMON_OUT" </dev/null &
+    case "$OSTYPE" in
       *solaris*)
       *solaris*)
-        /bin/echo "${!}\\c" > "$ZOOPIDFILE"
+        /bin/echo "${!}\\c" >"$ZOOPIDFILE"
         ;;
         ;;
       aix*)
       aix*)
-        /bin/echo "$!\c" > "$ZOOPIDFILE"
+        /bin/echo "$!\c" >"$ZOOPIDFILE"
         ;;
         ;;
       *)
       *)
-        /bin/echo -n $! > "$ZOOPIDFILE"
+        echo -n $! >"$ZOOPIDFILE"
         ;;
         ;;
-      esac
-      if [ $? -eq 0 ];
-      then
-        sleep 1
-        pid=$(cat "${ZOOPIDFILE}")
-        if ps -p "${pid}" > /dev/null 2>&1; then
-          echo STARTED
-        else
-          echo FAILED TO START
-          exit 1
-        fi
+    esac
+    # this checks the exit code of the echo statements to verify the PID was written
+    # shellcheck disable=SC2320,SC2181
+    if [[ $? -eq 0 ]]; then
+      sleep 1
+      pid=$(cat "$ZOOPIDFILE")
+      if ps -p "$pid" &>/dev/null; then
+        echo STARTED
       else
       else
-        echo FAILED TO WRITE PID
+        echo FAILED TO START
         exit 1
         exit 1
       fi
       fi
     else
     else
-      echo SERVER DID NOT START
+      echo FAILED TO WRITE PID
       exit 1
       exit 1
     fi
     fi
     ;;
     ;;
-start-foreground)
+  start-foreground)
     ZOO_CMD=(exec "$JAVA")
     ZOO_CMD=(exec "$JAVA")
-    if [ "${ZOO_NOEXEC}" != "" ]; then
+    if [[ -n $ZOO_NOEXEC ]]; then
       ZOO_CMD=("$JAVA")
       ZOO_CMD=("$JAVA")
     fi
     fi
-    "${ZOO_CMD[@]}" $ZOO_DATADIR_AUTOCREATE "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" \
-    "-Dzookeeper.log.file=${ZOO_LOG_FILE}" \
-    -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError='kill -9 %p' \
-    -cp "$CLASSPATH" $JVMFLAGS $ZOOMAIN "$ZOOCFG"
+    "${ZOO_CMD[@]}" "-Dzookeeper.log.dir=$ZOO_LOG_DIR" \
+      "-Dzookeeper.log.file=$ZOO_LOG_FILE" \
+      -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError='kill -9 %p' \
+      "${flags[@]}" "${ZOOMAIN[@]}" "$ZOOCFG"
     ;;
     ;;
-print-cmd)
-    echo "\"$JAVA\" $ZOO_DATADIR_AUTOCREATE -Dzookeeper.log.dir=\"${ZOO_LOG_DIR}\" \
-    -Dzookeeper.log.file=\"${ZOO_LOG_FILE}\" \
+  print-classpath)
+    echo "CLASSPATH=$CLASSPATH"
+    ;;
+  print-cmd)
+    echo "\"$JAVA\" -Dzookeeper.log.dir=\"$ZOO_LOG_DIR\" \
+    -Dzookeeper.log.file=\"$ZOO_LOG_FILE\" \
     -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError='kill -9 %p' \
     -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError='kill -9 %p' \
-    -cp \"$CLASSPATH\" $JVMFLAGS $ZOOMAIN \"$ZOOCFG\" > \"$_ZOO_DAEMON_OUT\" 2>&1 < /dev/null"
+    $(for x in "${flags[@]}"; do echo "\"$x\""; done | paste -sd' ') \
+    $(for x in "${ZOOMAIN[@]}"; do echo "\"$x\""; done | paste -sd' ') \
+    \"$ZOOCFG\" &>\"$_ZOO_DAEMON_OUT\" </dev/null"
     ;;
     ;;
-stop)
+  stop)
     echo -n "Stopping zookeeper ... "
     echo -n "Stopping zookeeper ... "
-    if [ ! -f "$ZOOPIDFILE" ]
-    then
+    if [[ ! -f $ZOOPIDFILE ]]; then
       echo "no zookeeper to stop (could not find file $ZOOPIDFILE)"
       echo "no zookeeper to stop (could not find file $ZOOPIDFILE)"
     else
     else
-      $KILL $(cat "$ZOOPIDFILE")
+      $KILL "$(cat "$ZOOPIDFILE")"
       rm "$ZOOPIDFILE"
       rm "$ZOOPIDFILE"
       sleep 1
       sleep 1
       echo STOPPED
       echo STOPPED
     fi
     fi
     exit 0
     exit 0
     ;;
     ;;
-version)
-    ZOOMAIN=org.apache.zookeeper.version.VersionInfoMain
-    $JAVA -cp "$CLASSPATH" $ZOOMAIN 2> /dev/null
+  version)
+    ZOOMAIN=("org.apache.zookeeper.version.VersionInfoMain")
+    $JAVA "${ZOOMAIN[@]}" 2>/dev/null
     ;;
     ;;
-restart)
+  restart)
     shift
     shift
-    "$0" stop ${@}
+    "$0" stop "$@"
     sleep 3
     sleep 3
-    "$0" start ${@}
+    "$0" start "$@"
     ;;
     ;;
-status)
+  status)
     # -q is necessary on some versions of linux where nc returns too quickly, and no stat result is output
     # -q is necessary on some versions of linux where nc returns too quickly, and no stat result is output
     isSSL="false"
     isSSL="false"
-    clientPortAddress=`$GREP "^[[:space:]]*clientPortAddress[^[:alpha:]]" "$ZOOCFG" | sed -e 's/.*=//'`
-    if ! [ $clientPortAddress ]
-    then
-	      clientPortAddress="localhost"
+    clientPortAddress=$($GREP "^[[:space:]]*clientPortAddress[^[:alpha:]]" "$ZOOCFG" | sed -e 's/.*=//')
+    if [[ -z $clientPortAddress ]]; then
+      clientPortAddress="localhost"
     fi
     fi
-    clientPort=`$GREP "^[[:space:]]*clientPort[^[:alpha:]]" "$ZOOCFG" | sed -e 's/.*=//'`
-    if ! [[ "$clientPort"  =~ ^[0-9]+$ ]]
-    then
-      dataDir=`$GREP "^[[:space:]]*dataDir" "$ZOOCFG" | sed -e 's/.*=//'`
-      myid=`cat "$dataDir/myid" 2> /dev/null`
-      if ! [[ "$myid" =~ ^[0-9]+$ ]] ; then
+    clientPort=$($GREP "^[[:space:]]*clientPort[^[:alpha:]]" "$ZOOCFG" | sed -e 's/.*=//')
+    if ! [[ $clientPort =~ ^[0-9]+$ ]]; then
+      dataDir=$($GREP "^[[:space:]]*dataDir" "$ZOOCFG" | sed -e 's/.*=//')
+      myid=$(cat "$dataDir/myid" 2>/dev/null)
+      if ! [[ $myid =~ ^[0-9]+$ ]]; then
         echo "myid could not be determined, will not able to locate clientPort in the server configs."
         echo "myid could not be determined, will not able to locate clientPort in the server configs."
       else
       else
-        clientPortAndAddress=`$GREP "^[[:space:]]*server.$myid=.*;.*" "$ZOOCFG" | sed -e 's/.*=//' | sed -e 's/.*;//'`
-        if [ ! "$clientPortAndAddress" ] ; then
+        clientPortAndAddress=$($GREP "^[[:space:]]*server.$myid=.*;.*" "$ZOOCFG" | sed -e 's/.*=//' | sed -e 's/.*;//')
+        if [[ -z $clientPortAndAddress ]]; then
           echo "Client port not found in static config file. Looking in dynamic config file."
           echo "Client port not found in static config file. Looking in dynamic config file."
-          dynamicConfigFile=`$GREP "^[[:space:]]*dynamicConfigFile" "$ZOOCFG" | sed -e 's/.*=//'`
-          clientPortAndAddress=`$GREP "^[[:space:]]*server.$myid=.*;.*" "$dynamicConfigFile" | sed -e 's/.*=//' | sed -e 's/.*;//'`
+          dynamicConfigFile=$($GREP "^[[:space:]]*dynamicConfigFile" "$ZOOCFG" | sed -e 's/.*=//')
+          clientPortAndAddress=$($GREP "^[[:space:]]*server.$myid=.*;.*" "$dynamicConfigFile" | sed -e 's/.*=//' | sed -e 's/.*;//')
         fi
         fi
-        if [ ! "$clientPortAndAddress" ] ; then
+        if [[ -z $clientPortAndAddress ]]; then
           echo "Client port not found in the server configs"
           echo "Client port not found in the server configs"
         else
         else
-          if [[ "$clientPortAndAddress" =~ ^.*:[0-9]+ ]] ; then
-            if [[ "$clientPortAndAddress" =~ \[.*\]:[0-9]+ ]] ; then
-              # Extracts address from address:port for example extracts 127::1 from "[127::1]:2181"
-              clientPortAddress=`echo "$clientPortAndAddress" | sed -e 's|\[||' | sed -e 's|\]:.*||'`
-            else
-              clientPortAddress=`echo "$clientPortAndAddress" | sed -e 's/:.*//'`
-            fi
+          # Extracts address and port from address:port, even if address contains optional square braces
+          # For example, this extracts the address 127::1 and the port 2181 from "[127::1]:2181"
+          if [[ $clientPortAndAddress =~ ^\[?([^\]]*)\]?:([0-9]+) ]]; then
+            clientPortAddress=${BASH_REMATCH[1]}
+            clientPort=${BASH_REMATCH[2]}
+          elif [[ $clientPortAndAddress =~ ^[0-9]+$ ]]; then
+            clientPort=$clientPortAndAddress
           fi
           fi
-          clientPort=`echo "$clientPortAndAddress" | sed -e 's/.*://'`
         fi
         fi
       fi
       fi
     fi
     fi
-    if [ ! "$clientPort" ] ; then
+    if [[ -z $clientPort ]]; then
       echo "Client port not found. Looking for secureClientPort in the static config."
       echo "Client port not found. Looking for secureClientPort in the static config."
-      secureClientPort=`$GREP "^[[:space:]]*secureClientPort[^[:alpha:]]" "$ZOOCFG" | sed -e 's/.*=//'`
-      if [ "$secureClientPort" ] ; then
+      secureClientPort=$($GREP "^[[:space:]]*secureClientPort[^[:alpha:]]" "$ZOOCFG" | sed -e 's/.*=//')
+      if [[ -n $secureClientPort ]]; then
         isSSL="true"
         isSSL="true"
         clientPort=$secureClientPort
         clientPort=$secureClientPort
-        clientPortAddress=`$GREP "^[[:space:]]*secureClientPortAddress[^[:alpha:]]" "$ZOOCFG" | sed -e 's/.*=//'`
-        if ! [ $clientPortAddress ]
-        then
-            clientPortAddress="localhost"
+        clientPortAddress=$($GREP "^[[:space:]]*secureClientPortAddress[^[:alpha:]]" "$ZOOCFG" | sed -e 's/.*=//')
+        if [[ -z $clientPortAddress ]]; then
+          clientPortAddress="localhost"
         fi
         fi
       else
       else
         echo "Unable to find either secure or unsecure client port in any configs. Terminating."
         echo "Unable to find either secure or unsecure client port in any configs. Terminating."
@@ -290,31 +282,31 @@ status)
       fi
       fi
     fi
     fi
     echo "Client port found: $clientPort. Client address: $clientPortAddress. Client SSL: $isSSL."
     echo "Client port found: $clientPort. Client address: $clientPortAddress. Client SSL: $isSSL."
-    STAT=`"$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.log.file=${ZOO_LOG_FILE}" \
-          -cp "$CLASSPATH" $CLIENT_JVMFLAGS $JVMFLAGS org.apache.zookeeper.client.FourLetterWordMain \
-          $clientPortAddress $clientPort srvr $isSSL 2> /dev/null    \
-          | $GREP Mode`
-    if [ "x$STAT" = "x" ]
-    then
-      if [ "$isSSL" = "true" ] ; then
+    STAT=$("$JAVA" "-Dzookeeper.log.dir=$ZOO_LOG_DIR" "-Dzookeeper.log.file=$ZOO_LOG_FILE" \
+      "${clientflags[@]}" "${flags[@]}" org.apache.zookeeper.client.FourLetterWordMain \
+      "$clientPortAddress" "$clientPort" srvr "$isSSL" 2>/dev/null |
+      $GREP Mode)
+    if [[ -z $STAT ]]; then
+      if [[ $isSSL == "true" ]]; then
         echo " "
         echo " "
         echo "Note: We used secureClientPort ($secureClientPort) to establish connection, but we failed. The 'status'"
         echo "Note: We used secureClientPort ($secureClientPort) to establish connection, but we failed. The 'status'"
         echo "  command establishes a client connection to the server to execute diagnostic commands. Please make sure you"
         echo "  command establishes a client connection to the server to execute diagnostic commands. Please make sure you"
         echo "  provided all the Client SSL connection related parameters in the CLIENT_JVMFLAGS environment variable! E.g.:"
         echo "  provided all the Client SSL connection related parameters in the CLIENT_JVMFLAGS environment variable! E.g.:"
-        echo "  CLIENT_JVMFLAGS=\"-Dzookeeper.clientCnxnSocket=org.apache.zookeeper.ClientCnxnSocketNetty"
+        echo '  CLIENT_JVMFLAGS="-Dzookeeper.clientCnxnSocket=org.apache.zookeeper.ClientCnxnSocketNetty'
         echo "  -Dzookeeper.ssl.trustStore.location=/tmp/clienttrust.jks -Dzookeeper.ssl.trustStore.password=password"
         echo "  -Dzookeeper.ssl.trustStore.location=/tmp/clienttrust.jks -Dzookeeper.ssl.trustStore.password=password"
         echo "  -Dzookeeper.ssl.keyStore.location=/tmp/client.jks -Dzookeeper.ssl.keyStore.password=password"
         echo "  -Dzookeeper.ssl.keyStore.location=/tmp/client.jks -Dzookeeper.ssl.keyStore.password=password"
-        echo "  -Dzookeeper.client.secure=true\" ./zkServer.sh status"
+        echo '  -Dzookeeper.client.secure=true" ./zkServer.sh status'
         echo " "
         echo " "
       fi
       fi
       echo "Error contacting service. It is probably not running."
       echo "Error contacting service. It is probably not running."
       exit 1
       exit 1
     else
     else
-      echo $STAT
+      echo "$STAT"
       exit 0
       exit 0
     fi
     fi
     ;;
     ;;
-*)
+  *)
     echo "Usage: $0 [--config <conf-dir>] {start|start-foreground|stop|version|restart|status|print-cmd}" >&2
     echo "Usage: $0 [--config <conf-dir>] {start|start-foreground|stop|version|restart|status|print-cmd}" >&2
+    ;;
 
 
 esac
 esac

+ 26 - 21
bin/zkSnapShotToolkit.sh

@@ -1,19 +1,22 @@
-#!/usr/bin/env bash
-
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
+#! /usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
 
 #
 #
 # If this scripted is run out of /usr/bin or some other system bin directory
 # If this scripted is run out of /usr/bin or some other system bin directory
@@ -23,16 +26,18 @@
 
 
 # use POSIX interface, symlink is followed automatically
 # use POSIX interface, symlink is followed automatically
 ZOOBIN="${BASH_SOURCE-$0}"
 ZOOBIN="${BASH_SOURCE-$0}"
-ZOOBIN="$(dirname "${ZOOBIN}")"
-ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)"
+ZOOBIN="$(dirname "$ZOOBIN")"
+ZOOBINDIR="$(cd "$ZOOBIN" && pwd)"
 
 
-if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then
+if [[ -e "$ZOOBIN/../libexec/zkEnv.sh" ]]; then
+  # shellcheck source=bin/zkEnv.sh
   . "$ZOOBINDIR"/../libexec/zkEnv.sh
   . "$ZOOBINDIR"/../libexec/zkEnv.sh
 else
 else
+  # shellcheck source=bin/zkEnv.sh
   . "$ZOOBINDIR"/zkEnv.sh
   . "$ZOOBINDIR"/zkEnv.sh
 fi
 fi
 
 
-"$JAVA" -cp "$CLASSPATH" $JVMFLAGS \
-     org.apache.zookeeper.server.SnapshotFormatter "$@"
-
-
+# shellcheck disable=SC2206
+flags=($JVMFLAGS)
+"$JAVA" "${flags[@]}" \
+  org.apache.zookeeper.server.SnapshotFormatter "$@"

+ 26 - 19
bin/zkSnapshotComparer.sh

@@ -1,19 +1,22 @@
-#!/usr/bin/env bash
-
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
+#! /usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
 
 #
 #
 # If this scripted is run out of /usr/bin or some other system bin directory
 # If this scripted is run out of /usr/bin or some other system bin directory
@@ -23,14 +26,18 @@
 
 
 # use POSIX interface, symlink is followed automatically
 # use POSIX interface, symlink is followed automatically
 ZOOBIN="${BASH_SOURCE-$0}"
 ZOOBIN="${BASH_SOURCE-$0}"
-ZOOBIN="$(dirname "${ZOOBIN}")"
-ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)"
+ZOOBIN="$(dirname "$ZOOBIN")"
+ZOOBINDIR="$(cd "$ZOOBIN" && pwd)"
 
 
-if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then
+if [[ -e "$ZOOBIN/../libexec/zkEnv.sh" ]]; then
+  # shellcheck source=bin/zkEnv.sh
   . "$ZOOBINDIR"/../libexec/zkEnv.sh
   . "$ZOOBINDIR"/../libexec/zkEnv.sh
 else
 else
+  # shellcheck source=bin/zkEnv.sh
   . "$ZOOBINDIR"/zkEnv.sh
   . "$ZOOBINDIR"/zkEnv.sh
 fi
 fi
 
 
-"$JAVA" -cp "$CLASSPATH" $JVMFLAGS \
-     org.apache.zookeeper.server.SnapshotComparer "$@"
+# shellcheck disable=SC2206
+flags=($JVMFLAGS)
+"$JAVA" "${flags[@]}" \
+  org.apache.zookeeper.server.SnapshotComparer "$@"

+ 26 - 22
bin/zkSnapshotRecursiveSummaryToolkit.sh

@@ -1,19 +1,22 @@
-#!/usr/bin/env bash
-
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
+#! /usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
 
 #
 #
 # If this scripted is run out of /usr/bin or some other system bin directory
 # If this scripted is run out of /usr/bin or some other system bin directory
@@ -23,17 +26,18 @@
 
 
 # use POSIX interface, symlink is followed automatically
 # use POSIX interface, symlink is followed automatically
 ZOOBIN="${BASH_SOURCE-$0}"
 ZOOBIN="${BASH_SOURCE-$0}"
-ZOOBIN="$(dirname "${ZOOBIN}")"
-ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)"
+ZOOBIN="$(dirname "$ZOOBIN")"
+ZOOBINDIR="$(cd "$ZOOBIN" && pwd)"
 
 
-if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then
-  # shellcheck source=/bin/zkEnv.sh
+if [[ -e "$ZOOBIN/../libexec/zkEnv.sh" ]]; then
+  # shellcheck source=bin/zkEnv.sh
   . "$ZOOBINDIR"/../libexec/zkEnv.sh
   . "$ZOOBINDIR"/../libexec/zkEnv.sh
 else
 else
+  # shellcheck source=bin/zkEnv.sh
   . "$ZOOBINDIR"/zkEnv.sh
   . "$ZOOBINDIR"/zkEnv.sh
 fi
 fi
 
 
-"$JAVA" -cp "$CLASSPATH" $JVMFLAGS \
-     org.apache.zookeeper.server.SnapshotRecursiveSummary "$@"
-
-
+# shellcheck disable=SC2206
+flags=($JVMFLAGS)
+"$JAVA" "${flags[@]}" \
+  org.apache.zookeeper.server.SnapshotRecursiveSummary "$@"

+ 26 - 21
bin/zkTxnLogToolkit.sh

@@ -1,19 +1,22 @@
-#!/usr/bin/env bash
-
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
+#! /usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
 
 #
 #
 # If this scripted is run out of /usr/bin or some other system bin directory
 # If this scripted is run out of /usr/bin or some other system bin directory
@@ -23,16 +26,18 @@
 
 
 # use POSIX interface, symlink is followed automatically
 # use POSIX interface, symlink is followed automatically
 ZOOBIN="${BASH_SOURCE-$0}"
 ZOOBIN="${BASH_SOURCE-$0}"
-ZOOBIN="$(dirname "${ZOOBIN}")"
-ZOOBINDIR="$(cd "${ZOOBIN}"; pwd)"
+ZOOBIN="$(dirname "$ZOOBIN")"
+ZOOBINDIR="$(cd "$ZOOBIN" && pwd)"
 
 
-if [ -e "$ZOOBIN/../libexec/zkEnv.sh" ]; then
+if [[ -e "$ZOOBIN/../libexec/zkEnv.sh" ]]; then
+  # shellcheck source=bin/zkEnv.sh
   . "$ZOOBINDIR"/../libexec/zkEnv.sh
   . "$ZOOBINDIR"/../libexec/zkEnv.sh
 else
 else
+  # shellcheck source=bin/zkEnv.sh
   . "$ZOOBINDIR"/zkEnv.sh
   . "$ZOOBINDIR"/zkEnv.sh
 fi
 fi
 
 
-"$JAVA" -cp "$CLASSPATH" $JVMFLAGS \
-     org.apache.zookeeper.server.persistence.TxnLogToolkit "$@"
-
-
+# shellcheck disable=SC2206
+flags=($JVMFLAGS)
+"$JAVA" "${flags[@]}" \
+  org.apache.zookeeper.server.persistence.TxnLogToolkit "$@"

+ 37 - 35
dev/docker/run.sh

@@ -1,52 +1,55 @@
-#!/bin/bash
-
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
+#! /usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
 
 set -e -x -u
 set -e -x -u
 
 
-SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
 
 
 export IMAGE_NAME="zookeeper/dev"
 export IMAGE_NAME="zookeeper/dev"
 
 
-pushd ${SCRIPT_DIR}
+pushd "$SCRIPT_DIR"
 
 
-docker build --rm=true -t ${IMAGE_NAME} .
+docker build --rm=true -t "$IMAGE_NAME" .
 
 
 popd
 popd
 
 
-if [ "$(uname -s)" == "Linux" ]; then
+if [[ "$(uname -s)" == "Linux" ]]; then
   USER_NAME=${SUDO_USER:=$USER}
   USER_NAME=${SUDO_USER:=$USER}
-  USER_ID=$(id -u "${USER_NAME}")
-  GROUP_ID=$(id -g "${USER_NAME}")
+  USER_ID=$(id -u "$USER_NAME")
+  GROUP_ID=$(id -g "$USER_NAME")
   LOCAL_HOME=$(realpath ~)
   LOCAL_HOME=$(realpath ~)
 else # boot2docker uid and gid
 else # boot2docker uid and gid
   USER_NAME=$USER
   USER_NAME=$USER
   USER_ID=1000
   USER_ID=1000
   GROUP_ID=50
   GROUP_ID=50
-  LOCAL_HOME="/Users/${USER_NAME}"
+  LOCAL_HOME="/Users/$USER_NAME"
 fi
 fi
 
 
-docker build -t "${IMAGE_NAME}-${USER_NAME}" - <<UserSpecificDocker
-FROM ${IMAGE_NAME}
-RUN groupadd --non-unique -g ${GROUP_ID} ${USER_NAME} && \
-  useradd -g ${GROUP_ID} -u ${USER_ID} -k /root -m ${USER_NAME}
-ENV  HOME /home/${USER_NAME}
+docker build -t "$IMAGE_NAME-$USER_NAME" - <<UserSpecificDocker
+FROM $IMAGE_NAME
+RUN groupadd --non-unique -g $GROUP_ID $USER_NAME && \
+  useradd -g $GROUP_ID -u $USER_ID -k /root -m $USER_NAME
+ENV  HOME /home/$USER_NAME
 UserSpecificDocker
 UserSpecificDocker
 
 
-ZOOKEEPER_ROOT=${SCRIPT_DIR}/../..
+ZOOKEEPER_ROOT="$SCRIPT_DIR/../.."
 
 
 CMD="
 CMD="
 echo
 echo
@@ -57,16 +60,15 @@ echo
 bash
 bash
 "
 "
 
 
-pushd ${ZOOKEEPER_ROOT}
+pushd "$ZOOKEEPER_ROOT"
 
 
 docker run -i -t \
 docker run -i -t \
   --rm=true \
   --rm=true \
-  -w ${ZOOKEEPER_ROOT} \
-  -u "${USER}" \
-  -v "$(realpath $ZOOKEEPER_ROOT):${ZOOKEEPER_ROOT}" \
-  -v "${LOCAL_HOME}:/home/${USER_NAME}" \
-  ${IMAGE_NAME}-${USER_NAME} \
-  bash -c "${CMD}"
+  -w "$ZOOKEEPER_ROOT" \
+  -u "$USER" \
+  -v "$(realpath "$ZOOKEEPER_ROOT"):$ZOOKEEPER_ROOT" \
+  -v "$LOCAL_HOME:/home/$USER_NAME" \
+  "$IMAGE_NAME-$USER_NAME" \
+  bash -c "$CMD"
 
 
 popd
 popd
-

+ 1 - 0
pom.xml

@@ -1063,6 +1063,7 @@
       <plugin>
       <plugin>
         <groupId>org.apache.rat</groupId>
         <groupId>org.apache.rat</groupId>
         <artifactId>apache-rat-plugin</artifactId>
         <artifactId>apache-rat-plugin</artifactId>
+        <version>0.15</version>
         <configuration>
         <configuration>
           <excludes>
           <excludes>
             <exclude>**/README.md</exclude>
             <exclude>**/README.md</exclude>

+ 29 - 0
tools/ci/install-shfmt.sh

@@ -0,0 +1,29 @@
+#! /usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Install shfmt tool to search for and optionally format bash scripts
+# This is useful for other CI tools to run ShellCheck and shfmt to format
+
+set -e
+set -x
+
+shfmt_version=3.4.3
+sudo wget "https://github.com/mvdan/sh/releases/download/v${shfmt_version}/shfmt_v${shfmt_version}_linux_amd64" -O /usr/local/bin/shfmt &&
+  sudo chmod +x /usr/local/bin/shfmt

+ 28 - 0
tools/ci/run-shellcheck.sh

@@ -0,0 +1,28 @@
+#! /usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Run ShellCheck on all bash scripts
+
+set -e
+
+mapfile -t filestocheck < <(shfmt -f .)
+
+set -x
+shellcheck -P SCRIPTDIR -x "${filestocheck[@]}"

+ 26 - 0
tools/ci/run-shfmt.sh

@@ -0,0 +1,26 @@
+#! /usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Check formatting of all bash scripts
+
+set -e
+set -x
+
+shfmt -ln bash -l -d -i 2 -ci -s .

+ 24 - 21
tools/sonar/code-coverage.sh

@@ -1,4 +1,5 @@
-#!/usr/bin/env bash
+#! /usr/bin/env bash
+#
 # Licensed to the Apache Software Foundation (ASF) under one
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information
 # distributed with this work for additional information
@@ -7,13 +8,15 @@
 # "License"); you may not use this file except in compliance
 # "License"); you may not use this file except in compliance
 # with the License.  You may obtain a copy of the License at
 # with the License.  You may obtain a copy of the License at
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
 
 usage() {
 usage() {
   echo
   echo
@@ -34,7 +37,7 @@ usage() {
 
 
 execute() {
 execute() {
   SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
   SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
-  MAIN_POM="${SCRIPT_DIR}/../../pom.xml"
+  MAIN_POM="$SCRIPT_DIR/../../pom.xml"
 
 
   mvn -B -e -Pclover -f "$MAIN_POM" clean install -DskipTests -DskipShade
   mvn -B -e -Pclover -f "$MAIN_POM" clean install -DskipTests -DskipShade
 
 
@@ -43,7 +46,7 @@ execute() {
   mvn -B -e -Pclover -f "$MAIN_POM" clover:aggregate clover:clover
   mvn -B -e -Pclover -f "$MAIN_POM" clover:aggregate clover:clover
 
 
   # If the required parameters are given, the code coverage results are uploaded to the SonarQube Server
   # If the required parameters are given, the code coverage results are uploaded to the SonarQube Server
-  if [ -n "$SONAR_LOGIN" ] && [ -n "$SONAR_PROJECT_KEY" ] && [ -n "$SONAR_URL" ]; then
+  if [[ -n $SONAR_LOGIN ]] && [[ -n $SONAR_PROJECT_KEY ]] && [[ -n $SONAR_URL ]]; then
     mvn -B -e -Pclover -f "$MAIN_POM" sonar:sonar -Dsonar.clover.reportPath=./target/clover/clover.xml \
     mvn -B -e -Pclover -f "$MAIN_POM" sonar:sonar -Dsonar.clover.reportPath=./target/clover/clover.xml \
       -Dsonar.host.url="$SONAR_URL" -Dsonar.login="$SONAR_LOGIN" -Dsonar.projectKey="$SONAR_PROJECT_KEY" -Dsonar.projectName="$SONAR_PROJECT_NAME"
       -Dsonar.host.url="$SONAR_URL" -Dsonar.login="$SONAR_LOGIN" -Dsonar.projectKey="$SONAR_PROJECT_KEY" -Dsonar.projectName="$SONAR_PROJECT_NAME"
   fi
   fi
@@ -51,18 +54,18 @@ execute() {
 
 
 while getopts ":u:l:k:n:h" option; do
 while getopts ":u:l:k:n:h" option; do
   case $option in
   case $option in
-  u) SONAR_URL=${OPTARG:-} ;;
-  l) SONAR_LOGIN=${OPTARG:-} ;;
-  k) SONAR_PROJECT_KEY=${OPTARG:-} ;;
-  n) SONAR_PROJECT_NAME=${OPTARG:-} ;;
-  h) # Display usage
-    usage
-    exit
-    ;;
-  \?) # Invalid option
-    echo "Error: Invalid option"
-    exit
-    ;;
+    u) SONAR_URL=${OPTARG:-} ;;
+    l) SONAR_LOGIN=${OPTARG:-} ;;
+    k) SONAR_PROJECT_KEY=${OPTARG:-} ;;
+    n) SONAR_PROJECT_NAME=${OPTARG:-} ;;
+    h) # Display usage
+      usage
+      exit
+      ;;
+    \?) # Invalid option
+      echo "Error: Invalid option"
+      exit
+      ;;
   esac
   esac
 done
 done
 
 

+ 21 - 20
zookeeper-client/zookeeper-client-c/ssl/gencerts.sh

@@ -1,19 +1,22 @@
-#!/usr/bin/env bash
-
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
+#! /usr/bin/env bash
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
 
 #
 #
 # This script cleans up old transaction logs and snapshots
 # This script cleans up old transaction logs and snapshots
@@ -25,12 +28,11 @@
 # relative to the canonical path of this script.
 # relative to the canonical path of this script.
 #
 #
 
 
-
 # determining the domain name in the certificates:
 # determining the domain name in the certificates:
 # - use the first commandline argument, if present
 # - use the first commandline argument, if present
 # - if not, then use the fully qualified domain name
 # - if not, then use the fully qualified domain name
 # - if `hostname` command fails, fall back to zookeeper.apache.org
 # - if `hostname` command fails, fall back to zookeeper.apache.org
-FQDN=`hostname -f`
+FQDN=$(hostname -f)
 FQDN=${1:-$FQDN}
 FQDN=${1:-$FQDN}
 FQDN=${FQDN:-"zookeeper.apache.org"}
 FQDN=${FQDN:-"zookeeper.apache.org"}
 
 
@@ -39,7 +41,7 @@ openssl genrsa -out rootkey.pem 2048
 
 
 #Generate the root Cert
 #Generate the root Cert
 openssl req -x509 -new -key rootkey.pem -out root.crt -config <(
 openssl req -x509 -new -key rootkey.pem -out root.crt -config <(
-cat <<-EOF
+  cat <<-EOF
 [ req ]
 [ req ]
 default_bits = 2048
 default_bits = 2048
 prompt = no
 prompt = no
@@ -61,7 +63,7 @@ openssl genrsa -out clientkey.pem 2048
 
 
 #Generate Client Cert
 #Generate Client Cert
 openssl req -new -key clientkey.pem -out client.csr -config <(
 openssl req -new -key clientkey.pem -out client.csr -config <(
-cat <<-EOF
+  cat <<-EOF
 [ req ]
 [ req ]
 default_bits = 2048
 default_bits = 2048
 prompt = no
 prompt = no
@@ -92,7 +94,7 @@ openssl genrsa -out serverkey.pem 2048
 
 
 #Generate Server Cert
 #Generate Server Cert
 openssl req -new -key serverkey.pem -out server.csr -config <(
 openssl req -new -key serverkey.pem -out server.csr -config <(
-cat <<-EOF
+  cat <<-EOF
 [ req ]
 [ req ]
 default_bits = 2048
 default_bits = 2048
 prompt = no
 prompt = no
@@ -116,7 +118,6 @@ openssl pkcs12 -export -in server.crt -inkey serverkey.pem -out server.pkcs12 -p
 # Import Keystore in JKS
 # Import Keystore in JKS
 keytool -importkeystore -srckeystore server.pkcs12 -destkeystore server.jks -srcstoretype pkcs12 -srcstorepass password -deststorepass password
 keytool -importkeystore -srckeystore server.pkcs12 -destkeystore server.jks -srcstoretype pkcs12 -srcstorepass password -deststorepass password
 
 
-
 keytool -importcert -keystore server.jks -file root.crt -storepass password -noprompt
 keytool -importcert -keystore server.jks -file root.crt -storepass password -noprompt
 
 
 keytool -importcert -alias ca -file root.crt -keystore clienttrust.jks -storepass password -noprompt
 keytool -importcert -alias ca -file root.crt -keystore clienttrust.jks -storepass password -noprompt

+ 127 - 162
zookeeper-client/zookeeper-client-c/tests/zkServer.sh

@@ -1,4 +1,4 @@
-#!/bin/bash
+#! /usr/bin/env bash
 #
 #
 # Licensed to the Apache Software Foundation (ASF) under one
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # or more contributor license agreements.  See the NOTICE file
@@ -8,13 +8,15 @@
 # "License"); you may not use this file except in compliance
 # "License"); you may not use this file except in compliance
 # with the License.  You may obtain a copy of the License at
 # with the License.  You may obtain a copy of the License at
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
 
 # This is the port where zookeeper server runs on.
 # This is the port where zookeeper server runs on.
 ZOOPORT=${ZOOPORT:-"22181"}
 ZOOPORT=${ZOOPORT:-"22181"}
@@ -24,239 +26,202 @@ ZKMAXCNXNS=${ZKMAXCNXNS:-"100"}
 
 
 EXTRA_JVM_ARGS=${EXTRA_JVM_ARGS:-""}
 EXTRA_JVM_ARGS=${EXTRA_JVM_ARGS:-""}
 
 
-if [ "x$1" == "x" ]
-then
-    echo "USAGE: $0 startClean|start|startCleanReadOnly|startRequireSASLAuth [jaasConf] [readOnly]|stop"
-    exit 2
+if [[ -z $1 ]]; then
+  echo "USAGE: $0 startClean|start|startCleanReadOnly|startRequireSASLAuth [jaasConf] [readOnly]|stop"
+  exit 2
 fi
 fi
 
 
-
-
-
 # =====
 # =====
 # ===== cleanup old executions
 # ===== cleanup old executions
 # =====
 # =====
 
 
-case "`uname`" in
-    CYGWIN*) cygwin=true ;;
-    *) cygwin=false ;;
+case "$(uname)" in
+  CYGWIN* | MINGW*) cygwin=true ;;
+  *) cygwin=false ;;
 esac
 esac
 
 
-
-if $cygwin
-then
-    # cygwin has a "kill" in the shell itself, gets confused
-    KILL=/bin/kill
+if $cygwin; then
+  # cygwin has a "kill" in the shell itself, gets confused
+  KILL='/bin/kill'
 else
 else
-    KILL=kill
+  KILL='kill'
 fi
 fi
 
 
 # Make sure nothing is left over from before
 # Make sure nothing is left over from before
-if [ -r "/tmp/zk.pid" ]
-then
-pid=`cat /tmp/zk.pid`
-$KILL -9 $pid
-rm -f /tmp/zk.pid
+if [[ -r "/tmp/zk.pid" ]]; then
+  pid=$(cat /tmp/zk.pid)
+  $KILL -9 "$pid"
+  rm -f /tmp/zk.pid
 fi
 fi
 
 
-if [ -r "${base_dir}/build/tmp/zk.pid" ]
-then
-pid=`cat "${base_dir}/build/tmp/zk.pid"`
-$KILL -9 $pid
-rm -f "${base_dir}/build/tmp/zk.pid"
+if [[ -r "$base_dir/build/tmp/zk.pid" ]]; then
+  pid=$(cat "$base_dir/build/tmp/zk.pid")
+  $KILL -9 "$pid"
+  rm -f "$base_dir/build/tmp/zk.pid"
 fi
 fi
 
 
 # [ZOOKEEPER-820] If lsof command is present, look for a process listening
 # [ZOOKEEPER-820] If lsof command is present, look for a process listening
-# on ZOOPORT and kill it. 
-which lsof &> /dev/null
-if [ $? -eq 0  ]
-then
-    pid=`lsof -i :$ZOOPORT | grep LISTEN | awk '{print $2}'`
-    if [ -n "$pid" ]
-    then
-        $KILL -9 $pid
-    fi
+# on ZOOPORT and kill it.
+if which lsof &>/dev/null; then
+  pid=$(lsof -i ":$ZOOPORT" | grep LISTEN | awk '{print $2}')
+  if [[ -n $pid ]]; then
+    $KILL -9 "$pid"
+  fi
 fi
 fi
 
 
-
-
 # =====
 # =====
 # ===== build classpath
 # ===== build classpath
 # =====
 # =====
 
 
-if [ "x${base_dir}" == "x" ]
-then
-zk_base="../../../"
+if [[ -z $base_dir ]]; then
+  zk_base="../../../"
 else
 else
-zk_base="${base_dir}"
+  zk_base="$base_dir"
 fi
 fi
 
 
-CLASSPATH="$CLASSPATH:${zk_base}/build/classes"
-CLASSPATH="$CLASSPATH:${zk_base}/conf"
-CLASSPATH="$CLASSPATH:${zk_base}/zookeeper-server/target/classes"
+CLASSPATH="$CLASSPATH:$zk_base/build/classes"
+CLASSPATH="$CLASSPATH:$zk_base/conf"
+CLASSPATH="$CLASSPATH:$zk_base/zookeeper-server/target/classes"
 
 
-for i in "${zk_base}"/build/lib/*.jar
-do
-    CLASSPATH="$CLASSPATH:$i"
+for i in "$zk_base"/build/lib/*.jar; do
+  CLASSPATH="$CLASSPATH:$i"
 done
 done
 
 
-for d in "${zk_base}"/zookeeper-server/target/lib/*.jar
-do
-    CLASSPATH="$d:$CLASSPATH"
+for d in "$zk_base"/zookeeper-server/target/lib/*.jar; do
+  CLASSPATH="$d:$CLASSPATH"
 done
 done
 
 
-for i in "${zk_base}"/zookeeper-server/src/main/resource/lib/*.jar
-do
-    CLASSPATH="$CLASSPATH:$i"
+for i in "$zk_base"/zookeeper-server/src/main/resource/lib/*.jar; do
+  CLASSPATH="$CLASSPATH:$i"
 done
 done
 
 
-CLASSPATH="$CLASSPATH:${CLOVER_HOME}/lib/clover*.jar"
+CLASSPATH="$CLASSPATH:$CLOVER_HOME/lib/clover*.jar"
 
 
-if $cygwin
-then
-    CLASSPATH=`cygpath -wp "$CLASSPATH"`
+if $cygwin; then
+  CLASSPATH=$(cygpath -wp "$CLASSPATH")
 fi
 fi
-
-
+export CLASSPATH
 
 
 # =====
 # =====
 # ===== initialize JVM arguments
 # ===== initialize JVM arguments
 # =====
 # =====
 
 
 read_only=
 read_only=
-PROPERTIES="$EXTRA_JVM_ARGS -Dzookeeper.extendedTypesEnabled=true -Dznode.container.checkIntervalMs=100"
-if [ "x$1" == "xstartRequireSASLAuth" ]
-then
-    PROPERTIES="-Dzookeeper.sessionRequireClientSASLAuth=true $PROPERTIES"
-    PROPERTIES="$PROPERTIES -Dzookeeper.authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider"
-    if [ "x$2" != "x" ]
-    then
-        PROPERTIES="$PROPERTIES -Djava.security.auth.login.config=$2"
-    fi
-    if [ "x$3" != "x" ]
-    then
-        PROPERTIES="-Dreadonlymode.enabled=true $PROPERTIES"
-        read_only=true
-    fi
-fi
-if [ "x$1" == "xstartCleanReadOnly" ]
-then
-    PROPERTIES="-Dreadonlymode.enabled=true $PROPERTIES"
+# shellcheck disable=SC2206
+PROPERTIES=($EXTRA_JVM_ARGS "-Dzookeeper.extendedTypesEnabled=true" "-Dznode.container.checkIntervalMs=100")
+if [[ $1 == "xstartRequireSASLAuth" ]]; then
+  PROPERTIES=("-Dzookeeper.sessionRequireClientSASLAuth=true" "${PROPERTIES[@]}"
+    "-Dzookeeper.authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider")
+  if [[ -n $2 ]]; then
+    PROPERTIES=("${PROPERTIES[@]}" "-Djava.security.auth.login.config=$2")
+  fi
+  if [[ -n $3 ]]; then
+    PROPERTIES=("-Dreadonlymode.enabled=true" "${PROPERTIES[@]}")
     read_only=true
     read_only=true
+  fi
+fi
+if [[ $1 == "startCleanReadOnly" ]]; then
+  PROPERTIES=("-Dreadonlymode.enabled=true" "${PROPERTIES[@]}")
+  read_only=true
 fi
 fi
-
-
 
 
 # =====
 # =====
 # ===== initialize data and test directories
 # ===== initialize data and test directories
 # =====
 # =====
 
 
-if [ "x${base_dir}" == "x" ]
-then
-    tmp_dir="/tmp"
-    tests_dir="tests"
+if [[ -z $base_dir ]]; then
+  tmp_dir="/tmp"
+  tests_dir="tests"
 else
 else
-    tmp_dir="${base_dir}/build/tmp"
-    tests_dir=${base_dir}/zookeeper-client/zookeeper-client-c/tests
+  tmp_dir="$base_dir/build/tmp"
+  tests_dir=$base_dir/zookeeper-client/zookeeper-client-c/tests
 fi
 fi
 
 
-
-
-
 # =====
 # =====
 # ===== start the ZooKeeper server
 # ===== start the ZooKeeper server
 # =====
 # =====
 
 
 case $1 in
 case $1 in
-start|startClean|startRequireSASLAuth|startCleanReadOnly)
+  start | startClean | startRequireSASLAuth | startCleanReadOnly)
 
 
-    if [ "x$1" == "xstartClean" ] || [ "x$1" == "xstartCleanReadOnly" ]
-    then
-        rm -rf "${tmp_dir}/zkdata"
+    if [[ $1 == "startClean" ]] || [[ $1 == "startCleanReadOnly" ]]; then
+      rm -rf "$tmp_dir/zkdata"
     fi
     fi
-    mkdir -p "${tmp_dir}/zkdata"
-
+    mkdir -p "$tmp_dir/zkdata"
 
 
     # ===== initialize certificates
     # ===== initialize certificates
     certs_dir="/tmp/certs"
     certs_dir="/tmp/certs"
-    rm -rf "${certs_dir}"
-    mkdir -p "${certs_dir}"
-    cp ${tests_dir}/../ssl/gencerts.sh "${certs_dir}/"  > /dev/null
-    cd ${certs_dir} > /dev/null
-    # GitHub is providing us hostnames with more than 64 characters now.
-    # And there are no cppunit tests do hostname verification currently,
-    # so we could set CN to arbitrary hostname for now.
-    ./gencerts.sh tests.zookeeper.apache.org > ./gencerts.stdout 2> ./gencerts.stderr
-    cd - > /dev/null
-
+    rm -rf "$certs_dir"
+    mkdir -p "$certs_dir"
+    cp "$tests_dir"/../ssl/gencerts.sh "$certs_dir/" >/dev/null
+    (
+      cd "$certs_dir" >/dev/null &&
+        # GitHub is providing us hostnames with more than 64 characters now.
+        # And there are no cppunit tests do hostname verification currently,
+        # so we could set CN to arbitrary hostname for now.
+        ./gencerts.sh tests.zookeeper.apache.org >./gencerts.stdout 2>./gencerts.stderr
+    )
 
 
     # ===== prepare the configs
     # ===== prepare the configs
-    sed "s#TMPDIR#${tmp_dir}#g;s#CERTDIR#${certs_dir}#g;s#MAXCLIENTCONNECTIONS#${ZKMAXCNXNS}#g;s#CLIENTPORT#${ZOOPORT}#g" ${tests_dir}/zoo.cfg > "${tmp_dir}/zoo.cfg"
-    if [ "x$read_only" != "x" ]
-    then
-        # we can put the new server to read-only mode by starting only a single instance of a three node server
-        echo "server.1=localhost:22881:33881" >> ${tmp_dir}/zoo.cfg
-        echo "server.2=localhost:22882:33882" >> ${tmp_dir}/zoo.cfg
-        echo "server.3=localhost:22883:33883" >> ${tmp_dir}/zoo.cfg
-        echo "1" > ${tmp_dir}/zkdata/myid
-        main_class="org.apache.zookeeper.server.quorum.QuorumPeerMain"
+    sed "s#TMPDIR#$tmp_dir#g;s#CERTDIR#$certs_dir#g;s#MAXCLIENTCONNECTIONS#$ZKMAXCNXNS#g;s#CLIENTPORT#$ZOOPORT#g" "$tests_dir/zoo.cfg" >"$tmp_dir/zoo.cfg"
+    if [[ -n $read_only ]]; then
+      # we can put the new server to read-only mode by starting only a single instance of a three node server
+      {
+        echo "server.1=localhost:22881:33881"
+        echo "server.2=localhost:22882:33882"
+        echo "server.3=localhost:22883:33883"
+      } >>"$tmp_dir/zoo.cfg"
+      echo "1" >"$tmp_dir/zkdata/myid"
+      main_class="org.apache.zookeeper.server.quorum.QuorumPeerMain"
     else
     else
-        main_class="org.apache.zookeeper.server.ZooKeeperServerMain"
+      main_class="org.apache.zookeeper.server.ZooKeeperServerMain"
     fi
     fi
 
 
-
     # ===== start the server
     # ===== start the server
-    java -cp "$CLASSPATH" $PROPERTIES ${main_class} ${tmp_dir}/zoo.cfg &> "${tmp_dir}/zk.log" &
+    java "${PROPERTIES[@]}" "$main_class" "$tmp_dir/zoo.cfg" &>"$tmp_dir/zk.log" &
     pid=$!
     pid=$!
-    echo -n $! > /tmp/zk.pid
-
+    echo -n $! >/tmp/zk.pid
 
 
     # ===== wait for the server to start
     # ===== wait for the server to start
-    if [ "x$1" == "xstartRequireSASLAuth" ] || [ "x$1" == "xstartCleanReadOnly" ]
-    then
-       # ===== in these cases we can not connect simply with the java client, so we are just waiting...
-       sleep 4
-       success=true
+    if [[ $1 == "startRequireSASLAuth" ]] || [[ $1 == "startCleanReadOnly" ]]; then
+      # ===== in these cases we can not connect simply with the java client, so we are just waiting...
+      sleep 4
+      success=true
     else
     else
-        # ===== wait max 120 seconds for server to be ready to server clients (this handles testing on slow hosts)
-        success=false
-        for i in {1..120}
-        do
-            if ps -p $pid > /dev/null
-            then
-                java -cp "$CLASSPATH" $PROPERTIES org.apache.zookeeper.ZooKeeperMain -server localhost:$ZOOPORT ls / > /dev/null 2>&1
-                if [ $? -ne 0  ]
-                then
-                    # server not up yet - wait
-                    sleep 1
-                else
-                    # server is up and serving client connections
-                    success=true
-                    break
-                fi
-            else
-                # server died - exit now
-                echo -n " ZooKeeper server process failed"
-                break
-            fi
-        done
+      # ===== wait max 120 seconds for server to be ready to server clients (this handles testing on slow hosts)
+      success=false
+      for i in {1..120}; do
+        if ps -p $pid >/dev/null; then
+          if ! java "${PROPERTIES[@]}" org.apache.zookeeper.ZooKeeperMain -server "localhost:$ZOOPORT" ls / &>/dev/null; then
+            # server not up yet - wait
+            sleep 1
+          else
+            # server is up and serving client connections
+            success=true
+            break
+          fi
+        else
+          # server died - exit now
+          echo -n " ZooKeeper server process failed"
+          break
+        fi
+      done
     fi
     fi
 
 
-    if $success
-    then
-        ## in case for debug, but generally don't use as it messes up the
-        ## console test output
-        echo -n " ZooKeeper server started"
+    if $success; then
+      ## in case for debug, but generally don't use as it messes up the
+      ## console test output
+      echo -n " ZooKeeper server started"
     else
     else
-        echo -n " ZooKeeper server NOT started"
+      echo -n " ZooKeeper server NOT started"
     fi
     fi
 
 
     ;;
     ;;
-stop)
+  stop)
     # Already killed above
     # Already killed above
     ;;
     ;;
-*)
-    echo "Unknown command " + $1
+  *)
+    echo "Unknown command $1"
     exit 2
     exit 2
+    ;;
 esac
 esac
-

+ 37 - 27
zookeeper-contrib/zookeeper-contrib-loggraph/src/main/resources/loggraph-dev.sh

@@ -1,38 +1,48 @@
-#!/bin/sh
-
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
+#! /usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
 
-make_canonical () {
-    cd $1; pwd;
+make_canonical() {
+  cd "$1" && pwd
 }
 }
 
 
-SCRIPTDIR=`dirname $0`
-BUILDDIR=`make_canonical $SCRIPTDIR/../../../target/`
-LIBDIR=`make_canonical $BUILDDIR/../lib`
-WEBDIR=`make_canonical $SCRIPTDIR/../web`
+SCRIPTDIR=$(dirname "$0")
+BUILDDIR=$(make_canonical "$SCRIPTDIR"/../../../target/)
+LIBDIR=$(make_canonical "$BUILDDIR"/../lib)
+WEBDIR=$(make_canonical "$SCRIPTDIR"/../web)
 
 
-if [ ! -x $BUILDDIR ]; then
-    echo "\n\n*** You need to build loggraph before running it ***\n\n";
-    exit;
+if [[ ! -x $BUILDDIR ]]; then
+  echo
+  echo
+  echo "*** You need to build loggraph before running it ***"
+  echo
+  echo
+  exit
 fi
 fi
 
 
-for i in `ls $LIBDIR`; do 
-    CLASSPATH=$LIBDIR/$i:$CLASSPATH
+for i in "$LIBDIR"/*; do
+  CLASSPATH=$i:$CLASSPATH
 done
 done
 
 
 CLASSPATH=$BUILDDIR/classes:$WEBDIR:$CLASSPATH
 CLASSPATH=$BUILDDIR/classes:$WEBDIR:$CLASSPATH
-echo $CLASSPATH
-java -Dlogback.configurationFile=org/apache/zookeeper/graph/logback.xml -Xdebug -Xrunjdwp:transport=dt_socket,address=4444,server=y,suspend=n -cp $CLASSPATH org.apache.zookeeper.graph.LogServer $*
+export CLASSPATH
+
+java -Dlogback.configurationFile=org/apache/zookeeper/graph/logback.xml \
+  -Xdebug -Xrunjdwp:transport=dt_socket,address=4444,server=y,suspend=n \
+  org.apache.zookeeper.graph.LogServer "$@"

+ 34 - 34
zookeeper-contrib/zookeeper-contrib-loggraph/src/main/resources/loggraph.sh

@@ -1,43 +1,43 @@
-#!/bin/sh
-
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
+#! /usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
 
-make_canonical () {
-    cd $1; pwd;
+make_canonical() {
+  cd "$1" && pwd
 }
 }
 
 
-SCRIPTDIR=`dirname $0`
-BUILDDIR=`make_canonical $SCRIPTDIR/../../../target/`
-LIBDIR=`make_canonical $BUILDDIR/../lib`
-
-if [ ! -x $BUILDDIR ]; then
-    echo "\n\n*** You need to build loggraph before running it ***\n\n";
-    exit;
+SCRIPTDIR=$(dirname "$0")
+BUILDDIR=$(make_canonical "$SCRIPTDIR"/../../../target/)
+LIBDIR=$(make_canonical "$BUILDDIR"/../lib)
+
+if [[ ! -x $BUILDDIR ]]; then
+  echo
+  echo
+  echo "*** You need to build loggraph before running it ***"
+  echo
+  echo
+  exit
 fi
 fi
 
 
-for i in `ls $LIBDIR`; do 
-    CLASSPATH=$LIBDIR/$i:$CLASSPATH
-done
-
-for i in `ls $BUILDDIR/*.jar`; do 
-    CLASSPATH=$i:$CLASSPATH
+for i in "$LIBDIR"/* "$BUILDDIR"/*.jar; do
+  CLASSPATH=$i:$CLASSPATH
 done
 done
+export CLASSPATH
 
 
-java -cp $CLASSPATH org.apache.zookeeper.graph.LogServer $*
-
-
-
-
+java org.apache.zookeeper.graph.LogServer "$@"

+ 54 - 47
zookeeper-contrib/zookeeper-contrib-rest/rest.sh

@@ -1,19 +1,22 @@
-#!/bin/sh
-
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
+#! /usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
 
 #
 #
 # If this scripted is run out of /usr/bin or some other system bin directory
 # If this scripted is run out of /usr/bin or some other system bin directory
@@ -22,24 +25,27 @@
 #
 #
 
 
 # Only follow symlinks if readlink supports it
 # Only follow symlinks if readlink supports it
-if readlink -f "$0" > /dev/null 2>&1
-then
-  ZKREST=`readlink -f "$0"`
+if readlink -f "$0" &>/dev/null; then
+  ZKREST=$(readlink -f "$0")
 else
 else
   ZKREST="$0"
   ZKREST="$0"
 fi
 fi
-ZKREST_HOME=`dirname "$ZKREST"`
+ZKREST_HOME=$(dirname "$ZKREST")
 
 
-if $cygwin
-then
-    # cygwin has a "kill" in the shell itself, gets confused
-    KILL=/bin/kill
+case "$(uname)" in
+  CYGWIN* | MINGW*) cygwin=true ;;
+  *) cygwin=false ;;
+esac
+
+if $cygwin; then
+  # cygwin has a "kill" in the shell itself, gets confused
+  KILL='/bin/kill'
 else
 else
-    KILL=kill
+  KILL='kill'
 fi
 fi
 
 
-if [ -z $ZKREST_PIDFILE ]
-    then ZKREST_PIDFILE=$ZKREST_HOME/server.pid
+if [[ -z $ZKREST_PIDFILE ]]; then
+  ZKREST_PIDFILE=$ZKREST_HOME/server.pid
 fi
 fi
 
 
 ZKREST_MAIN=org.apache.zookeeper.server.jersey.RestMain
 ZKREST_MAIN=org.apache.zookeeper.server.jersey.RestMain
@@ -49,42 +55,43 @@ ZKREST_LOG=$ZKREST_HOME/zkrest.log
 
 
 CLASSPATH="$ZKREST_CONF:$CLASSPATH"
 CLASSPATH="$ZKREST_CONF:$CLASSPATH"
 
 
-for i in "$ZKREST_HOME"/lib/*.jar
-do
-    CLASSPATH="$i:$CLASSPATH"
+for i in "$ZKREST_HOME"/lib/*.jar; do
+  CLASSPATH="$i:$CLASSPATH"
 done
 done
 
 
-for i in "$ZKREST_HOME"/zookeeper-*.jar
-do
-    CLASSPATH="$i:$CLASSPATH"
+for i in "$ZKREST_HOME"/zookeeper-*.jar; do
+  CLASSPATH="$i:$CLASSPATH"
 done
 done
+export CLASSPATH
 
 
 case $1 in
 case $1 in
-start)
-    echo  "Starting ZooKeeper REST Gateway ... "
-    java  -cp "$CLASSPATH" $JVMFLAGS $ZKREST_MAIN >$ZKREST_LOG 2>&1 &
-    /bin/echo -n $! > "$ZKREST_PIDFILE"
+  start)
+    echo "Starting ZooKeeper REST Gateway ... "
+    # shellcheck disable=SC2206
+    flags=($JVMFLAGS)
+    java "${flags[@]}" "$ZKREST_MAIN" &>"$ZKREST_LOG" &
+    echo -n $! >"$ZKREST_PIDFILE"
     echo STARTED
     echo STARTED
     ;;
     ;;
-stop)
+  stop)
     echo "Stopping ZooKeeper REST Gateway ... "
     echo "Stopping ZooKeeper REST Gateway ... "
-    if [ ! -f "$ZKREST_PIDFILE" ]
-    then
-    echo "error: could not find file $ZKREST_PIDFILE"
-    exit 1
+    if [[ ! -f $ZKREST_PIDFILE ]]; then
+      echo "error: could not find file $ZKREST_PIDFILE"
+      exit 1
     else
     else
-    $KILL -9 $(cat "$ZKREST_PIDFILE")
-    rm "$ZKREST_PIDFILE"
-    echo STOPPED
+      $KILL -9 "$(cat "$ZKREST_PIDFILE")"
+      rm "$ZKREST_PIDFILE"
+      echo STOPPED
     fi
     fi
     ;;
     ;;
-restart)
+  restart)
     shift
     shift
-    "$0" stop ${@}
+    "$0" stop "$@"
     sleep 3
     sleep 3
-    "$0" start ${@}
+    "$0" start "$@"
     ;;
     ;;
-*)
+  *)
     echo "Usage: $0 {start|stop|restart}" >&2
     echo "Usage: $0 {start|stop|restart}" >&2
+    ;;
 
 
 esac
 esac

+ 49 - 55
zookeeper-contrib/zookeeper-contrib-rest/src/test/zkServer.sh

@@ -1,4 +1,4 @@
-#!/bin/bash
+#! /usr/bin/env bash
 #
 #
 # Licensed to the Apache Software Foundation (ASF) under one
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # or more contributor license agreements.  See the NOTICE file
@@ -8,84 +8,78 @@
 # "License"); you may not use this file except in compliance
 # "License"); you may not use this file except in compliance
 # with the License.  You may obtain a copy of the License at
 # with the License.  You may obtain a copy of the License at
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
 
-if [ "x$1" == "x" ]
-then
-    echo "USAGE: $0 startClean|start|stop hostPorts"
-    exit 2
+if [[ -z $1 ]]; then
+  echo "USAGE: $0 startClean|start|stop hostPorts"
+  exit 2
 fi
 fi
 
 
-if [ "x$1" == "xstartClean" ]
-then
-    if [ "x${base_dir}" == "x" ]
-    then
+if [[ $1 == "startClean" ]]; then
+  if [[ -z $base_dir ]]; then
     rm -rf /tmp/zkdata
     rm -rf /tmp/zkdata
-    else
-    rm -rf ${base_dir}/build/tmp
-    fi
+  else
+    rm -rf "$base_dir/build/tmp"
+  fi
 fi
 fi
 
 
 # Make sure nothing is left over from before
 # Make sure nothing is left over from before
-if [ -r "/tmp/zk.pid" ]
-then
-pid=`cat /tmp/zk.pid`
-kill -9 $pid
-rm -f /tmp/zk.pid
+if [[ -r "/tmp/zk.pid" ]]; then
+  pid=$(cat /tmp/zk.pid)
+  kill -9 "$pid"
+  rm -f /tmp/zk.pid
 fi
 fi
 
 
-if [ -r "${base_dir}/build/tmp/zk.pid" ]
-then
-pid=`cat ${base_dir}/build/tmp/zk.pid`
-kill -9 $pid
-rm -f ${base_dir}/build/tmp/zk.pid
+if [[ -r "$base_dir/build/tmp/zk.pid" ]]; then
+  pid=$(cat "$base_dir/build/tmp/zk.pid")
+  kill -9 "$pid"
+  rm -f "$base_dir/build/tmp/zk.pid"
 fi
 fi
 
 
-if [ "x${base_dir}" == "x" ]	
-then
-zk_base="../../../"
+if [[ -z $base_dir ]]; then
+  zk_base="../../../"
 else
 else
-zk_base="${base_dir}"
+  zk_base="$base_dir"
 fi
 fi
 
 
-CLASSPATH="$CLASSPATH:${zk_base}/build/classes"
-CLASSPATH="$CLASSPATH:${zk_base}/conf"
+CLASSPATH="$CLASSPATH:$zk_base/build/classes"
+CLASSPATH="$CLASSPATH:$zk_base/conf"
 
 
-for i in "${zk_base}"/build/lib/*.jar
-do
-    CLASSPATH="$CLASSPATH:$i"
+for i in "$zk_base"/build/lib/*.jar; do
+  CLASSPATH="$CLASSPATH:$i"
 done
 done
 
 
-for i in "${zk_base}"/zookeeper-server/src/main/resource/lib/*.jar
-do
-    CLASSPATH="$CLASSPATH:$i"
+for i in "$zk_base"/zookeeper-server/src/main/resource/lib/*.jar; do
+  CLASSPATH="$CLASSPATH:$i"
 done
 done
+export CLASSPATH
 
 
 case $1 in
 case $1 in
-start|startClean)
-    if [ "x${base_dir}" == "x" ]
-        then
-        mkdir -p /tmp/zkdata
-        java -cp $CLASSPATH org.apache.zookeeper.server.ZooKeeperServerMain 22182 /tmp/zkdata &> /tmp/zk.log &
-        echo $! > /tmp/zk.pid
-        else
-        mkdir -p ${base_dir}/build/tmp/zkdata
-        java -cp $CLASSPATH org.apache.zookeeper.server.ZooKeeperServerMain 22182 ${base_dir}/build/tmp/zkdata &> ${base_dir}/build/tmp/zk.log &
-        echo $! > ${base_dir}/build/tmp/zk.pid
+  start | startClean)
+    if [[ -z $base_dir ]]; then
+      mkdir -p /tmp/zkdata
+      java org.apache.zookeeper.server.ZooKeeperServerMain 22182 /tmp/zkdata &>/tmp/zk.log &
+      echo $! >/tmp/zk.pid
+    else
+      mkdir -p "$base_dir/build/tmp/zkdata"
+      java org.apache.zookeeper.server.ZooKeeperServerMain 22182 "$base_dir/build/tmp/zkdata" &>"$base_dir/build/tmp/zk.log" &
+      echo $! >"$base_dir/build/tmp/zk.pid"
     fi
     fi
-        sleep 5
+    sleep 5
     ;;
     ;;
-stop)
+  stop)
     # Already killed above
     # Already killed above
     ;;
     ;;
-*)
-    echo "Unknown command " + $1
+  *)
+    echo "Unknown command $1"
     exit 2
     exit 2
+    ;;
 esac
 esac
-

+ 24 - 20
zookeeper-contrib/zookeeper-contrib-zkpython/src/test/run_tests.sh

@@ -1,20 +1,22 @@
-#!/bin/sh
+#! /usr/bin/env bash
 #
 #
-#  Licensed to the Apache Software Foundation (ASF) under one
+# Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information
 # distributed with this work for additional information
 # regarding copyright ownership.  The ASF licenses this file
 # regarding copyright ownership.  The ASF licenses this file
 # to you under the Apache License, Version 2.0 (the
 # to you under the Apache License, Version 2.0 (the
 # "License"); you may not use this file except in compliance
 # "License"); you may not use this file except in compliance
 # with the License.  You may obtain a copy of the License at
 # with the License.  You may obtain a copy of the License at
-
-#     http://www.apache.org/licenses/LICENSE-2.0
-
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
 
 
 # Usage: run_tests.sh testdir [logdir]
 # Usage: run_tests.sh testdir [logdir]
 # logdir is optional, defaults to cwd
 # logdir is optional, defaults to cwd
@@ -25,19 +27,21 @@ set -e
 ARGC=$#
 ARGC=$#
 
 
 # check to make sure enough arguments were given or exit
 # check to make sure enough arguments were given or exit
-if [ $ARGC -lt 2 ]; then
-    export ZKPY_LOG_DIR="."
+if [[ $ARGC -eq 1 ]]; then
+  export ZKPY_LOG_DIR="."
+elif [[ $ARGC -eq 2 ]]; then
+  export ZKPY_LOG_DIR=$2
 else
 else
-    export ZKPY_LOG_DIR=$2
+  echo "Usage: $0 testdir [logdir]" 1>&2
+  exit 1
 fi
 fi
 
 
 # Find the build directory containing zookeeper.so
 # Find the build directory containing zookeeper.so
-SO_PATH=`find ./target/ -name 'zookeeper*.so' | head -1`
-PYTHONPATH=`dirname $SO_PATH`
+SO_PATH=$(find ./target/ -name 'zookeeper*.so' | head -1)
+PYTHONPATH=$(dirname "$SO_PATH")
 LIB_PATH=../../zookeeper-client/zookeeper-client-c/target/c/.libs
 LIB_PATH=../../zookeeper-client/zookeeper-client-c/target/c/.libs
-for test in `ls $1/*_test.py`; 
-do
-    echo "Running $test"
-    echo "Running LD_LIBRARY_PATH=$LIB_PATH:$LD_LIBRARY_PATH DYLD_LIBRARY_PATH=$LIB_PATH:$DYLD_LIBRARY_PATH PYTHONPATH=$PYTHONPATH python $test"
-    LD_LIBRARY_PATH=$LIB_PATH:$LD_LIBRARY_PATH DYLD_LIBRARY_PATH=$LIB_PATH:$DYLD_LIBRARY_PATH PYTHONPATH=$PYTHONPATH python $test
+for test in "$1"/*_test.py; do
+  echo "Running $test"
+  echo "Running LD_LIBRARY_PATH=$LIB_PATH:$LD_LIBRARY_PATH DYLD_LIBRARY_PATH=$LIB_PATH:$DYLD_LIBRARY_PATH PYTHONPATH=$PYTHONPATH python $test"
+  LD_LIBRARY_PATH=$LIB_PATH:$LD_LIBRARY_PATH DYLD_LIBRARY_PATH=$LIB_PATH:$DYLD_LIBRARY_PATH PYTHONPATH=$PYTHONPATH python "$test"
 done
 done

+ 48 - 61
zookeeper-contrib/zookeeper-contrib-zkpython/src/test/zkServer.sh

@@ -1,4 +1,4 @@
-#!/bin/bash
+#! /usr/bin/env bash
 #
 #
 # Licensed to the Apache Software Foundation (ASF) under one
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # or more contributor license agreements.  See the NOTICE file
@@ -8,95 +8,82 @@
 # "License"); you may not use this file except in compliance
 # "License"); you may not use this file except in compliance
 # with the License.  You may obtain a copy of the License at
 # with the License.  You may obtain a copy of the License at
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
 
-if [ "x$1" == "x" ]
-then
-    echo "USAGE: $0 startClean|start|stop"
-    exit 2
+if [[ -z $1 ]]; then
+  echo "USAGE: $0 startClean|start|stop"
+  exit 2
 fi
 fi
 
 
-if [ "x${base_dir}" == "x" ]
-then
+if [[ -n $base_dir ]]; then
   PROJECT_ROOT="../../"
   PROJECT_ROOT="../../"
 else
 else
-  PROJECT_ROOT=${base_dir}
+  PROJECT_ROOT=$base_dir
 fi
 fi
-WORK_DIR=${PROJECT_ROOT}/zookeeper-contrib/zookeeper-contrib-zkpython/target/zkpython_tests
-TEST_DIR=${PROJECT_ROOT}/zookeeper-contrib/zookeeper-contrib-zkpython/src/test
-
+WORK_DIR=$PROJECT_ROOT/zookeeper-contrib/zookeeper-contrib-zkpython/target/zkpython_tests
+TEST_DIR=$PROJECT_ROOT/zookeeper-contrib/zookeeper-contrib-zkpython/src/test
 
 
-if [ -r "${WORK_DIR}/../zk.pid" ]
-then
-  pid=`cat "${WORK_DIR}/../zk.pid"`
-  kill -9 $pid
-  rm -f "${WORK_DIR}/../zk.pid"
+if [[ -r "$WORK_DIR/../zk.pid" ]]; then
+  pid=$(cat "$WORK_DIR/../zk.pid")
+  kill -9 "$pid"
+  rm -f "$WORK_DIR/../zk.pid"
 fi
 fi
 
 
-which lsof &> /dev/null
-if [ $? -eq 0  ]
-then
-    pid=`lsof -i :22182 | grep LISTEN | awk '{print $2}'`
-    if [ -n "$pid" ]
-    then
-        kill -9 $pid
-    fi
+if which lsof &>/dev/null; then
+  pid=$(lsof -i :22182 | grep LISTEN | awk '{print $2}')
+  if [[ -n $pid ]]; then
+    kill -9 "$pid"
+  fi
 fi
 fi
 
 
-
-
-
-if [ "x$1" == "xstartClean" ]
-then
-    rm -rf ${WORK_DIR}
+if [[ $1 == "startClean" ]]; then
+  rm -rf "$WORK_DIR"
 fi
 fi
 
 
+CLASSPATH="$CLASSPATH:$PROJECT_ROOT/zookeeper-server/target/classes"
+CLASSPATH="$CLASSPATH:$PROJECT_ROOT/conf"
 
 
-
-CLASSPATH="$CLASSPATH:${PROJECT_ROOT}/zookeeper-server/target/classes"
-CLASSPATH="$CLASSPATH:${zk_base}/conf"
-
-for i in "${PROJECT_ROOT}"/zookeeper-server/target/lib/*.jar
-do
-    CLASSPATH="$CLASSPATH:$i"
+for i in "$PROJECT_ROOT"/zookeeper-server/target/lib/*.jar; do
+  CLASSPATH="$CLASSPATH:$i"
 done
 done
 
 
-for i in "${PROJECT_ROOT}"/zookeeper-server/src/main/resource/lib/*.jar
-do
-    CLASSPATH="$CLASSPATH:$i"
+for i in "$PROJECT_ROOT"/zookeeper-server/src/main/resource/lib/*.jar; do
+  CLASSPATH="$CLASSPATH:$i"
 done
 done
+export CLASSPATH
 
 
 # Make sure nothing is left over from before
 # Make sure nothing is left over from before
 #fuser -skn tcp 22182/tcp
 #fuser -skn tcp 22182/tcp
 
 
 case $1 in
 case $1 in
-start|startClean)
-    mkdir -p ${WORK_DIR}/zkdata
+  start | startClean)
+    mkdir -p "$WORK_DIR/zkdata"
 
 
-    rm -rf ${WORK_DIR}/ssl
-    mkdir -p ${WORK_DIR}/ssl
-    cp ${PROJECT_ROOT}/zookeeper-client/zookeeper-client-c/ssl/gencerts.sh ${WORK_DIR}/ssl/
-    cd ${WORK_DIR}/ssl/
-    ./gencerts.sh
-    cd -
+    rm -rf "$WORK_DIR/ssl"
+    mkdir -p "$WORK_DIR/ssl"
+    cp "$PROJECT_ROOT/zookeeper-client/zookeeper-client-c/ssl/gencerts.sh" "$WORK_DIR/ssl/"
+    (cd "$WORK_DIR/ssl/" && ./gencerts.sh)
 
 
-    sed "s#WORKDIR#${WORK_DIR}#g" ${TEST_DIR}/zoo.cfg > "${WORK_DIR}/zoo.cfg"
-    java  -Dzookeeper.extendedTypesEnabled=true -Dznode.container.checkIntervalMs=100 -cp $CLASSPATH org.apache.zookeeper.server.ZooKeeperServerMain "${WORK_DIR}/zoo.cfg" &> "${WORK_DIR}/zoo.log" &
+    sed "s#WORKDIR#$WORK_DIR#g" "$TEST_DIR/zoo.cfg" >"$WORK_DIR/zoo.cfg"
+    java -Dzookeeper.extendedTypesEnabled=true -Dznode.container.checkIntervalMs=100 \
+      org.apache.zookeeper.server.ZooKeeperServerMain "$WORK_DIR/zoo.cfg" &>"$WORK_DIR/zoo.log" &
     pid=$!
     pid=$!
-    echo -n $! > ${WORK_DIR}/../zk.pid
+    echo -n $! >"$WORK_DIR"/../zk.pid
     sleep 5
     sleep 5
     ;;
     ;;
-stop)
+  stop)
     # Already killed above
     # Already killed above
     ;;
     ;;
-*)
-    echo "Unknown command " + $1
+  *)
+    echo "Unknown command $1"
     exit 2
     exit 2
+    ;;
 esac
 esac
-

+ 20 - 16
zookeeper-contrib/zookeeper-contrib-zooinspector/zooInspector-dev.sh

@@ -1,18 +1,22 @@
-#!/bin/sh
-
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
+#! /usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#   https://www.apache.org/licenses/LICENSE-2.0
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-         
-java -cp ../../build/contrib/ZooInspector/*:../../../build/*:../../../build/lib/*:lib org.apache.zookeeper.inspector.ZooInspector
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+export CLASSPATH="../../build/contrib/ZooInspector/*:../../../build/*:../../../build/lib/*:lib"
+java org.apache.zookeeper.inspector.ZooInspector

+ 18 - 17
zookeeper-contrib/zookeeper-contrib-zooinspector/zooInspector.sh

@@ -1,25 +1,26 @@
-#!/bin/sh
-
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
+#! /usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
 
 
 # Get the path to the directory containing this script
 # Get the path to the directory containing this script
 SCRIPT_DIR=$(dirname "$0")
 SCRIPT_DIR=$(dirname "$0")
 
 
 # Get the path to the uber jar for this tool
 # Get the path to the uber jar for this tool
 # (Requires "mvn install" or "mvn package" be run first)
 # (Requires "mvn install" or "mvn package" be run first)
-JAVA_LIB=`ls ${SCRIPT_DIR}/target/zookeeper-contrib-zooinspector-*-jar-with-dependencies.jar`
-
-java -jar "${JAVA_LIB}"
+java -jar "$SCRIPT_DIR"/target/zookeeper-contrib-zooinspector-*-jar-with-dependencies.jar

+ 41 - 45
zookeeper-recipes/zookeeper-recipes-lock/src/main/c/tests/zkServer.sh

@@ -1,4 +1,4 @@
-#!/bin/bash
+#! /usr/bin/env bash
 #
 #
 # Licensed to the Apache Software Foundation (ASF) under one
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # or more contributor license agreements.  See the NOTICE file
@@ -8,68 +8,64 @@
 # "License"); you may not use this file except in compliance
 # "License"); you may not use this file except in compliance
 # with the License.  You may obtain a copy of the License at
 # with the License.  You may obtain a copy of the License at
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
 
 
-if [ "x$1" == "x" ]
-then
-	echo "USAGE: $0 startClean|start|stop hostPorts"
-	exit 2
+if [[ -z $1 ]]; then
+  echo "USAGE: $0 startClean|start|stop hostPorts"
+  exit 2
 fi
 fi
 
 
-if [ "x$1" == "xstartClean" ]
-then
-	rm -rf /tmp/zkdata
+if [[ $1 == "startClean" ]]; then
+  rm -rf /tmp/zkdata
 fi
 fi
 
 
 # Make sure nothing is left over from before
 # Make sure nothing is left over from before
-if [ -r "/tmp/zk.pid" ]
-then
-pid=`cat /tmp/zk.pid`
-kill -9 $pid
-rm -f /tmp/zk.pid
+if [[ -r "/tmp/zk.pid" ]]; then
+  pid=$(cat /tmp/zk.pid)
+  kill -9 "$pid"
+  rm -f /tmp/zk.pid
 fi
 fi
 
 
 base_dir="../../../../.."
 base_dir="../../../../.."
 
 
-CLASSPATH="$CLASSPATH:${base_dir}/build/classes"
-CLASSPATH="$CLASSPATH:${base_dir}/conf"
+CLASSPATH="$CLASSPATH:$base_dir/build/classes"
+CLASSPATH="$CLASSPATH:$base_dir/conf"
 
 
-for f in "${base_dir}"/zookeeper-*.jar
-do
-    CLASSPATH="$CLASSPATH:$f"
+for f in "$base_dir"/zookeeper-*.jar; do
+  CLASSPATH="$CLASSPATH:$f"
 done
 done
 
 
-for i in "${base_dir}"/build/lib/*.jar
-do
-    CLASSPATH="$CLASSPATH:$i"
+for i in "$base_dir"/build/lib/*.jar; do
+  CLASSPATH="$CLASSPATH:$i"
 done
 done
 
 
-for i in "${base_dir}"/zookeeper-server/src/main/resource/lib/*.jar
-do
-    CLASSPATH="$CLASSPATH:$i"
+for i in "$base_dir"/zookeeper-server/src/main/resource/lib/*.jar; do
+  CLASSPATH="$CLASSPATH:$i"
 done
 done
 
 
-CLASSPATH="$CLASSPATH:${CLOVER_HOME}/lib/clover.jar"
+CLASSPATH="$CLASSPATH:$CLOVER_HOME/lib/clover.jar"
+export CLASSPATH
 
 
 case $1 in
 case $1 in
-start|startClean)
-	mkdir -p /tmp/zkdata
-	java -cp $CLASSPATH org.apache.zookeeper.server.ZooKeeperServerMain 22181 /tmp/zkdata &> /tmp/zk.log &
-        echo $! > /tmp/zk.pid
-        sleep 5
-	;;
-stop)
-	# Already killed above
-	;;
-*)
-	echo "Unknown command " + $1
-	exit 2
+  start | startClean)
+    mkdir -p /tmp/zkdata
+    java org.apache.zookeeper.server.ZooKeeperServerMain 22181 /tmp/zkdata &>/tmp/zk.log &
+    echo $! >/tmp/zk.pid
+    sleep 5
+    ;;
+  stop)
+    # Already killed above
+    ;;
+  *)
+    echo "Unknown command $1"
+    exit 2
+    ;;
 esac
 esac
-

+ 41 - 45
zookeeper-recipes/zookeeper-recipes-queue/src/main/c/tests/zkServer.sh

@@ -1,4 +1,4 @@
-#!/bin/bash
+#! /usr/bin/env bash
 #
 #
 # Licensed to the Apache Software Foundation (ASF) under one
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # or more contributor license agreements.  See the NOTICE file
@@ -8,68 +8,64 @@
 # "License"); you may not use this file except in compliance
 # "License"); you may not use this file except in compliance
 # with the License.  You may obtain a copy of the License at
 # with the License.  You may obtain a copy of the License at
 #
 #
-#     http://www.apache.org/licenses/LICENSE-2.0
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
 #
 #
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
 
 
-if [ "x$1" == "x" ]
-then
-	echo "USAGE: $0 startClean|start|stop hostPorts"
-	exit 2
+if [[ -z $1 ]]; then
+  echo "USAGE: $0 startClean|start|stop hostPorts"
+  exit 2
 fi
 fi
 
 
-if [ "x$1" == "xstartClean" ]
-then
-	rm -rf /tmp/zkdata
+if [[ $1 == "startClean" ]]; then
+  rm -rf /tmp/zkdata
 fi
 fi
 
 
 # Make sure nothing is left over from before
 # Make sure nothing is left over from before
-if [ -r "/tmp/zk.pid" ]
-then
-pid=`cat /tmp/zk.pid`
-kill -9 $pid
-rm -f /tmp/zk.pid
+if [[ -r "/tmp/zk.pid" ]]; then
+  pid=$(cat /tmp/zk.pid)
+  kill -9 "$pid"
+  rm -f /tmp/zk.pid
 fi
 fi
 
 
 base_dir="../../../../.."
 base_dir="../../../../.."
 
 
-CLASSPATH="$CLASSPATH:${base_dir}/build/classes"
-CLASSPATH="$CLASSPATH:${base_dir}/conf"
+CLASSPATH="$CLASSPATH:$base_dir/build/classes"
+CLASSPATH="$CLASSPATH:$base_dir/conf"
 
 
-for f in "${base_dir}"/zookeeper-*.jar
-do
-    CLASSPATH="$CLASSPATH:$f"
+for f in "$base_dir"/zookeeper-*.jar; do
+  CLASSPATH="$CLASSPATH:$f"
 done
 done
 
 
-for i in "${base_dir}"/build/lib/*.jar
-do
-    CLASSPATH="$CLASSPATH:$i"
+for i in "$base_dir"/build/lib/*.jar; do
+  CLASSPATH="$CLASSPATH:$i"
 done
 done
 
 
-for i in "${base_dir}"/zookeeper-server/src/main/resource/lib/*.jar
-do
-    CLASSPATH="$CLASSPATH:$i"
+for i in "$base_dir"/zookeeper-server/src/main/resource/lib/*.jar; do
+  CLASSPATH="$CLASSPATH:$i"
 done
 done
 
 
-CLASSPATH="$CLASSPATH:${CLOVER_HOME}/lib/clover.jar"
+CLASSPATH="$CLASSPATH:$CLOVER_HOME/lib/clover.jar"
+export CLASSPATH
 
 
 case $1 in
 case $1 in
-start|startClean)
-	mkdir -p /tmp/zkdata
-	java -cp $CLASSPATH org.apache.zookeeper.server.ZooKeeperServerMain 22181 /tmp/zkdata &> /tmp/zk.log &
-        echo $! > /tmp/zk.pid
-        sleep 5
-	;;
-stop)
-	# Already killed above
-	;;
-*)
-	echo "Unknown command " + $1
-	exit 2
+  start | startClean)
+    mkdir -p /tmp/zkdata
+    java org.apache.zookeeper.server.ZooKeeperServerMain 22181 /tmp/zkdata &>/tmp/zk.log &
+    echo $! >/tmp/zk.pid
+    sleep 5
+    ;;
+  stop)
+    # Already killed above
+    ;;
+  *)
+    echo "Unknown command $1"
+    exit 2
+    ;;
 esac
 esac
-

+ 0 - 22
zookeeper-server/src/main/resources/lastRevision.bat

@@ -1,22 +0,0 @@
-echo off
-rem Licensed to the Apache Software Foundation (ASF) under one
-rem or more contributor license agreements.  See the NOTICE file
-rem distributed with this work for additional information
-rem regarding copyright ownership.  The ASF licenses this file
-rem to you under the Apache License, Version 2.0 (the
-rem "License"); you may not use this file except in compliance
-rem with the License.  You may obtain a copy of the License at
-rem
-rem     http://www.apache.org/licenses/LICENSE-2.0
-rem
-rem Unless required by applicable law or agreed to in writing, software
-rem distributed under the License is distributed on an "AS IS" BASIS,
-rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-rem See the License for the specific language governing permissions and
-rem limitations under the License.
-
-rem Find the current revision, store it in a file, for DOS
-
-for /f "delims=" %%i in ('git rev-parse HEAD') do set rev=%%i
-       echo lastRevision=%rev% > %1
-)

+ 0 - 22
zookeeper-server/src/main/resources/lastRevision.sh

@@ -1,22 +0,0 @@
-#!/bin/sh
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Find the current revision, store it in a file
-FILE=$1
-LASTREV=$(git rev-parse HEAD)
-
-echo "lastRevision=${LASTREV}" > "$FILE"

+ 0 - 614
zookeeper-server/src/test/resources/test-github-pr.sh

@@ -1,614 +0,0 @@
-#!/usr/bin/env bash
-#   Licensed under the Apache License, Version 2.0 (the "License");
-#   you may not use this file except in compliance with the License.
-#   You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-#   Unless required by applicable law or agreed to in writing, software
-#   distributed under the License is distributed on an "AS IS" BASIS,
-#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#   See the License for the specific language governing permissions and
-#   limitations under the License.
-
-
-#set -x
-
-### Setup some variables.
-### GIT_COMMIT and BUILD_URL are set by Hudson if it is run by patch process
-### Read variables from properties file
-. `dirname $0`/test-patch.properties
-
-###############################################################################
-parseArgs() {
-  case "$1" in
-    QABUILD)
-      ### Set QABUILD to true to indicate that this script is being run by Hudson
-      QABUILD=true
-      if [[ $# != 13 ]] ; then
-        echo "ERROR: usage $0 QABUILD <PATCH_DIR> <PS_CMD> <WGET_CMD> <JIRACLI> <GIT_CMD> <GREP_CMD> <PATCH_CMD> <FINDBUGS_HOME> <WORKSPACE_BASEDIR> <JIRA_PASSWD> <JAVA5_HOME> <CURL_CMD>"
-        cleanupAndExit 0
-      fi
-      PATCH_DIR=$2
-      PS=$3
-      WGET=$4
-      JIRACLI=$5
-      GIT=$6
-      GREP=$7
-      PATCH=$8
-      FINDBUGS_HOME=$9
-      BASEDIR=${10}
-      JIRA_PASSWD=${11}
-      JAVA5_HOME=${12}
-      CURL=${13}
-      if [ ! -e "$PATCH_DIR" ] ; then
-        mkdir -p $PATCH_DIR
-      fi
-
-      ## Obtain PR number and title
-      PULLREQUEST_ID=${GIT_PR_NUMBER}
-      PULLREQUEST_TITLE="${GIT_PR_TITLE}"
-
-      ## Extract jira number from PR title
-      local prefix=${PULLREQUEST_TITLE%ZOOKEEPER\-[0-9]*}
-      local noprefix=${PULLREQUEST_TITLE#$prefix}
-      local regex='\(ZOOKEEPER-.[0-9]*\)'
-      defect=$(expr "$noprefix" : ${regex})
-
-      echo "Pull request id: ${PULLREQUEST_ID}"
-      echo "Pull request title: ${PULLREQUEST_TITLE}"
-      echo "Defect number: ${defect}"
-
-      JIRA_COMMENT="GitHub Pull Request ${PULLREQUEST_NUMBER} Build
-      "
-      ;;
-    DEVELOPER)
-      ### Set QABUILD to false to indicate that this script is being run by a developer
-      QABUILD=false
-      if [[ $# != 9 ]] ; then
-        echo "ERROR: usage $0 DEVELOPER <GIT_PR_URL> <SCRATCH_DIR> <GIT_CMD> <GREP_CMD> <PATCH_CMD> <FINDBUGS_HOME> <WORKSPACE_BASEDIR> <JAVA5_HOME>"
-        cleanupAndExit 0
-      fi
-      PATCH_DIR=$3
-      PATCH_FILE=${PATCH_DIR}/patch
-      curl -L $2.diff > ${PATCH_FILE}
-      ### PATCH_FILE contains the location of the patchfile
-      if [[ ! -e "$PATCH_FILE" ]] ; then
-        echo "Unable to locate the patch file $PATCH_FILE"
-        cleanupAndExit 0
-      fi
-      ### Check if $PATCH_DIR exists. If it does not exist, create a new directory
-      if [[ ! -e "$PATCH_DIR" ]] ; then
-	mkdir "$PATCH_DIR"
-	if [[ $? == 0 ]] ; then
-	  echo "$PATCH_DIR has been created"
-	else
-	  echo "Unable to create $PATCH_DIR"
-	  cleanupAndExit 0
-	fi
-      fi
-      GIT=$4
-      GREP=$5
-      PATCH=$6
-      FINDBUGS_HOME=$7
-      BASEDIR=$8
-      JAVA5_HOME=${9}
-      ### Obtain the patch filename to append it to the version number
-      local subject=`grep "Subject:" ${PATCH_FILE}`
-      local length=`expr match ${subject} ZOOKEEPER-[0-9]*`
-      local position=`expr index ${subject} ZOOKEEPER-`
-      defect=${${subject:$position:$length}#ZOOKEEPER-}
-      ;;
-    *)
-      echo "ERROR: usage $0 QABUILD [args] | DEVELOPER [args]"
-      cleanupAndExit 0
-      ;;
-  esac
-}
-
-###############################################################################
-checkout () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Testing patch for pull request ${PULLREQUEST_ID}."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  ### When run by a developer, if the workspace contains modifications, do not continue
-  # Ref http://stackoverflow.com/a/2659808 for details on checking dirty status
-  ${GIT} diff-index --quiet HEAD
-  if [[ $? -ne 0 ]] ; then
-    uncommitted=`${GIT} diff --name-only HEAD`
-    uncommitted="You have the following files with uncommitted changes:${NEWLINE}${uncommitted}"
-  fi
-  untracked="$(${GIT} ls-files --exclude-standard --others)" && test -z "${untracked}"
-  if [[ $? -ne 0 ]] ; then
-    untracked="You have untracked and unignored files:${NEWLINE}${untracked}"
-  fi
-
-  if [[ $QABUILD == "false" ]] ; then
-    if [[ $uncommitted || $untracked ]] ; then
-      echo "ERROR: can't run in a workspace that contains the following modifications"
-      echo ""
-      echo "${uncommitted}"
-      echo ""
-      echo "${untracked}"
-      cleanupAndExit 1
-    fi
-  else
-    # I don't believe we need to do anything here - the jenkins job will
-    # cleanup the environment for us ("cleanup before checkout" action)
-    # on the precommit jenkins job
-    echo
-  fi
-  return $?
-}
-
-###############################################################################
-setup () {
-  ### exit if warnings are NOT defined in the properties file
-  if [ -z "$OK_FINDBUGS_WARNINGS" ] || [[ -z "$OK_JAVADOC_WARNINGS" ]] || [[ -z $OK_RELEASEAUDIT_WARNINGS ]]; then
-    echo "Please define the following properties in test-patch.properties file"
-	 echo  "OK_FINDBUGS_WARNINGS"
-	 echo  "OK_RELEASEAUDIT_WARNINGS"
-	 echo  "OK_JAVADOC_WARNINGS"
-    cleanupAndExit 1
-  fi
-  ### get pull request diff
-  ${CURL} -L ${GIT_PR_URL}.diff > $PATCH_DIR/patch
-
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo " Pre-build trunk to verify trunk stability and javac warnings"
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  echo "$ANT_HOME/bin/ant  -Djavac.args="-Xlint -Xmaxwarns 1000" -Djava5.home=${JAVA5_HOME} -DZookeeperPatchProcess= clean tar > $PATCH_DIR/trunkJavacWarnings.txt 2>&1"
- $ANT_HOME/bin/ant -Djavac.args="-Xlint -Xmaxwarns 1000" -Djava5.home=${JAVA5_HOME} -DZookeeperPatchProcess= clean tar > $PATCH_DIR/trunkJavacWarnings.txt 2>&1
-  if [[ $? != 0 ]] ; then
-    echo "Trunk compilation is broken?"
-    cleanupAndExit 1
-  fi
-}
-
-###############################################################################
-### Check for @author tags in the patch
-checkAuthor () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Checking there are no @author tags in the patch."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  authorTags=`$GREP -c -i '@author' $PATCH_DIR/patch`
-  echo "There appear to be $authorTags @author tags in the patch."
-  if [[ $authorTags != 0 ]] ; then
-    JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 @author.  The patch appears to contain $authorTags @author tags which the Zookeeper community has agreed to not allow in code contributions."
-    return 1
-  fi
-  JIRA_COMMENT="$JIRA_COMMENT
-
-    +1 @author.  The patch does not contain any @author tags."
-  return 0
-}
-
-###############################################################################
-### Check for tests in the patch
-checkTests () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Checking there are new or changed tests in the patch."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  testReferences=`$GREP -c -i '/test' $PATCH_DIR/patch`
-  echo "There appear to be $testReferences test files referenced in the patch."
-  if [[ $testReferences == 0 ]] ; then
-    if [[ $QABUILD == "true" ]] ; then
-      patchIsDoc=`$GREP -c -i 'title="documentation' $PATCH_DIR/jira`
-      if [[ $patchIsDoc != 0 ]] ; then
-        echo "The patch appears to be a documentation patch that doesn't require tests."
-        JIRA_COMMENT="$JIRA_COMMENT
-
-    +0 tests included.  The patch appears to be a documentation patch that doesn't require tests."
-        return 0
-      fi
-    fi
-    JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 tests included.  The patch doesn't appear to include any new or modified tests.
-                        Please justify why no new tests are needed for this patch.
-                        Also please list what manual steps were performed to verify this patch."
-    return 1
-  fi
-  JIRA_COMMENT="$JIRA_COMMENT
-
-    +1 tests included.  The patch appears to include $testReferences new or modified tests."
-  return 0
-}
-
-###############################################################################
-### Check there are no javadoc warnings
-checkJavadocWarnings () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Determining number of patched javadoc warnings."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  echo "$ANT_HOME/bin/ant -DZookeeperPatchProcess= clean javadoc | tee $PATCH_DIR/patchJavadocWarnings.txt"
-  $ANT_HOME/bin/ant -DZookeeperPatchProcess= clean javadoc | tee $PATCH_DIR/patchJavadocWarnings.txt
-  javadocWarnings=`$GREP -o '\[javadoc\] [0-9]* warning' $PATCH_DIR/patchJavadocWarnings.txt | awk '{total += $2} END {print total}'`
-  echo ""
-  echo ""
-  echo "There appear to be $javadocWarnings javadoc warnings generated by the patched build."
-
-  ### if current warnings greater than OK_JAVADOC_WARNINGS
-  if [[ $javadocWarnings > $OK_JAVADOC_WARNINGS ]] ; then
-    JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 javadoc.  The javadoc tool appears to have generated `expr $(($javadocWarnings-$OK_JAVADOC_WARNINGS))` warning messages."
-    return 1
-  fi
-  JIRA_COMMENT="$JIRA_COMMENT
-
-    +1 javadoc.  The javadoc tool did not generate any warning messages."
-  return 0
-}
-
-###############################################################################
-### Check there are no changes in the number of Javac warnings
-checkJavacWarnings () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Determining number of patched javac warnings."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  echo "$ANT_HOME/bin/ant -Djavac.args="-Xlint -Xmaxwarns 1000" -Djava5.home=${JAVA5_HOME} -DZookeeperPatchProcess= clean tar > $PATCH_DIR/patchJavacWarnings.txt 2>&1"
-  $ANT_HOME/bin/ant -Djavac.args="-Xlint -Xmaxwarns 1000" -Djava5.home=${JAVA5_HOME} -DZookeeperPatchProcess= clean tar > $PATCH_DIR/patchJavacWarnings.txt 2>&1
-  if [[ $? != 0 ]] ; then
-    JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 javac.  The patch appears to cause tar ant target to fail."
-    return 1
-  fi
-  ### Compare trunk and patch javac warning numbers
-  if [[ -f $PATCH_DIR/patchJavacWarnings.txt ]] ; then
-    trunkJavacWarnings=`$GREP -o '\[javac\] [0-9]* warning' $PATCH_DIR/trunkJavacWarnings.txt | awk '{total += $2} END {print total}'`
-    patchJavacWarnings=`$GREP -o '\[javac\] [0-9]* warning' $PATCH_DIR/patchJavacWarnings.txt | awk '{total += $2} END {print total}'`
-    echo "There appear to be $trunkJavacWarnings javac compiler warnings before the patch and $patchJavacWarnings javac compiler warnings after applying the patch."
-    if [[ $patchJavacWarnings != "" && $trunkJavacWarnings != "" ]] ; then
-      if [[ $patchJavacWarnings -gt $trunkJavacWarnings ]] ; then
-        JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 javac.  The applied patch generated $patchJavacWarnings javac compiler warnings (more than the trunk's current $trunkJavacWarnings warnings)."
-        return 1
-      fi
-    fi
-  fi
-  JIRA_COMMENT="$JIRA_COMMENT
-
-    +1 javac.  The applied patch does not increase the total number of javac compiler warnings."
-  return 0
-}
-
-###############################################################################
-### Check there are no changes in the number of release audit (RAT) warnings
-checkReleaseAuditWarnings () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Determining number of patched release audit warnings."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  echo "$ANT_HOME/bin/ant -Djava5.home=${JAVA5_HOME} -DZookeeperPatchProcess= releaseaudit > $PATCH_DIR/patchReleaseAuditWarnings.txt 2>&1"
-  $ANT_HOME/bin/ant -Djava5.home=${JAVA5_HOME} -DZookeeperPatchProcess= releaseaudit > $PATCH_DIR/patchReleaseAuditWarnings.txt 2>&1
-
-  ### Compare trunk and patch release audit warning numbers
-  if [[ -f $PATCH_DIR/patchReleaseAuditWarnings.txt ]] ; then
-    patchReleaseAuditWarnings=`$GREP -c '\!?????' $PATCH_DIR/patchReleaseAuditWarnings.txt`
-    echo ""
-    echo ""
-    echo "There appear to be $OK_RELEASEAUDIT_WARNINGS release audit warnings before the patch and $patchReleaseAuditWarnings release audit warnings after applying the patch."
-    if [[ $patchReleaseAuditWarnings != "" && $OK_RELEASEAUDIT_WARNINGS != "" ]] ; then
-      if [[ $patchReleaseAuditWarnings -gt $OK_RELEASEAUDIT_WARNINGS ]] ; then
-        JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 release audit.  The applied patch generated $patchReleaseAuditWarnings release audit warnings (more than the trunk's current $OK_RELEASEAUDIT_WARNINGS warnings)."
-        $GREP '\!?????' $PATCH_DIR/patchReleaseAuditWarnings.txt > $PATCH_DIR/patchReleaseAuditProblems.txt
-        echo "Lines that start with ????? in the release audit report indicate files that do not have an Apache license header." >> $PATCH_DIR/patchReleaseAuditProblems.txt
-        JIRA_COMMENT_FOOTER="Release audit warnings: $BUILD_URL/artifact/trunk/patchprocess/patchReleaseAuditProblems.txt
-$JIRA_COMMENT_FOOTER"
-        return 1
-      fi
-    fi
-  fi
-  JIRA_COMMENT="$JIRA_COMMENT
-
-    +1 release audit.  The applied patch does not increase the total number of release audit warnings."
-  return 0
-}
-
-###############################################################################
-### Check there are no changes in the number of Checkstyle warnings
-checkStyle () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Determining number of patched checkstyle warnings."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  echo "THIS IS NOT IMPLEMENTED YET"
-  echo ""
-  echo ""
-  echo "$ANT_HOME/bin/ant -DZookeeperPatchProcess= checkstyle"
-  $ANT_HOME/bin/ant -DZookeeperPatchProcess= checkstyle
-  JIRA_COMMENT_FOOTER="Checkstyle results: $BUILD_URL/artifact/trunk/build/test/checkstyle-errors.html
-$JIRA_COMMENT_FOOTER"
-  ### TODO: calculate actual patchStyleErrors
-#  patchStyleErrors=0
-#  if [[ $patchStyleErrors != 0 ]] ; then
-#    JIRA_COMMENT="$JIRA_COMMENT
-#
-#    -1 checkstyle.  The patch generated $patchStyleErrors code style errors."
-#    return 1
-#  fi
-#  JIRA_COMMENT="$JIRA_COMMENT
-#
-#    +1 checkstyle.  The patch generated 0 code style errors."
-  return 0
-}
-
-###############################################################################
-### Check there are no changes in the number of Findbugs warnings
-checkFindbugsWarnings () {
-  findbugs_version=`${FINDBUGS_HOME}/bin/findbugs -version`
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Determining number of patched Findbugs warnings."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  echo "$ANT_HOME/bin/ant -Dfindbugs.home=$FINDBUGS_HOME -Djava5.home=${JAVA5_HOME} -DZookeeperPatchProcess= findbugs"
-  $ANT_HOME/bin/ant -Dfindbugs.home=$FINDBUGS_HOME -Djava5.home=${JAVA5_HOME} -DZookeeperPatchProcess= findbugs
-  if [ $? != 0 ] ; then
-    JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 findbugs.  The patch appears to cause Findbugs (version ${findbugs_version}) to fail."
-    return 1
-  fi
-JIRA_COMMENT_FOOTER="Findbugs warnings: $BUILD_URL/artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html
-$JIRA_COMMENT_FOOTER"
-  cp $BASEDIR/build/test/findbugs/*.xml $PATCH_DIR/patchFindbugsWarnings.xml
-  $FINDBUGS_HOME/bin/setBugDatabaseInfo -timestamp "01/01/2000" \
-    $PATCH_DIR/patchFindbugsWarnings.xml \
-    $PATCH_DIR/patchFindbugsWarnings.xml
-  findbugsWarnings=`$FINDBUGS_HOME/bin/filterBugs -first "01/01/2000" $PATCH_DIR/patchFindbugsWarnings.xml \
-    $BASEDIR/build/test/findbugs/newPatchFindbugsWarnings.xml | /usr/bin/awk '{print $1}'`
-  $FINDBUGS_HOME/bin/convertXmlToText -html \
-    $BASEDIR/build/test/findbugs/newPatchFindbugsWarnings.xml \
-    $BASEDIR/build/test/findbugs/newPatchFindbugsWarnings.html
-  cp $BASEDIR/build/test/findbugs/newPatchFindbugsWarnings.html $PATCH_DIR/newPatchFindbugsWarnings.html
-  cp $BASEDIR/build/test/findbugs/newPatchFindbugsWarnings.xml $PATCH_DIR/newPatchFindbugsWarnings.xml
-
-  ### if current warnings greater than OK_FINDBUGS_WARNINGS
-  if [[ $findbugsWarnings > $OK_FINDBUGS_WARNINGS ]] ; then
-    JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 findbugs.  The patch appears to introduce `expr $(($findbugsWarnings-$OK_FINDBUGS_WARNINGS))` new Findbugs (version ${findbugs_version}) warnings."
-    return 1
-  fi
-  JIRA_COMMENT="$JIRA_COMMENT
-
-    +1 findbugs.  The patch does not introduce any new Findbugs (version ${findbugs_version}) warnings."
-  return 0
-}
-
-###############################################################################
-### Run the test-core target
-runCoreTests () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Running core tests."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-
-  ### Kill any rogue build processes from the last attempt
-  $PS auxwww | $GREP ZookeeperPatchProcess | /usr/bin/nawk '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null
-
-  echo "$ANT_HOME/bin/ant -DZookeeperPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no -Dtest.junit.threads=4 -Dcompile.c++=yes -Djava5.home=$JAVA5_HOME test-core"
-  $ANT_HOME/bin/ant -DZookeeperPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no -Dtest.junit.threads=4 -Dcompile.c++=yes -Djava5.home=$JAVA5_HOME test-core
-  if [[ $? != 0 ]] ; then
-    JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 core tests.  The patch failed core unit tests."
-    return 1
-  fi
-  JIRA_COMMENT="$JIRA_COMMENT
-
-    +1 core tests.  The patch passed core unit tests."
-  return 0
-}
-
-###############################################################################
-### Run the test-contrib target
-runContribTests () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Running contrib tests."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-
-  ### Kill any rogue build processes from the last attempt
-  $PS auxwww | $GREP ZookeeperPatchProcess | /usr/bin/nawk '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null
-
-  echo "$ANT_HOME/bin/ant -DZookeeperPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no test-contrib"
-  $ANT_HOME/bin/ant -DZookeeperPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no test-contrib
-  if [[ $? != 0 ]] ; then
-    JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 contrib tests.  The patch failed contrib unit tests."
-    return 1
-  fi
-  JIRA_COMMENT="$JIRA_COMMENT
-
-    +1 contrib tests.  The patch passed contrib unit tests."
-  return 0
-}
-
-###############################################################################
-### Submit a comment to the defect's Jira
-submitJiraComment () {
-  local result=$1
-  ### Do not output the value of JIRA_COMMENT_FOOTER when run by a developer
-  if [[  $QABUILD == "false" ]] ; then
-    JIRA_COMMENT_FOOTER=""
-  fi
-  if [[ $result == 0 ]] ; then
-    comment="+1 overall.  $JIRA_COMMENT
-
-$JIRA_COMMENT_FOOTER"
-  else
-    comment="-1 overall.  $JIRA_COMMENT
-
-$JIRA_COMMENT_FOOTER"
-  fi
-  ### Output the test result to the console
-  echo "
-
-
-
-$comment"
-
-  if [[ $QABUILD == "true" ]] ; then
-    echo ""
-    echo ""
-    echo "======================================================================"
-    echo "======================================================================"
-    echo "    Adding comment to Jira."
-    echo "======================================================================"
-    echo "======================================================================"
-    echo ""
-    echo ""
-    ### Update Jira with a comment
-    export USER=jenkins
-    $JIRACLI -s https://issues.apache.org/jira -a addcomment -u hadoopqa -p $JIRA_PASSWD --comment "$comment" --issue $defect
-    $JIRACLI -s https://issues.apache.org/jira -a logout -u hadoopqa -p $JIRA_PASSWD
-  fi
-}
-
-###############################################################################
-### Cleanup files
-cleanupAndExit () {
-  local result=$1
-  if [[ $QABUILD == "true" ]] ; then
-    if [ -e "$PATCH_DIR" ] ; then
-      mv $PATCH_DIR $BASEDIR
-    fi
-  fi
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Finished build."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  exit $result
-}
-
-###############################################################################
-###############################################################################
-###############################################################################
-
-JIRA_COMMENT=""
-JIRA_COMMENT_FOOTER="Console output: $BUILD_URL/console
-
-This message is automatically generated."
-
-### Check if arguments to the script have been specified properly or not
-echo "----- Going to parser args -----"
-parseArgs $@
-cd $BASEDIR
-
-echo "----- Parsed args, going to checkout -----"
-checkout
-RESULT=$?
-if [[ $QABUILD == "true" ]] ; then
-  if [[ $RESULT != 0 ]] ; then
-    exit 100
-  fi
-fi
-setup
-checkAuthor
-(( RESULT = RESULT + $? ))
-
-checkTests
-checkTestsResult=$?
-(( RESULT = RESULT + $checkTestsResult ))
-if [[ $checkTestsResult != 0 ]] ; then
-  submitJiraComment 1
-  cleanupAndExit 1
-fi
-checkJavadocWarnings
-(( RESULT = RESULT + $? ))
-checkJavacWarnings
-(( RESULT = RESULT + $? ))
-### Checkstyle not implemented yet
-#checkStyle
-#(( RESULT = RESULT + $? ))
-checkFindbugsWarnings
-(( RESULT = RESULT + $? ))
-checkReleaseAuditWarnings
-(( RESULT = RESULT + $? ))
-### Do not call these when run by a developer
-if [[ $QABUILD == "true" ]] ; then
-  runCoreTests
-  (( RESULT = RESULT + $? ))
-  runContribTests
-  (( RESULT = RESULT + $? ))
-fi
-JIRA_COMMENT_FOOTER="Test results: $BUILD_URL/testReport/
-$JIRA_COMMENT_FOOTER"
-
-submitJiraComment $RESULT
-cleanupAndExit $RESULT

+ 0 - 647
zookeeper-server/src/test/resources/test-patch.sh

@@ -1,647 +0,0 @@
-#!/usr/bin/env bash
-#   Licensed under the Apache License, Version 2.0 (the "License");
-#   you may not use this file except in compliance with the License.
-#   You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-#   Unless required by applicable law or agreed to in writing, software
-#   distributed under the License is distributed on an "AS IS" BASIS,
-#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#   See the License for the specific language governing permissions and
-#   limitations under the License.
-
-
-#set -x
-
-### Setup some variables.  
-### GIT_COMMIT and BUILD_URL are set by Hudson if it is run by patch process
-### Read variables from properties file
-. `dirname $0`/test-patch.properties
-
-###############################################################################
-parseArgs() {
-  case "$1" in
-    HUDSON)
-      ### Set HUDSON to true to indicate that this script is being run by Hudson
-      HUDSON=true
-      if [[ $# != 14 ]] ; then
-        echo "ERROR: usage $0 HUDSON <PATCH_DIR> <PS_CMD> <WGET_CMD> <JIRACLI> <GIT_CMD> <GREP_CMD> <PATCH_CMD> <FINDBUGS_HOME> <WORKSPACE_BASEDIR> <JIRA_PASSWD> <JAVA5_HOME> <CURL_CMD> <DEFECT> "
-        cleanupAndExit 0
-      fi
-      PATCH_DIR=$2
-      PS=$3
-      WGET=$4
-      JIRACLI=$5
-      GIT=$6
-      GREP=$7
-      PATCH=$8
-      FINDBUGS_HOME=$9
-      BASEDIR=${10}
-      JIRA_PASSWD=${11}
-      JAVA5_HOME=${12}
-      CURL=${13}
-      defect=${14}
-		
-      ### Retrieve the defect number
-      if [ -z "$defect" ] ; then
-        echo "Could not determine the patch to test.  Exiting."
-        cleanupAndExit 0
-      fi
-
-      if [ ! -e "$PATCH_DIR" ] ; then
-        mkdir -p $PATCH_DIR 
-      fi
-
-      ;;
-    DEVELOPER)
-      ### Set HUDSON to false to indicate that this script is being run by a developer
-      HUDSON=false
-      if [[ $# != 9 ]] ; then
-        echo "ERROR: usage $0 DEVELOPER <PATCH_FILE> <SCRATCH_DIR> <GIT_CMD> <GREP_CMD> <PATCH_CMD> <FINDBUGS_HOME> <WORKSPACE_BASEDIR> <JAVA5_HOME>"
-        cleanupAndExit 0
-      fi
-      ### PATCH_FILE contains the location of the patchfile
-      PATCH_FILE=$2 
-      if [[ ! -e "$PATCH_FILE" ]] ; then
-        echo "Unable to locate the patch file $PATCH_FILE"
-        cleanupAndExit 0
-      fi
-      PATCH_DIR=$3
-      ### Check if $PATCH_DIR exists. If it does not exist, create a new directory
-      if [[ ! -e "$PATCH_DIR" ]] ; then
-	mkdir "$PATCH_DIR"
-	if [[ $? == 0 ]] ; then 
-	  echo "$PATCH_DIR has been created"
-	else
-	  echo "Unable to create $PATCH_DIR"
-	  cleanupAndExit 0
-	fi
-      fi
-      GIT=$4
-      GREP=$5
-      PATCH=$6
-      FINDBUGS_HOME=$7
-      BASEDIR=$8
-      JAVA5_HOME=${9}
-      ### Obtain the patch filename to append it to the version number
-      defect=`basename $PATCH_FILE` 
-      ;;
-    *)
-      echo "ERROR: usage $0 HUDSON [args] | DEVELOPER [args]"
-      cleanupAndExit 0
-      ;;
-  esac
-}
-
-###############################################################################
-checkout () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Testing patch for ${defect}."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  ### When run by a developer, if the workspace contains modifications, do not continue
-  # Ref http://stackoverflow.com/a/2659808 for details on checking dirty status
-  ${GIT} diff-index --quiet HEAD
-  if [[ $? -ne 0 ]] ; then
-    uncommitted=`${GIT} diff --name-only HEAD`
-    uncommitted="You have the following files with uncommitted changes:${NEWLINE}${uncommitted}"
-  fi
-  untracked="$(${GIT} ls-files --exclude-standard --others)" && test -z "${untracked}"
-  if [[ $? -ne 0 ]] ; then
-    untracked="You have untracked and unignored files:${NEWLINE}${untracked}"
-  fi
-
-  if [[ $HUDSON == "false" ]] ; then
-    if [[ $uncommitted || $untracked ]] ; then
-      echo "ERROR: can't run in a workspace that contains the following modifications"
-      echo ""
-      echo "${uncommitted}"
-      echo ""
-      echo "${untracked}"
-      cleanupAndExit 1
-    fi
-  else   
-    # I don't believe we need to do anything here - the jenkins job will
-    # cleanup the environment for us ("cleanup before checkout" action)
-    # on the precommit jenkins job
-    echo
-  fi
-  return $?
-}
-
-###############################################################################
-setup () {
-  ### Download latest patch file (ignoring .htm and .html) when run from patch process
-  if [[ $HUDSON == "true" ]] ; then
-    $WGET -q -O $PATCH_DIR/jira http://issues.apache.org/jira/browse/$defect
-    if [[ `$GREP -c 'Patch Available' $PATCH_DIR/jira` == 0 ]] ; then
-      echo "$defect is not \"Patch Available\".  Exiting."
-      cleanupAndExit 0
-    fi
-    relativePatchURL=`$GREP -o '"/jira/secure/attachment/[0-9]*/[^"]*' $PATCH_DIR/jira | $GREP -v -e 'htm[l]*$' | sort | tail -1 | $GREP -o '/jira/secure/attachment/[0-9]*/[^"]*'`
-    patchURL="http://issues.apache.org${relativePatchURL}"
-    patchNum=`echo $patchURL | $GREP -o '[0-9]*/' | $GREP -o '[0-9]*'`
-    echo "$defect patch is being downloaded at `date` from"
-    echo "$patchURL"
-    $WGET -q -O $PATCH_DIR/patch $patchURL
-    JIRA_COMMENT="Here are the results of testing the latest attachment 
-  $patchURL
-  against trunk revision ${GIT_COMMIT}."
-
-  ### Copy the patch file to $PATCH_DIR
-  else
-    cp $PATCH_FILE $PATCH_DIR/patch
-    if [[ $? == 0 ]] ; then
-      echo "Patch file $PATCH_FILE copied to $PATCH_DIR"
-    else
-      echo "Could not copy $PATCH_FILE to $PATCH_DIR"
-      cleanupAndExit 0
-    fi
-  fi
-  ### exit if warnings are NOT defined in the properties file
-  if [ -z "$OK_FINDBUGS_WARNINGS" ] || [[ -z "$OK_JAVADOC_WARNINGS" ]] || [[ -z $OK_RELEASEAUDIT_WARNINGS ]]; then
-    echo "Please define the following properties in test-patch.properties file"
-	 echo  "OK_FINDBUGS_WARNINGS"
-	 echo  "OK_RELEASEAUDIT_WARNINGS"
-	 echo  "OK_JAVADOC_WARNINGS"
-    cleanupAndExit 1
-  fi
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo " Pre-build trunk to verify trunk stability and javac warnings" 
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  echo "$ANT_HOME/bin/ant  -Djavac.args="-Xlint -Xmaxwarns 1000" -Djava5.home=${JAVA5_HOME} -DZookeeperPatchProcess= clean tar > $PATCH_DIR/trunkJavacWarnings.txt 2>&1"
- $ANT_HOME/bin/ant -Djavac.args="-Xlint -Xmaxwarns 1000" -Djava5.home=${JAVA5_HOME} -DZookeeperPatchProcess= clean tar > $PATCH_DIR/trunkJavacWarnings.txt 2>&1
-  if [[ $? != 0 ]] ; then
-    echo "Trunk compilation is broken?"
-    cleanupAndExit 1
-  fi
-}
-
-###############################################################################
-### Check for @author tags in the patch
-checkAuthor () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Checking there are no @author tags in the patch."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  authorTags=`$GREP -c -i '@author' $PATCH_DIR/patch`
-  echo "There appear to be $authorTags @author tags in the patch."
-  if [[ $authorTags != 0 ]] ; then
-    JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 @author.  The patch appears to contain $authorTags @author tags which the Zookeeper community has agreed to not allow in code contributions."
-    return 1
-  fi
-  JIRA_COMMENT="$JIRA_COMMENT
-
-    +1 @author.  The patch does not contain any @author tags."
-  return 0
-}
-
-###############################################################################
-### Check for tests in the patch
-checkTests () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Checking there are new or changed tests in the patch."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  testReferences=`$GREP -c -i '/test' $PATCH_DIR/patch`
-  echo "There appear to be $testReferences test files referenced in the patch."
-  if [[ $testReferences == 0 ]] ; then
-    if [[ $HUDSON == "true" ]] ; then
-      patchIsDoc=`$GREP -c -i 'title="documentation' $PATCH_DIR/jira`
-      if [[ $patchIsDoc != 0 ]] ; then
-        echo "The patch appears to be a documentation patch that doesn't require tests."
-        JIRA_COMMENT="$JIRA_COMMENT
-
-    +0 tests included.  The patch appears to be a documentation patch that doesn't require tests."
-        return 0
-      fi
-    fi
-    JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 tests included.  The patch doesn't appear to include any new or modified tests.
-                        Please justify why no new tests are needed for this patch.
-                        Also please list what manual steps were performed to verify this patch."
-    return 1
-  fi
-  JIRA_COMMENT="$JIRA_COMMENT
-
-    +1 tests included.  The patch appears to include $testReferences new or modified tests."
-  return 0
-}
-
-###############################################################################
-### Attempt to apply the patch
-applyPatch () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Applying patch."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  $PATCH -E -p0 < $PATCH_DIR/patch
-  if [[ $? != 0 ]] ; then
-    echo "PATCH APPLICATION FAILED"
-    JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 patch.  The patch command could not apply the patch."
-    return 1
-  fi
-  return 0
-}
-
-###############################################################################
-### Check there are no javadoc warnings
-checkJavadocWarnings () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Determining number of patched javadoc warnings."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  echo "$ANT_HOME/bin/ant -DZookeeperPatchProcess= clean javadoc | tee $PATCH_DIR/patchJavadocWarnings.txt"
-  $ANT_HOME/bin/ant -DZookeeperPatchProcess= clean javadoc | tee $PATCH_DIR/patchJavadocWarnings.txt
-  javadocWarnings=`$GREP -o '\[javadoc\] [0-9]* warning' $PATCH_DIR/patchJavadocWarnings.txt | awk '{total += $2} END {print total}'`
-  echo ""
-  echo ""
-  echo "There appear to be $javadocWarnings javadoc warnings generated by the patched build."
-
-  ### if current warnings greater than OK_JAVADOC_WARNINGS
-  if [[ $javadocWarnings > $OK_JAVADOC_WARNINGS ]] ; then
-    JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 javadoc.  The javadoc tool appears to have generated `expr $(($javadocWarnings-$OK_JAVADOC_WARNINGS))` warning messages."
-    return 1
-  fi
-  JIRA_COMMENT="$JIRA_COMMENT
-
-    +1 javadoc.  The javadoc tool did not generate any warning messages."
-  return 0
-}
-
-###############################################################################
-### Check there are no changes in the number of Javac warnings
-checkJavacWarnings () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Determining number of patched javac warnings."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  echo "$ANT_HOME/bin/ant -Djavac.args="-Xlint -Xmaxwarns 1000" -Djava5.home=${JAVA5_HOME} -DZookeeperPatchProcess= clean tar > $PATCH_DIR/patchJavacWarnings.txt 2>&1"
-  $ANT_HOME/bin/ant -Djavac.args="-Xlint -Xmaxwarns 1000" -Djava5.home=${JAVA5_HOME} -DZookeeperPatchProcess= clean tar > $PATCH_DIR/patchJavacWarnings.txt 2>&1
-  if [[ $? != 0 ]] ; then
-    JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 javac.  The patch appears to cause tar ant target to fail."
-    return 1
-  fi
-  ### Compare trunk and patch javac warning numbers
-  if [[ -f $PATCH_DIR/patchJavacWarnings.txt ]] ; then
-    trunkJavacWarnings=`$GREP -o '\[javac\] [0-9]* warning' $PATCH_DIR/trunkJavacWarnings.txt | awk '{total += $2} END {print total}'`
-    patchJavacWarnings=`$GREP -o '\[javac\] [0-9]* warning' $PATCH_DIR/patchJavacWarnings.txt | awk '{total += $2} END {print total}'`
-    echo "There appear to be $trunkJavacWarnings javac compiler warnings before the patch and $patchJavacWarnings javac compiler warnings after applying the patch."
-    if [[ $patchJavacWarnings != "" && $trunkJavacWarnings != "" ]] ; then
-      if [[ $patchJavacWarnings -gt $trunkJavacWarnings ]] ; then
-        JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 javac.  The applied patch generated $patchJavacWarnings javac compiler warnings (more than the trunk's current $trunkJavacWarnings warnings)."
-        return 1
-      fi
-    fi
-  fi
-  JIRA_COMMENT="$JIRA_COMMENT
-
-    +1 javac.  The applied patch does not increase the total number of javac compiler warnings."
-  return 0
-}
-
-###############################################################################
-### Check there are no changes in the number of release audit (RAT) warnings
-checkReleaseAuditWarnings () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Determining number of patched release audit warnings."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  echo "$ANT_HOME/bin/ant -Djava5.home=${JAVA5_HOME} -DZookeeperPatchProcess= releaseaudit > $PATCH_DIR/patchReleaseAuditWarnings.txt 2>&1"
-  $ANT_HOME/bin/ant -Djava5.home=${JAVA5_HOME} -DZookeeperPatchProcess= releaseaudit > $PATCH_DIR/patchReleaseAuditWarnings.txt 2>&1
-
-  ### Compare trunk and patch release audit warning numbers
-  if [[ -f $PATCH_DIR/patchReleaseAuditWarnings.txt ]] ; then
-    patchReleaseAuditWarnings=`$GREP -c '\!?????' $PATCH_DIR/patchReleaseAuditWarnings.txt`
-    echo ""
-    echo ""
-    echo "There appear to be $OK_RELEASEAUDIT_WARNINGS release audit warnings before the patch and $patchReleaseAuditWarnings release audit warnings after applying the patch."
-    if [[ $patchReleaseAuditWarnings != "" && $OK_RELEASEAUDIT_WARNINGS != "" ]] ; then
-      if [[ $patchReleaseAuditWarnings -gt $OK_RELEASEAUDIT_WARNINGS ]] ; then
-        JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 release audit.  The applied patch generated $patchReleaseAuditWarnings release audit warnings (more than the trunk's current $OK_RELEASEAUDIT_WARNINGS warnings)."
-        $GREP '\!?????' $PATCH_DIR/patchReleaseAuditWarnings.txt > $PATCH_DIR/patchReleaseAuditProblems.txt
-        echo "Lines that start with ????? in the release audit report indicate files that do not have an Apache license header." >> $PATCH_DIR/patchReleaseAuditProblems.txt
-        JIRA_COMMENT_FOOTER="Release audit warnings: $BUILD_URL/artifact/trunk/patchprocess/patchReleaseAuditProblems.txt
-$JIRA_COMMENT_FOOTER"
-        return 1
-      fi
-    fi
-  fi
-  JIRA_COMMENT="$JIRA_COMMENT
-
-    +1 release audit.  The applied patch does not increase the total number of release audit warnings."
-  return 0
-}
-
-###############################################################################
-### Check there are no changes in the number of Checkstyle warnings
-checkStyle () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Determining number of patched checkstyle warnings."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  echo "THIS IS NOT IMPLEMENTED YET"
-  echo ""
-  echo ""
-  echo "$ANT_HOME/bin/ant -DZookeeperPatchProcess= checkstyle"
-  $ANT_HOME/bin/ant -DZookeeperPatchProcess= checkstyle
-  JIRA_COMMENT_FOOTER="Checkstyle results: $BUILD_URL/artifact/trunk/build/test/checkstyle-errors.html
-$JIRA_COMMENT_FOOTER"
-  ### TODO: calculate actual patchStyleErrors
-#  patchStyleErrors=0
-#  if [[ $patchStyleErrors != 0 ]] ; then
-#    JIRA_COMMENT="$JIRA_COMMENT
-#
-#    -1 checkstyle.  The patch generated $patchStyleErrors code style errors."
-#    return 1
-#  fi
-#  JIRA_COMMENT="$JIRA_COMMENT
-#
-#    +1 checkstyle.  The patch generated 0 code style errors."
-  return 0
-}
-
-###############################################################################
-### Check there are no changes in the number of Findbugs warnings
-checkFindbugsWarnings () {
-  findbugs_version=`${FINDBUGS_HOME}/bin/findbugs -version`
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Determining number of patched Findbugs warnings."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  echo "$ANT_HOME/bin/ant -Dfindbugs.home=$FINDBUGS_HOME -Djava5.home=${JAVA5_HOME} -DZookeeperPatchProcess= findbugs"
-  $ANT_HOME/bin/ant -Dfindbugs.home=$FINDBUGS_HOME -Djava5.home=${JAVA5_HOME} -DZookeeperPatchProcess= findbugs
-  if [ $? != 0 ] ; then
-    JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 findbugs.  The patch appears to cause Findbugs (version ${findbugs_version}) to fail."
-    return 1
-  fi
-JIRA_COMMENT_FOOTER="Findbugs warnings: $BUILD_URL/artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html
-$JIRA_COMMENT_FOOTER"
-  cp $BASEDIR/build/test/findbugs/*.xml $PATCH_DIR/patchFindbugsWarnings.xml
-  $FINDBUGS_HOME/bin/setBugDatabaseInfo -timestamp "01/01/2000" \
-    $PATCH_DIR/patchFindbugsWarnings.xml \
-    $PATCH_DIR/patchFindbugsWarnings.xml
-  findbugsWarnings=`$FINDBUGS_HOME/bin/filterBugs -first "01/01/2000" $PATCH_DIR/patchFindbugsWarnings.xml \
-    $BASEDIR/build/test/findbugs/newPatchFindbugsWarnings.xml | /usr/bin/awk '{print $1}'`
-  $FINDBUGS_HOME/bin/convertXmlToText -html \
-    $BASEDIR/build/test/findbugs/newPatchFindbugsWarnings.xml \
-    $BASEDIR/build/test/findbugs/newPatchFindbugsWarnings.html
-  cp $BASEDIR/build/test/findbugs/newPatchFindbugsWarnings.html $PATCH_DIR/newPatchFindbugsWarnings.html
-  cp $BASEDIR/build/test/findbugs/newPatchFindbugsWarnings.xml $PATCH_DIR/newPatchFindbugsWarnings.xml
-
-  ### if current warnings greater than OK_FINDBUGS_WARNINGS
-  if [[ $findbugsWarnings > $OK_FINDBUGS_WARNINGS ]] ; then
-    JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 findbugs.  The patch appears to introduce `expr $(($findbugsWarnings-$OK_FINDBUGS_WARNINGS))` new Findbugs (version ${findbugs_version}) warnings."
-    return 1
-  fi
-  JIRA_COMMENT="$JIRA_COMMENT
-
-    +1 findbugs.  The patch does not introduce any new Findbugs (version ${findbugs_version}) warnings."
-  return 0
-}
-
-###############################################################################
-### Run the test-core target
-runCoreTests () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Running core tests."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  
-  ### Kill any rogue build processes from the last attempt
-  $PS auxwww | $GREP ZookeeperPatchProcess | /usr/bin/nawk '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null
-
-  echo "$ANT_HOME/bin/ant -DZookeeperPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=yes -Dtest.junit.threads=8 -Dcompile.c++=yes -Djava5.home=$JAVA5_HOME test-core"
-  $ANT_HOME/bin/ant -DZookeeperPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=yes -Dtest.junit.threads=8 -Dcompile.c++=yes -Djava5.home=$JAVA5_HOME test-core
-  if [[ $? != 0 ]] ; then
-    JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 core tests.  The patch failed core unit tests."
-    return 1
-  fi
-  JIRA_COMMENT="$JIRA_COMMENT
-
-    +1 core tests.  The patch passed core unit tests."
-  return 0
-}
-
-###############################################################################
-### Run the test-contrib target
-runContribTests () {
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Running contrib tests."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-
-  ### Kill any rogue build processes from the last attempt
-  $PS auxwww | $GREP ZookeeperPatchProcess | /usr/bin/nawk '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null
-
-  echo "$ANT_HOME/bin/ant -DZookeeperPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=yes test-contrib"
-  $ANT_HOME/bin/ant -DZookeeperPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=yes test-contrib
-  if [[ $? != 0 ]] ; then
-    JIRA_COMMENT="$JIRA_COMMENT
-
-    -1 contrib tests.  The patch failed contrib unit tests."
-    return 1
-  fi
-  JIRA_COMMENT="$JIRA_COMMENT
-
-    +1 contrib tests.  The patch passed contrib unit tests."
-  return 0
-}
-
-###############################################################################
-### Submit a comment to the defect's Jira
-submitJiraComment () {
-  local result=$1
-  ### Do not output the value of JIRA_COMMENT_FOOTER when run by a developer
-  if [[  $HUDSON == "false" ]] ; then
-    JIRA_COMMENT_FOOTER=""
-  fi
-  if [[ $result == 0 ]] ; then
-    comment="+1 overall.  $JIRA_COMMENT
-
-$JIRA_COMMENT_FOOTER"
-  else
-    comment="-1 overall.  $JIRA_COMMENT
-
-$JIRA_COMMENT_FOOTER"
-  fi
-  ### Output the test result to the console
-  echo "
-
-
-
-$comment"  
-
-  if [[ $HUDSON == "true" ]] ; then
-    echo ""
-    echo ""
-    echo "======================================================================"
-    echo "======================================================================"
-    echo "    Adding comment to Jira."
-    echo "======================================================================"
-    echo "======================================================================"
-    echo ""
-    echo ""
-    ### Update Jira with a comment
-    export USER=jenkins
-    $JIRACLI -s https://issues.apache.org/jira -a addcomment -u hadoopqa -p $JIRA_PASSWD --comment "$comment" --issue $defect
-    $JIRACLI -s https://issues.apache.org/jira -a logout -u hadoopqa -p $JIRA_PASSWD
-  fi
-}
-
-###############################################################################
-### Cleanup files
-cleanupAndExit () {
-  local result=$1
-  if [[ $HUDSON == "true" ]] ; then
-    if [ -e "$PATCH_DIR" ] ; then
-      mv $PATCH_DIR $BASEDIR
-    fi
-  fi
-  echo ""
-  echo ""
-  echo "======================================================================"
-  echo "======================================================================"
-  echo "    Finished build."
-  echo "======================================================================"
-  echo "======================================================================"
-  echo ""
-  echo ""
-  exit $result
-}
-
-###############################################################################
-###############################################################################
-###############################################################################
-
-JIRA_COMMENT=""
-JIRA_COMMENT_FOOTER="Console output: $BUILD_URL/console
-
-This message is automatically generated."
-
-### Check if arguments to the script have been specified properly or not
-parseArgs $@
-cd $BASEDIR
-
-checkout
-RESULT=$?
-if [[ $HUDSON == "true" ]] ; then
-  if [[ $RESULT != 0 ]] ; then
-    exit 100
-  fi
-fi
-setup
-checkAuthor
-RESULT=$?
-
-checkTests
-(( RESULT = RESULT + $? ))
-applyPatch
-if [[ $? != 0 ]] ; then
-  submitJiraComment 1
-  cleanupAndExit 1
-fi
-checkJavadocWarnings
-(( RESULT = RESULT + $? ))
-checkJavacWarnings
-(( RESULT = RESULT + $? ))
-### Checkstyle not implemented yet
-#checkStyle
-#(( RESULT = RESULT + $? ))
-checkFindbugsWarnings
-(( RESULT = RESULT + $? ))
-checkReleaseAuditWarnings
-(( RESULT = RESULT + $? ))
-### Do not call these when run by a developer 
-if [[ $HUDSON == "true" ]] ; then
-  runCoreTests
-  (( RESULT = RESULT + $? ))
-  runContribTests
-  (( RESULT = RESULT + $? ))
-fi
-JIRA_COMMENT_FOOTER="Test results: $BUILD_URL/testReport/
-$JIRA_COMMENT_FOOTER"
-
-submitJiraComment $RESULT
-cleanupAndExit $RESULT

+ 0 - 221
zookeeper-server/src/test/resources/test-scripts.sh

@@ -1,221 +0,0 @@
-#!/usr/bin/env bash
-
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-ZKS=bin/zkServer.sh
-ZKSI=bin/zkServer-initialize.sh
-
-if [ ! -d "conf" ]; then
-    echo "run this from the toplevel directory"
-    exit 1
-fi
-
-DATADIR=test-scripts_datadir
-DATALOGDIR=test-scripts_datalogdir
-
-case "`uname`" in
-    CYGWIN*) cygwin=true ;;
-    *) cygwin=false ;;
-esac
-
-if $cygwin
-then
-    ZOOCFG=`cygpath -wp "$ZOOCFG"`
-    # cygwin has a "kill" in the shell itself, gets confused
-    KILL=/bin/kill
-else
-    KILL=kill
-fi
-
-fail() {
-    # don't run clear_tmp to allow debugging
-    echo "FAIL $1"
-    $KILL -9 $(cat "$ZOOPIDFILE")
-    $KILL -9 $$
-}
-
-#generate a minimal config
-genconfig1() {
-    cat > test-scripts.cfg <<EOF
-tickTime=2000
-initLimit=10
-syncLimit=5
-dataDir=$DATADIR
-clientPort=19181
-EOF
-}
-
-genconfig2() {
-    genconfig1
-    cat >> test-scripts.cfg <<EOF
-dataLogDir=$DATALOGDIR
-EOF
-}
-
-export ZOOCFGDIR=`pwd`
-export ZOOCFG="test-scripts.cfg"
-export CLASSPATH=$ZOOCFGDIR/conf
-
-#clear out the clutter generated by scripts
-clear_tmp() {
-    rm -f test-scripts.cfg
-    rm -fr $DATADIR
-    rm -fr $DATALOGDIR
-    rm -f zookeeper.out
-}
-
-start() {
-    $CONFIG
-    #ensure not already running
-    $ZKS status && (echo "already running"; fail $LINENO)
-    export ZOOPIDFILE="$DATADIR/zookeeper_server.pid"
-
-    $ZKS start
-}
-
-stop() {
-    $ZKS stop
-}
-
-CONFIG=genconfig1
-
-clear_tmp
-start
-ls $DATADIR || fail $LINENO
-ls $DATALOGDIR && fail $LINENO
-stop
-
-CONFIG=genconfig2
-
-clear_tmp
-start
-ls $DATADIR || fail $LINENO
-
-# zk actually checks for this to exist, but doesn't create
-ls $DATALOGDIR && fail $LINENO
-
-clear_tmp
-mkdir -p "$DATALOGDIR"
-start
-ls $DATADIR || fail $LINENO
-ls $DATALOGDIR || fail $LINENO
-stop
-
-#
-# verify autocreate disabled
-#
-export ZOO_DATADIR_AUTOCREATE_DISABLE=1
-
-CONFIG=genconfig1
-
-clear_tmp
-start
-[ $? -eq 1 ] || fail $LINENO
-ls $DATADIR && fail $LINENO
-ls $DATALOGDIR && fail $LINENO
-
-CONFIG=genconfig2
-
-clear_tmp
-mkdir -p "$DATADIR/version-2"
-start
-[ $? -eq 1 ] || fail $LINENO
-ls $DATALOGDIR && fail $LINENO
-
-CONFIG=genconfig1
-
-clear_tmp
-mkdir -p "$DATADIR/version-2"
-start
-[ $? -eq 0 ] || fail $LINENO
-stop
-
-CONFIG=genconfig2
-
-clear_tmp
-mkdir -p "$DATADIR/version-2"
-mkdir -p "$DATALOGDIR/version-2"
-start
-[ $? -eq 0 ] || fail $LINENO
-stop
-
-#
-# validate the initialize script
-#
-
-CONFIG=genconfig1
-
-clear_tmp
-$CONFIG
-
-$ZKSI --configfile "$ZOOCFGDIR/$ZOOCFG"
-ls $DATADIR || fail $LINENO
-
-#ensure not already running
-$ZKS status && (echo "already running"; fail $LINENO)
-export ZOOPIDFILE="$DATADIR/zookeeper_server.pid"
-
-$ZKS start
-[ $? -eq 0 ] || fail $LINENO
-stop
-
-
-CONFIG=genconfig2
-
-clear_tmp
-$CONFIG
-
-$ZKSI --configfile "$ZOOCFGDIR/$ZOOCFG"
-ls $DATADIR || fail $LINENO
-ls $DATALOGDIR || fail $LINENO
-
-#ensure not already running
-$ZKS status && (echo "already running"; fail $LINENO)
-export ZOOPIDFILE="$DATADIR/zookeeper_server.pid"
-
-$ZKS start
-[ $? -eq 0 ] || fail $LINENO
-stop
-
-
-## validate force
-CONFIG=genconfig1
-
-clear_tmp
-$CONFIG
-
-$ZKSI --configfile "$ZOOCFGDIR/$ZOOCFG" || fail $LINENO
-ls $DATADIR || fail $LINENO
-$ZKSI --configfile "$ZOOCFGDIR/$ZOOCFG" && fail $LINENO
-$ZKSI --force --configfile "$ZOOCFGDIR/$ZOOCFG" || fail $LINENO
-
-#ensure not already running
-$ZKS status && (echo "already running"; fail $LINENO)
-export ZOOPIDFILE="$DATADIR/zookeeper_server.pid"
-
-$ZKS start
-[ $? -eq 0 ] || fail $LINENO
-stop
-
-$ZKSI --force --myid=1 --configfile "$ZOOCFGDIR/$ZOOCFG" || fail $LINENO
-
-#test version script
-TEST_PRINT_VERSION=`$ZKS version 2>/dev/null`
-[ "$TEST_PRINT_VERSION" != "" ] || fail $LINENO
-
-#done, cleanup and exit
-clear_tmp
-echo "SUCCESS"