DRILL-432: Can not run 'sqlline' on Windows with CYGWIN
* Clean up and unify various shell scripts.


Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/822cbb06
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/822cbb06
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/822cbb06

Branch: refs/heads/master
Commit: 822cbb0692a99969c19305096a5ba4a948e120c8
Parents: 6804b52
Author: Aditya Kishore <[email protected]>
Authored: Fri Mar 21 16:39:42 2014 -0700
Committer: Jacques Nadeau <[email protected]>
Committed: Sat Mar 22 10:04:11 2014 -0700

----------------------------------------------------------------------
 distribution/src/resources/drill-config.sh | 135 ++++++++++++++++--------
 distribution/src/resources/runbit          |  29 +----
 distribution/src/resources/sqlline         |  50 ++-------
 distribution/src/resources/submit_plan     |  33 +-----
 4 files changed, 105 insertions(+), 142 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/822cbb06/distribution/src/resources/drill-config.sh
----------------------------------------------------------------------
diff --git a/distribution/src/resources/drill-config.sh 
b/distribution/src/resources/drill-config.sh
index 7be5bad..d5667f9 100644
--- a/distribution/src/resources/drill-config.sh
+++ b/distribution/src/resources/drill-config.sh
@@ -1,31 +1,32 @@
+# 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.
 #
-#/**
-# * Copyright 2013 The Apache Software Foundation
-# *
-# * 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.
-# */
-
 # included in all the drill scripts with source command
 # should not be executable directly
 # also should not be passed any arguments, since we need original $*
-# Modelled after $HADOOP_HOME/bin/hadoop-env.sh.
+# Modelled after $HADOOP_HOME/bin/hadoop-config.sh
+#
+# Environment Variables:
+#
+#   JAVA_HOME        The java implementation to use.
+#
+#   DRILL_CLASSPATH  Extra Java CLASSPATH entries.
+#
+#   HADOOP_HOME      Hadoop home
 
 # resolve links - "${BASH_SOURCE-$0}" may be a softlink
-
 this="${BASH_SOURCE-$0}"
 while [ -h "$this" ]; do
   ls=`ls -ld "$this"`
@@ -40,19 +41,17 @@ done
 # convert relative path to absolute path
 bin=`dirname "$this"`
 script=`basename "$this"`
-bin=`cd "$bin">/dev/null; pwd`
-this="$bin/$script"
+home=`cd "$bin/..">/dev/null; pwd`
+this="$home/bin/$script"
 
 # the root of the drill installation
 if [ -z "$DRILL_HOME" ]; then
-  export DRILL_HOME=`dirname "$this"`/..
+  DRILL_HOME="$home"
 fi
 
 #check to see if the conf dir or drill home are given as an optional arguments
-while [ $# -gt 1 ]
-do
-  if [ "--config" = "$1" ]
-  then
+while [ $# -gt 1 ]; do
+  if [ "--config" = "$1" ]; then
     shift
     confdir=$1
     shift
@@ -62,35 +61,55 @@ do
     break
   fi
 done
- 
+
 # Allow alternate drill conf dir location.
-export DRILL_CONF_DIR="${DRILL_CONF_DIR:-/etc/drill/conf}"
+DRILL_CONF_DIR="${DRILL_CONF_DIR:-/etc/drill/conf}"
 
-if [ ! -d $DRILL_CONF_DIR ]
-then
-  export DRILL_CONF_DIR=$DRILL_HOME/conf
+if [ ! -d $DRILL_CONF_DIR ]; then
+  DRILL_CONF_DIR=$DRILL_HOME/conf
 fi
 
+# Source drill-env.sh for any user configured values
 . "${DRILL_CONF_DIR}/drill-env.sh"
 
-if [ "${HADOOP_HOME}x" != "x" ]
-then
+# get log directory
+if [ "$DRILL_LOG_DIR" = "" ]; then
+  DRILL_LOG_DIR=/var/log/drill
+fi
+
+# If HADOOP_HOME is specified, add all Hadoop jars except those
+# specifically excluded in $DRILL_HOME/bin/hadoop-excludes.txt
+if [ "${HADOOP_HOME}x" != "x" ] ; then
   HADOOP_CLASSPATH=""
-  for jar in `ls $HADOOP_HOME/lib/*jar`
-  do
+  for jar in `ls $HADOOP_HOME/lib/*jar` ; do
     echo $jar | grep -v -f $DRILL_HOME/bin/hadoop-excludes.txt >/dev/null
-    if [ "$?" -eq "0" ]
-    then
+    if [ "$?" -eq "0" ] ; then
       HADOOP_CLASSPATH=$jar:$HADOOP_CLASSPATH
     fi
   done
-  export HADOOP_CLASSPATH=$HADOOP_HOME/conf:$HADOOP_CLASSPATH
+  HADOOP_CLASSPATH=$HADOOP_HOME/conf:$HADOOP_CLASSPATH
+fi
+
+# Setup Drill classpath entries
+CP=$DRILL_HOME/jars/*:$DRILL_CLASSPATH
+CP=$DRILL_HOME/lib/*:$CP
+CP=$DRILL_HOME/contrib/*:$CP
+if [ "${HADOOP_CLASSPATH}x" != "x" ]; then
+  CP=$HADOOP_CLASSPATH:$CP
 fi
+CP=$DRILL_CONF_DIR:$CP
 
 # Newer versions of glibc use an arena memory allocator that causes virtual
 # memory usage to explode. Tune the variable down to prevent vmem explosion.
 export MALLOC_ARENA_MAX=${MALLOC_ARENA_MAX:-4}
 
+# Test for cygwin
+is_cygwin=false
+case "`uname`" in
+CYGWIN*) is_cygwin=true;;
+esac
+
+# Test for or find JAVA_HOME
 if [ -z "$JAVA_HOME" ]; then
   if [ -e `which java` ]; then
     SOURCE=`which java`
@@ -107,9 +126,41 @@ if [ -z "$JAVA_HOME" ]; then
 +======================================================================+
 |      Error: JAVA_HOME is not set and Java could not be found         |
 +----------------------------------------------------------------------+
-| Drill requires Java 1.7 or later.                                    |
+| Apache Drill requires Java 1.7 or later.                             |
 +======================================================================+
 EOF
     exit 1
   fi
 fi
+# Now, verify that 'java' binary exists and is suitable for Drill.
+if $is_cygwin; then
+  JAVA_BIN="java.exe"
+else
+  JAVA_BIN="java"
+fi
+JAVA=`find -L "$JAVA_HOME" -name $JAVA_BIN | head -n 1`
+if [ ! -e "$JAVA" ]; then
+  echo "Java not found at JAVA_HOME=$JAVA_HOME."
+  exit 1
+fi
+# Ensure that Java version is at least 1.7
+"$JAVA" -version 2>&1 | grep "version" | egrep -e "1.4|1.5|1.6" > /dev/null
+if [ $? -eq 0 ]; then
+  echo "Java 1.7 or later is required to run Apache Drill."
+  exit 1
+fi
+
+# Adjust paths for CYGWIN
+if $is_cygwin; then
+  DRILL_HOME=`cygpath -w "$DRILL_HOME"`
+  DRILL_CONF_DIR=`cygpath -w "$DRILL_CONF_DIR"`
+  DRILL_LOG_DIR=`cygpath -w "$DRILL_LOG_DIR"`
+  CP=`cygpath -w -p "$CP"`
+fi
+
+# Variables exported form this script
+export is_cygwin
+export DRILL_HOME
+export DRILL_CONF_DIR
+export DRILL_LOG_DIR
+export CP

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/822cbb06/distribution/src/resources/runbit
----------------------------------------------------------------------
diff --git a/distribution/src/resources/runbit 
b/distribution/src/resources/runbit
index 85daf87..a52c9e6 100755
--- a/distribution/src/resources/runbit
+++ b/distribution/src/resources/runbit
@@ -1,5 +1,5 @@
 #!/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.
@@ -15,30 +15,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+bin=`dirname "${BASH_SOURCE-$0}"`
+bin=`cd "$bin">/dev/null; pwd`
 
-if [ -z $JAVA_HOME ]
-then
-  JAVA=`which java`
-else
-  JAVA=`find -L $JAVA_HOME -name java | head -n 1`
-fi
-
-if [ -e $JAVA ]; then
-  echo ""
-else
-  echo "Java not found."
-  exit 1
-fi
-
-$JAVA -version 2>&1 | grep "version" | egrep -e "1.7" > /dev/null
-if [ $? -ne 0 ]; then
-  echo "Java 1.7 is required to run Apache Drill."
-  exit 1
-fi
-
-CP=$DRILL_HOME/jars/*:$CP
-CP=$DRILL_HOME/lib/*:$CP
-CP=$CP:$DRILL_CONF_DIR
-CP=$HADOOP_CLASSPATH:$CP
+. "$bin"/drill-config.sh
 
 exec $JAVA $DRILL_JAVA_OPTS -cp $CP org.apache.drill.exec.server.Drillbit

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/822cbb06/distribution/src/resources/sqlline
----------------------------------------------------------------------
diff --git a/distribution/src/resources/sqlline 
b/distribution/src/resources/sqlline
index c526f03..ff83ab1 100755
--- a/distribution/src/resources/sqlline
+++ b/distribution/src/resources/sqlline
@@ -1,5 +1,5 @@
 #!/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.
@@ -16,8 +16,7 @@
 # limitations under the License.
 
 ARGS=();
-while [ $# -gt 0 ]
-do
+while [ $# -gt 0 ] ; do
   case "$1" in
   -q) shift;
       QUERY=$1;;
@@ -35,47 +34,12 @@ bin=`cd "$bin">/dev/null; pwd`
 
 . "$bin"/drill-config.sh
 
-if [ -z $JAVA_HOME ]
-then
-  JAVA=`which java`
-else
-  JAVA=`find -L $JAVA_HOME -name java | head -n 1`
-fi
-
-if [ -e $JAVA ]; then
-  echo ""
-else
-  echo "Java not found."
-  exit 1
-fi
-
-$JAVA -version 2>&1 | grep "version" | egrep -e "1.7" > /dev/null
-if [ $? -ne 0 ]; then
-  echo "Java 1.7 is required to run Apache Drill."
-  exit 1
-fi
-
-# get log directory
-if [ "$DRILL_LOG_DIR" = "" ]; then
-  export DRILL_LOG_DIR=/var/log/drill
-fi
-
-
-CP=$DRILL_HOME/jars/*:$CP
-CP=$DRILL_HOME/lib/*:$CP
-CP=$DRILL_HOME/contrib/*:$CP
-CP=$HADOOP_CLASSPATH:$CP
-
-CP=$DRILL_CONF_DIR:$CP
-
 DRILL_SHELL_JAVA_OPTS="$DRILL_SHELL_JAVA_OPTS 
-Dlog.path=$DRILL_LOG_DIR/sqlline.log"
 
-if [ -n "$QUERY" ]
-then
-  echo $QUERY | exec $JAVA $DRILL_SHELL_JAVA_OPTS $DRILL_JAVA_OPTS -cp $CP 
sqlline.SqlLine -d org.apache.drill.jdbc.Driver "${ARGS[@]}"
-elif [ -n "$FILE" ]
-then
-  exec $JAVA $DRILL_SHELL_JAVA_OPTS $DRILL_JAVA_OPTS -cp $CP sqlline.SqlLine 
"${ARGS[@]}" --run=$FILE
+if [ -n "$QUERY" ] ; then
+  echo $QUERY | exec "$JAVA" $DRILL_SHELL_JAVA_OPTS $DRILL_JAVA_OPTS -cp $CP 
sqlline.SqlLine -d org.apache.drill.jdbc.Driver "${ARGS[@]}"
+elif [ -n "$FILE" ] ; then
+  exec "$JAVA" $DRILL_SHELL_JAVA_OPTS $DRILL_JAVA_OPTS -cp $CP sqlline.SqlLine 
"${ARGS[@]}" --run=$FILE
 else
-  exec $JAVA $DRILL_SHELL_JAVA_OPTS $DRILL_JAVA_OPTS -cp $CP sqlline.SqlLine 
"${ARGS[@]}"
+  exec "$JAVA" $DRILL_SHELL_JAVA_OPTS $DRILL_JAVA_OPTS -cp $CP sqlline.SqlLine 
"${ARGS[@]}"
 fi

http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/822cbb06/distribution/src/resources/submit_plan
----------------------------------------------------------------------
diff --git a/distribution/src/resources/submit_plan 
b/distribution/src/resources/submit_plan
index 3c9184a..36666cc 100755
--- a/distribution/src/resources/submit_plan
+++ b/distribution/src/resources/submit_plan
@@ -1,5 +1,5 @@
 #!/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.
@@ -20,37 +20,6 @@ bin=`cd "$bin">/dev/null; pwd`
 
 . "$bin"/drill-config.sh
 
-if [ -z $JAVA_HOME ]
-then
-  JAVA=`which java`
-else
-  JAVA=`find -L $JAVA_HOME -name java | head -n 1`
-fi
-
-if [ -e $JAVA ]; then
-  echo ""
-else
-  echo "Java not found."
-  exit 1
-fi
-
-$JAVA -version 2>&1 | grep "version" | egrep -e "1.7" > /dev/null
-if [ $? -ne 0 ]; then
-  echo "Java 1.7 is required to run Apache Drill."
-  exit 1
-fi
-
-# get log directory
-if [ "$DRILL_LOG_DIR" = "" ]; then
-  export DRILL_LOG_DIR=/var/log/drill
-fi
-
-CP=$DRILL_HOME/jars/*:$CP
-CP=$DRILL_HOME/lib/*:$CP
-
-CP=$DRILL_CONF_DIR:$CP
-CP=$HADOOP_CLASSPATH:$CP
-
 DRILL_SHELL_JAVA_OPTS="$DRILL_SHELL_JAVA_OPTS 
-Dlog.path=$DRILL_LOG_DIR/submitter.log"
 
 exec $JAVA $DRILL_SHELL_JAVA_OPTS $DRILL_JAVA_OPTS -cp $CP 
org.apache.drill.exec.client.QuerySubmitter $@

Reply via email to