PageRenderTime 40ms CodeModel.GetById 18ms app.highlight 16ms RepoModel.GetById 2ms app.codeStats 0ms

/scalate-distro/src/main/release/bin/scalate

http://github.com/scalate/scalate
Shell | 159 lines | 102 code | 26 blank | 31 comment | 25 complexity | 9433812ed132e0b3315830775a51de32 MD5 | raw file
  1#!/bin/sh
  2# ------------------------------------------------------------------------
  3# Copyright (C) 2009 Progress Software, Inc. All rights reserved.
  4# http://fusesource.com
  5# 
  6# Licensed under the Apache License, Version 2.0 (the "License");
  7# you may not use this file except in compliance with the License.
  8# You may obtain a copy of the License at
  9# 
 10#     http://www.apache.org/licenses/LICENSE-2.0
 11# 
 12# Unless required by applicable law or agreed to in writing, software
 13# distributed under the License is distributed on an "AS IS" BASIS,
 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15# See the License for the specific language governing permissions and
 16# limitations under the License.
 17# ------------------------------------------------------------------------
 18
 19# load system-wide scalate configuration
 20if [ -f "/etc/scalate.conf" ] ; then
 21  . /etc/scalate.conf
 22fi
 23
 24# provide default values for people who don't use RPMs
 25if [ -z "$usejikes" ] ; then
 26  usejikes=false;
 27fi
 28
 29# load user scalate configuration
 30if [ -f "$HOME/.scalaterc" ] ; then
 31  . "$HOME/.scalaterc"
 32fi
 33
 34# OS specific support.  $var _must_ be set to either true or false.
 35cygwin=false;
 36darwin=false;
 37case "`uname`" in
 38  CYGWIN*) cygwin=true ;;
 39  Darwin*) darwin=true
 40           if [ -z "$JAVA_HOME" ] ; then
 41             JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
 42           fi
 43           ;;
 44esac
 45
 46if [ -z "$SCALATE_HOME" ] ; then
 47  # try to find SCALATE
 48  if [ -d /opt/scalate ] ; then
 49    SCALATE_HOME=/opt/scalate
 50  fi
 51
 52  if [ -d "${HOME}/opt/scalate" ] ; then
 53    SCALATE_HOME="${HOME}/opt/scalate"
 54  fi
 55
 56  ## resolve links - $0 may be a link to scalate's home
 57  PRG="$0"
 58  progname=`basename "$0"`
 59  saveddir=`pwd`
 60
 61  # need this for relative symlinks
 62  dirname_prg=`dirname "$PRG"`
 63  cd "$dirname_prg"
 64
 65  while [ -h "$PRG" ] ; do
 66    ls=`ls -ld "$PRG"`
 67    link=`expr "$ls" : '.*-> \(.*\)$'`
 68    if expr "$link" : '.*/.*' > /dev/null; then
 69    PRG="$link"
 70    else
 71    PRG=`dirname "$PRG"`"/$link"
 72    fi
 73  done
 74
 75  SCALATE_HOME=`dirname "$PRG"`
 76
 77  cd "$saveddir"
 78
 79  # make it fully qualified
 80  SCALATE_HOME=`cd "$SCALATE_HOME/.." && pwd`
 81fi
 82
 83# For Cygwin, ensure paths are in UNIX format before anything is touched
 84if $cygwin ; then
 85  [ -n "$SCALATE_HOME" ] &&
 86    SCALATE_HOME=`cygpath --unix "$SCALATE_HOME"`
 87  [ -n "$JAVA_HOME" ] &&
 88    JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
 89  [ -n "$CLASSPATH" ] &&
 90    CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
 91fi
 92
 93if [ -z "$JAVACMD" ] ; then
 94  if [ -n "$JAVA_HOME"  ] ; then
 95    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
 96      # IBM's JDK on AIX uses strange locations for the executables
 97      JAVACMD="$JAVA_HOME/jre/sh/java"
 98    else
 99      JAVACMD="$JAVA_HOME/bin/java"
100    fi
101  else
102    JAVACMD=`which java 2> /dev/null `
103    if [ -z "$JAVACMD" ] ; then
104        JAVACMD=java
105    fi
106  fi
107fi
108
109if [ ! -x "$JAVACMD" ] ; then
110  echo "Error: JAVA_HOME is not defined correctly."
111  echo "  We cannot execute $JAVACMD"
112  exit 1
113fi
114
115if [ -z "$SCALATE_BASE" ] ; then
116  SCALATE_BASE="$SCALATE_HOME"
117fi
118
119CLASSPATH="${SCALATE_HOME}/lib/*:${SCALATE_HOME}/lib/tool/*:${SCALATE_HOME}/lib/optional/*"
120
121# For Cygwin, switch paths to Windows format before running java
122if $cygwin; then
123  SCALATE_HOME=`cygpath --windows "$SCALATE_HOME"`
124  SCALATE_BASE=`cygpath --windows "$SCALATE_BASE"`
125  SCALATE_CLASSPATH=`cygpath --path --windows "$SCALATE_CLASSPATH"`
126  JAVA_HOME=`cygpath --windows "$JAVA_HOME"`
127  CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
128  CYGHOME=`cygpath --windows "$HOME"`
129fi
130
131if [ -z "$SCALATE_OPTS" ] ; then
132  SCALATE_OPTS="-Xmx512M"
133fi
134
135if [ -z "$SUNJMX" ] ; then
136  #SUNJMX="-Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
137  SUNJMX="-Dcom.sun.management.jmxremote"
138fi
139
140SCALATE_OPTS="$SCALATE_OPTS $SUNJMX"
141
142# Optionally enable YourKit debugging
143if [ "x$YOURKIT_DEBUG" != "x" ]; then
144    SCALATE_DEBUG_OPTS="-agentlib:yjpagent"
145fi
146
147# Optionally enable remote debugging
148if [ "x$SCALATE_DEBUG" != "x" ]; then
149    SCALATE_DEBUG_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
150fi
151
152SCALATE_CLASS="org.fusesource.scalate.tool.ScalateMain"
153
154if [ -n "$CYGHOME" ]; then
155    exec "$JAVACMD" $SCALATE_DEBUG_OPTS $SCALATE_OPTS -classpath "${CLASSPATH}" -Dscalate.classpath="${SCALATE_CLASSPATH}" -Dscalate.home="${SCALATE_HOME}" -Dscalate.base="${SCALATE_BASE}" -Dcygwin.user.home="$CYGHOME" $SCALATE_CLASS $@
156else
157    exec "$JAVACMD" $SCALATE_DEBUG_OPTS $SCALATE_OPTS -classpath "${CLASSPATH}" -Dscalate.classpath="${SCALATE_CLASSPATH}" -Dscalate.home="${SCALATE_HOME}" -Dscalate.base="${SCALATE_BASE}" $SCALATE_CLASS $@
158fi
159