You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@fluo.apache.org by GitBox <gi...@apache.org> on 2020/08/20 15:15:10 UTC

[GitHub] [fluo-uno] ctubbsii opened a new pull request #254: Do more with ShellCheck

ctubbsii opened a new pull request #254:
URL: https://github.com/apache/fluo-uno/pull/254


   * Fix numerous issues to make ShellCheck pass across `bin/*` and
     `conf/uno.conf`
   * Add GitHub Actions and CI script for automated ShellCheck testing
   * Add missing checksum for latest Hadoop 3.1, since it's still supported
     by Accumulo
   * Fix parameter passing for `--no-deps` flag
   * Build SNAPSHOT version with correct version of Guava for Hadoop 3.1
     and later
   * Make some long if statements into more concise `&&` syntax for
     readability
   * Remove some unnecessary quoting
   * Rely on return code for pgrep for many statements that were previously
     relying on its output unnecessarily


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [fluo-uno] ctubbsii commented on a change in pull request #254: Do more with ShellCheck

Posted by GitBox <gi...@apache.org>.
ctubbsii commented on a change in pull request #254:
URL: https://github.com/apache/fluo-uno/pull/254#discussion_r474222177



##########
File path: bin/impl/install.sh
##########
@@ -15,6 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+# shellcheck source=bin/impl/util.sh

Review comment:
       Yes, exactly.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [fluo-uno] ctubbsii commented on a change in pull request #254: Do more with ShellCheck

Posted by GitBox <gi...@apache.org>.
ctubbsii commented on a change in pull request #254:
URL: https://github.com/apache/fluo-uno/pull/254#discussion_r477265508



##########
File path: bin/uno
##########
@@ -17,89 +17,33 @@
 
 # Start: Resolve Script Directory
 SOURCE="${BASH_SOURCE[0]}"
-while [[ -h "$SOURCE" ]]; do # resolve $SOURCE until the file is no longer a symlink
+# resolve $SOURCE until the file is no longer a symlink
+while [[ -h "$SOURCE" ]]; do
    bin="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
    SOURCE="$(readlink "$SOURCE")"
-   [[ $SOURCE != /* ]] && SOURCE="$bin/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
+   # if $SOURCE was a relative symlink, we need to resolve it relative to the
+   # path where the symlink file was located
+   [[ $SOURCE != /* ]] && SOURCE="$bin/$SOURCE"
 done
 bin="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
 # Stop: Resolve Script Directory
 
-source "$bin"/impl/load-env.sh "$1"
-source "$UNO_HOME"/bin/impl/util.sh
+uno_cmd=$1
+shift
 
-case "$1" in
-  ashell)
-    check_dirs ACCUMULO_HOME
-    "$ACCUMULO_HOME"/bin/accumulo shell -u "$ACCUMULO_USER" -p "$ACCUMULO_PASSWORD" "${@:2}"
-    ;;
-  zk)
-    check_dirs ZOOKEEPER_HOME 
-    "$ZOOKEEPER_HOME"/bin/zkCli.sh
-    ;;
-  env)
-    "$bin"/impl/print-env.sh "${@:2}"
-    ;;
-  fetch)
-    hash mvn 2>/dev/null || { echo >&2 "Maven must be installed & on PATH. Aborting."; exit 1; }
-    hash wget 2>/dev/null || { echo >&2 "wget must be installed & on PATH. Aborting."; exit 1; }
-    if [[ "$2" == "all" ]]; then
-      "$bin"/impl/fetch.sh fluo
-    else
-      "$bin"/impl/fetch.sh "$2" "$3"
-    fi
-    ;;
-  install)
-    "$bin"/impl/install.sh "${@:2}"
-    ;;
-  kill)
-    "$bin"/impl/kill.sh "${@:2}"
-    ;;
-  run)
-    "$bin"/impl/run.sh "${@:2}"
-    ;;
-  setup)
-    "$bin"/impl/setup.sh "${@:2}"
-    ;;
-  start)
-    "$bin"/impl/start.sh "${@:2}"
-    ;;
-  stop)
-    "$bin"/impl/stop.sh "${@:2}"
-    ;;
-  version)
-    "$bin"/impl/version.sh "${@:2}"
-    ;;
-  
-  status)
-    "$bin"/impl/status.sh "${@:2}"
-    ;;
- 
-  wipe)
-    "$bin"/impl/kill.sh
-    if [[ -d "$INSTALL" ]]; then
-      echo "removing $INSTALL"
-      rm -rf "$INSTALL"
-    fi
+# shellcheck source=bin/impl/load-env.sh
+source "$bin"/impl/load-env.sh "$uno_cmd"
+# shellcheck source=bin/impl/commands.sh
+source "$UNO_HOME"/bin/impl/commands.sh
+
+case "$uno_cmd" in
+  ashell|env|fetch|install|kill|run|setup|start|status|stop|version|wipe|zk)
+    "uno_${uno_cmd}_main" "$@"

Review comment:
       I like this, and thought about doing something like this, but didn't look into it to figure out the syntax. One thing I wasn't sure about was compatibility with Bash 3. I tried to avoid any changes I thought might not work on Bash 3. Since I don't have a macOS machine to test on, I chose to avoid this one because of uncertainty of whether it would work there.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [fluo-uno] ctubbsii commented on pull request #254: Do more with ShellCheck

Posted by GitBox <gi...@apache.org>.
ctubbsii commented on pull request #254:
URL: https://github.com/apache/fluo-uno/pull/254#issuecomment-679311347


   @keith-turner I fixed the previous error, if you want to take another pass at a review.
   
   Some of the conditional statements in bash at the end of some scripts were returning `false`, which resulted in the return code for the entire script being false, and causing some of the steps to not execute.
   
   I fixed this by adding a 'true' statement at the end of called scripts, so that they don't return false, if they aren't supposed to.
   
   In order to track this down, I ended up consolidating a few smaller scripts into a single script with multiple functions. This refactor helped me track down the bug fix the problem. I'm leaving it included in this PR, because I think it's better this way, and using functions instead of scripts helps with understanding return codes.
   
   I think there's more opportunities to clean up additional things in these scripts, but this PR is already too big, so I'll defer to another time.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [fluo-uno] ctubbsii commented on a change in pull request #254: Do more with ShellCheck

Posted by GitBox <gi...@apache.org>.
ctubbsii commented on a change in pull request #254:
URL: https://github.com/apache/fluo-uno/pull/254#discussion_r477263613



##########
File path: bin/impl/fetch.sh
##########
@@ -122,13 +116,20 @@ zookeeper)
   fetch_zookeeper
   ;;
 *)
-  echo "Usage: uno fetch <component>"
-  echo -e "\nPossible components:\n"
-  echo "    accumulo   Downloads Accumulo, Hadoop & ZooKeeper. Builds Accumulo if repo set in uno.conf"
-  echo "    fluo       Downloads Fluo, Accumulo, Hadoop & ZooKeeper. Builds Fluo or Accumulo if repo set in uno.conf"
-  echo "    hadoop     Downloads Hadoop"
-  echo "    zookeeper  Downloads ZooKeeper"
-  echo "Options:"
-  echo "    --no-deps  Dependencies will be fetched unless this option is specified. Only works for fluo & accumulo components."
+  cat <<EOF
+Usage: uno fetch <component>
+
+Possible components:
+
+    accumulo   Downloads Accumulo, Hadoop & ZooKeeper. Builds Accumulo if repo set in uno.conf
+    fluo       Downloads Fluo, Accumulo, Hadoop & ZooKeeper. Builds Fluo or Accumulo if repo set in uno.conf
+    hadoop     Downloads Hadoop
+    zookeeper  Downloads ZooKeeper
+
+Options:
+    --no-deps  Dependencies will be fetched unless this option is specified. Only works for fluo & accumulo components.
+EOF
   exit 1
 esac
+
+# fetch.sh

Review comment:
       It's mostly style. They help me remember which file I'm editing, and help provide a non-empty final line for the script, so that I don't get warnings with `git add --patch`. But, they serve no real functional purpose.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [fluo-uno] ctubbsii commented on a change in pull request #254: Do more with ShellCheck

Posted by GitBox <gi...@apache.org>.
ctubbsii commented on a change in pull request #254:
URL: https://github.com/apache/fluo-uno/pull/254#discussion_r474222177



##########
File path: bin/impl/install.sh
##########
@@ -15,6 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+# shellcheck source=bin/impl/util.sh

Review comment:
       Yes, exactly. Because it can't predict the value of `$UNO_HOME` to resolve it itself.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [fluo-uno] keith-turner commented on a change in pull request #254: Do more with ShellCheck

Posted by GitBox <gi...@apache.org>.
keith-turner commented on a change in pull request #254:
URL: https://github.com/apache/fluo-uno/pull/254#discussion_r476907831



##########
File path: bin/impl/fetch.sh
##########
@@ -122,13 +116,20 @@ zookeeper)
   fetch_zookeeper
   ;;
 *)
-  echo "Usage: uno fetch <component>"
-  echo -e "\nPossible components:\n"
-  echo "    accumulo   Downloads Accumulo, Hadoop & ZooKeeper. Builds Accumulo if repo set in uno.conf"
-  echo "    fluo       Downloads Fluo, Accumulo, Hadoop & ZooKeeper. Builds Fluo or Accumulo if repo set in uno.conf"
-  echo "    hadoop     Downloads Hadoop"
-  echo "    zookeeper  Downloads ZooKeeper"
-  echo "Options:"
-  echo "    --no-deps  Dependencies will be fetched unless this option is specified. Only works for fluo & accumulo components."
+  cat <<EOF
+Usage: uno fetch <component>
+
+Possible components:
+
+    accumulo   Downloads Accumulo, Hadoop & ZooKeeper. Builds Accumulo if repo set in uno.conf
+    fluo       Downloads Fluo, Accumulo, Hadoop & ZooKeeper. Builds Fluo or Accumulo if repo set in uno.conf
+    hadoop     Downloads Hadoop
+    zookeeper  Downloads ZooKeeper
+
+Options:
+    --no-deps  Dependencies will be fetched unless this option is specified. Only works for fluo & accumulo components.
+EOF
   exit 1
 esac
+
+# fetch.sh

Review comment:
       What is the purpose of these comments?

##########
File path: bin/uno
##########
@@ -17,89 +17,33 @@
 
 # Start: Resolve Script Directory
 SOURCE="${BASH_SOURCE[0]}"
-while [[ -h "$SOURCE" ]]; do # resolve $SOURCE until the file is no longer a symlink
+# resolve $SOURCE until the file is no longer a symlink
+while [[ -h "$SOURCE" ]]; do
    bin="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
    SOURCE="$(readlink "$SOURCE")"
-   [[ $SOURCE != /* ]] && SOURCE="$bin/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
+   # if $SOURCE was a relative symlink, we need to resolve it relative to the
+   # path where the symlink file was located
+   [[ $SOURCE != /* ]] && SOURCE="$bin/$SOURCE"
 done
 bin="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
 # Stop: Resolve Script Directory
 
-source "$bin"/impl/load-env.sh "$1"
-source "$UNO_HOME"/bin/impl/util.sh
+uno_cmd=$1
+shift
 
-case "$1" in
-  ashell)
-    check_dirs ACCUMULO_HOME
-    "$ACCUMULO_HOME"/bin/accumulo shell -u "$ACCUMULO_USER" -p "$ACCUMULO_PASSWORD" "${@:2}"
-    ;;
-  zk)
-    check_dirs ZOOKEEPER_HOME 
-    "$ZOOKEEPER_HOME"/bin/zkCli.sh
-    ;;
-  env)
-    "$bin"/impl/print-env.sh "${@:2}"
-    ;;
-  fetch)
-    hash mvn 2>/dev/null || { echo >&2 "Maven must be installed & on PATH. Aborting."; exit 1; }
-    hash wget 2>/dev/null || { echo >&2 "wget must be installed & on PATH. Aborting."; exit 1; }
-    if [[ "$2" == "all" ]]; then
-      "$bin"/impl/fetch.sh fluo
-    else
-      "$bin"/impl/fetch.sh "$2" "$3"
-    fi
-    ;;
-  install)
-    "$bin"/impl/install.sh "${@:2}"
-    ;;
-  kill)
-    "$bin"/impl/kill.sh "${@:2}"
-    ;;
-  run)
-    "$bin"/impl/run.sh "${@:2}"
-    ;;
-  setup)
-    "$bin"/impl/setup.sh "${@:2}"
-    ;;
-  start)
-    "$bin"/impl/start.sh "${@:2}"
-    ;;
-  stop)
-    "$bin"/impl/stop.sh "${@:2}"
-    ;;
-  version)
-    "$bin"/impl/version.sh "${@:2}"
-    ;;
-  
-  status)
-    "$bin"/impl/status.sh "${@:2}"
-    ;;
- 
-  wipe)
-    "$bin"/impl/kill.sh
-    if [[ -d "$INSTALL" ]]; then
-      echo "removing $INSTALL"
-      rm -rf "$INSTALL"
-    fi
+# shellcheck source=bin/impl/load-env.sh
+source "$bin"/impl/load-env.sh "$uno_cmd"
+# shellcheck source=bin/impl/commands.sh
+source "$UNO_HOME"/bin/impl/commands.sh
+
+case "$uno_cmd" in
+  ashell|env|fetch|install|kill|run|setup|start|status|stop|version|wipe|zk)
+    "uno_${uno_cmd}_main" "$@"

Review comment:
       This is a nice refactoring.  Its a bit hard to review, I am just going to trust that you copied the code from the files to functions correctly. 
   
   Instead of having the switch statement enumerate all the command names, wonder if it would work to check if the function exists instead.  Maybe something like the following, although I am not sure if it would even work.
   
   ```bash
   if [ "$(type -t uno_${uno_cmd}_main)" = 'function' ]; then
       "uno_${uno_cmd}_main" "$@"
   else
      uno_help_main "$@"
   fi
   ```
   
   Below is a post I found about checking if a function exists in bash to write the above.
   
   https://stackoverflow.com/questions/1007538/check-if-a-function-exists-from-a-bash-script




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [fluo-uno] keith-turner commented on a change in pull request #254: Do more with ShellCheck

Posted by GitBox <gi...@apache.org>.
keith-turner commented on a change in pull request #254:
URL: https://github.com/apache/fluo-uno/pull/254#discussion_r474199567



##########
File path: bin/impl/install.sh
##########
@@ -15,6 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+# shellcheck source=bin/impl/util.sh

Review comment:
       What is the purpose of this comment? does it help shellcheck find the file being sourced?

##########
File path: README.md
##########
@@ -188,17 +188,19 @@ applications or follow the instructions starting at the [Configure a Fluo applic
 section of the Fluo install instructions. These instructions will guide you through the process of
 configuring, initializing, and starting your application.
 
-[fluo]: http://fluo.apache.org/
-[accumulo]: http://accumulo.apache.org/
-[zookeeper]: http://zookeeper.apache.org/
-[hadoop]: http://hadoop.apache.org/
-[mirrors]: http://www.apache.org/dyn/closer.cgi
-[Webindex]: https://github.com/apache/fluo-examples/tree/main/webindex
+[Accumulo Proxy]: https://github.com/apache/accumulo-proxy
+[Muchos]: https://github.com/apache/fluo-muchos
 [Phrasecount]: https://github.com/apache/fluo-examples/tree/main/phrasecount
+[Webindex]: https://github.com/apache/fluo-examples/tree/main/webindex

Review comment:
       Seems like you sorted these.  Curious how you did that.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [fluo-uno] ctubbsii merged pull request #254: Do more with ShellCheck

Posted by GitBox <gi...@apache.org>.
ctubbsii merged pull request #254:
URL: https://github.com/apache/fluo-uno/pull/254


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [fluo-uno] ctubbsii commented on pull request #254: Do more with ShellCheck

Posted by GitBox <gi...@apache.org>.
ctubbsii commented on pull request #254:
URL: https://github.com/apache/fluo-uno/pull/254#issuecomment-677859599


   This isn't quite ready for merging. I saw a bug where this didn't properly trigger the install of ZooKeeper after installing Hadoop, when doing `uno setup accumulo` *without* doing `. <(uno env)`. You shouldn't need to source the environment for Uno to work properly..  I'm going to have to try to track down the relevant change before I can merge this.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [fluo-uno] ctubbsii commented on a change in pull request #254: Do more with ShellCheck

Posted by GitBox <gi...@apache.org>.
ctubbsii commented on a change in pull request #254:
URL: https://github.com/apache/fluo-uno/pull/254#discussion_r474221878



##########
File path: README.md
##########
@@ -188,17 +188,19 @@ applications or follow the instructions starting at the [Configure a Fluo applic
 section of the Fluo install instructions. These instructions will guide you through the process of
 configuring, initializing, and starting your application.
 
-[fluo]: http://fluo.apache.org/
-[accumulo]: http://accumulo.apache.org/
-[zookeeper]: http://zookeeper.apache.org/
-[hadoop]: http://hadoop.apache.org/
-[mirrors]: http://www.apache.org/dyn/closer.cgi
-[Webindex]: https://github.com/apache/fluo-examples/tree/main/webindex
+[Accumulo Proxy]: https://github.com/apache/accumulo-proxy
+[Muchos]: https://github.com/apache/fluo-muchos
 [Phrasecount]: https://github.com/apache/fluo-examples/tree/main/phrasecount
+[Webindex]: https://github.com/apache/fluo-examples/tree/main/webindex

Review comment:
       I did, using vim visual mode... select a bunch of lines, and do `:sort`. You can also do `:sort u` for uniqueness.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org