/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. # load system-wide scalate configuration
  19. if [ -f "/etc/scalate.conf" ] ; then
  20. . /etc/scalate.conf
  21. fi
  22. # provide default values for people who don't use RPMs
  23. if [ -z "$usejikes" ] ; then
  24. usejikes=false;
  25. fi
  26. # load user scalate configuration
  27. if [ -f "$HOME/.scalaterc" ] ; then
  28. . "$HOME/.scalaterc"
  29. fi
  30. # OS specific support. $var _must_ be set to either true or false.
  31. cygwin=false;
  32. darwin=false;
  33. case "`uname`" in
  34. CYGWIN*) cygwin=true ;;
  35. Darwin*) darwin=true
  36. if [ -z "$JAVA_HOME" ] ; then
  37. JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
  38. fi
  39. ;;
  40. esac
  41. if [ -z "$SCALATE_HOME" ] ; then
  42. # try to find SCALATE
  43. if [ -d /opt/scalate ] ; then
  44. SCALATE_HOME=/opt/scalate
  45. fi
  46. if [ -d "${HOME}/opt/scalate" ] ; then
  47. SCALATE_HOME="${HOME}/opt/scalate"
  48. fi
  49. ## resolve links - $0 may be a link to scalate's home
  50. PRG="$0"
  51. progname=`basename "$0"`
  52. saveddir=`pwd`
  53. # need this for relative symlinks
  54. dirname_prg=`dirname "$PRG"`
  55. cd "$dirname_prg"
  56. while [ -h "$PRG" ] ; do
  57. ls=`ls -ld "$PRG"`
  58. link=`expr "$ls" : '.*-> \(.*\)$'`
  59. if expr "$link" : '.*/.*' > /dev/null; then
  60. PRG="$link"
  61. else
  62. PRG=`dirname "$PRG"`"/$link"
  63. fi
  64. done
  65. SCALATE_HOME=`dirname "$PRG"`
  66. cd "$saveddir"
  67. # make it fully qualified
  68. SCALATE_HOME=`cd "$SCALATE_HOME/.." && pwd`
  69. fi
  70. # For Cygwin, ensure paths are in UNIX format before anything is touched
  71. if $cygwin ; then
  72. [ -n "$SCALATE_HOME" ] &&
  73. SCALATE_HOME=`cygpath --unix "$SCALATE_HOME"`
  74. [ -n "$JAVA_HOME" ] &&
  75. JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  76. [ -n "$CLASSPATH" ] &&
  77. CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
  78. fi
  79. if [ -z "$JAVACMD" ] ; then
  80. if [ -n "$JAVA_HOME" ] ; then
  81. if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
  82. # IBM's JDK on AIX uses strange locations for the executables
  83. JAVACMD="$JAVA_HOME/jre/sh/java"
  84. else
  85. JAVACMD="$JAVA_HOME/bin/java"
  86. fi
  87. else
  88. JAVACMD=`which java 2> /dev/null `
  89. if [ -z "$JAVACMD" ] ; then
  90. JAVACMD=java
  91. fi
  92. fi
  93. fi
  94. if [ ! -x "$JAVACMD" ] ; then
  95. echo "Error: JAVA_HOME is not defined correctly."
  96. echo " We cannot execute $JAVACMD"
  97. exit 1
  98. fi
  99. if [ -z "$SCALATE_BASE" ] ; then
  100. SCALATE_BASE="$SCALATE_HOME"
  101. fi
  102. CLASSPATH="${SCALATE_HOME}/lib/*:${SCALATE_HOME}/lib/tool/*:${SCALATE_HOME}/lib/optional/*"
  103. # For Cygwin, switch paths to Windows format before running java
  104. if $cygwin; then
  105. SCALATE_HOME=`cygpath --windows "$SCALATE_HOME"`
  106. SCALATE_BASE=`cygpath --windows "$SCALATE_BASE"`
  107. SCALATE_CLASSPATH=`cygpath --path --windows "$SCALATE_CLASSPATH"`
  108. JAVA_HOME=`cygpath --windows "$JAVA_HOME"`
  109. CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  110. CYGHOME=`cygpath --windows "$HOME"`
  111. fi
  112. if [ -z "$SCALATE_OPTS" ] ; then
  113. SCALATE_OPTS="-Xmx512M"
  114. fi
  115. if [ -z "$SUNJMX" ] ; then
  116. #SUNJMX="-Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
  117. SUNJMX="-Dcom.sun.management.jmxremote"
  118. fi
  119. SCALATE_OPTS="$SCALATE_OPTS $SUNJMX"
  120. # Optionally enable YourKit debugging
  121. if [ "x$YOURKIT_DEBUG" != "x" ]; then
  122. SCALATE_DEBUG_OPTS="-agentlib:yjpagent"
  123. fi
  124. # Optionally enable remote debugging
  125. if [ "x$SCALATE_DEBUG" != "x" ]; then
  126. SCALATE_DEBUG_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"
  127. fi
  128. SCALATE_CLASS="org.fusesource.scalate.tool.ScalateMain"
  129. if [ -n "$CYGHOME" ]; then
  130. 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 $@
  131. else
  132. exec "$JAVACMD" $SCALATE_DEBUG_OPTS $SCALATE_OPTS -classpath "${CLASSPATH}" -Dscalate.classpath="${SCALATE_CLASSPATH}" -Dscalate.home="${SCALATE_HOME}" -Dscalate.base="${SCALATE_BASE}" $SCALATE_CLASS $@
  133. fi