leiningen/bin/lein

190 lines
6.2 KiB
Text
Raw Normal View History

#!/bin/sh
2009-11-02 06:21:50 +00:00
2011-04-13 02:08:00 +00:00
LEIN_VERSION="1.5.1"
export LEIN_VERSION
case $LEIN_VERSION in
*SNAPSHOT) SNAPSHOT="YES" ;;
*) SNAPSHOT="NO" ;;
esac
# Make sure classpath is in unix format for manipulating, then put
# it back to windows format when we use it
if [ "$OSTYPE" = "cygwin" ] && [ "$CLASSPATH" != "" ]; then
CLASSPATH=`cygpath -up $CLASSPATH`
fi
if [ `whoami` = "root" ] && [ "$LEIN_ROOT" = "" ]; then
2010-07-30 20:28:45 +00:00
echo "WARNING: You're currently running as root; probably by accident."
echo "Press control-C to abort or Enter to continue as root."
echo "Set LEIN_ROOT to disable this warning."
read _
2010-07-30 20:28:45 +00:00
fi
ORIGINAL_PWD="$PWD"
while [ ! -r "$PWD/project.clj" ] && [ "$PWD" != "/" ] && [ ! $NOT_FOUND ]
do
cd ..
if [ "$(dirname "$PWD")" = "/" ]; then
NOT_FOUND=0
cd "$ORIGINAL_PWD"
fi
done
2010-08-08 20:33:04 +00:00
if [ "$LEIN_HOME" = "" ]; then
LEIN_HOME="$HOME/.lein"
fi
LEIN_PLUGINS="$(ls -1 lib/dev/*jar 2> /dev/null | tr \\n \:)"
LEIN_USER_PLUGINS="$(ls -1 $LEIN_HOME/plugins/*jar 2> /dev/null | tr \\n \:)"
CLASSPATH=$CLASSPATH:$LEIN_USER_PLUGINS:$LEIN_PLUGINS:test/:src/
LEIN_JAR="$HOME/.lein/self-installs/leiningen-$LEIN_VERSION-standalone.jar"
CLOJURE_JAR="$HOME/.m2/repository/org/clojure/clojure/1.2.0/clojure-1.2.0.jar"
NULL_DEVICE=/dev/null
# normalize $0 on certain BSDs
if [ "$(dirname "$0")" = "." ]; then
SCRIPT="$(which $(basename "$0"))"
else
SCRIPT="$0"
fi
# resolve symlinks to the script itself portably
while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT="$(dirname "$SCRIPT"$)/$link"
fi
done
BIN_DIR="$(dirname "$SCRIPT")"
if [ -r "$BIN_DIR/../src/leiningen/core.clj" ]; then
# Running from source checkout
LEIN_DIR="$(dirname "$BIN_DIR")"
LEIN_LIBS="$(find -H "$LEIN_DIR/lib" -mindepth 1 -maxdepth 1 -print0 2> /dev/null | tr \\0 \:)"
CLASSPATH="$CLASSPATH:$LEIN_LIBS:$LEIN_DIR/src:$LEIN_DIR/classes:$LEIN_DIR/resources:$LEIN_JAR"
if [ "$LEIN_LIBS" = "" -a "$1" != "self-install" -a ! -r "$LEIN_JAR" ]; then
2010-09-03 03:16:54 +00:00
echo "Leiningen is missing its dependencies. Please see \"Building\" in the README."
exit 1
fi
else
# Not running from a checkout
CLASSPATH="$CLASSPATH:$LEIN_JAR"
if [ ! -r "$LEIN_JAR" -a "$1" != "self-install" ]; then
2010-09-03 03:16:54 +00:00
"$0" self-install
2009-11-10 06:22:09 +00:00
fi
2009-11-02 06:21:50 +00:00
fi
HTTP_CLIENT="wget --no-check-certificate -O"
2010-02-12 08:41:12 +00:00
if type -p curl >/dev/null 2>&1; then
if [ "$https_proxy" != "" ]; then
CURL_PROXY="-x $https_proxy"
fi
HTTP_CLIENT="curl $CURL_PROXY --insecure -f -L -o"
2010-02-12 08:41:12 +00:00
fi
JAVA_CMD=${JAVA_CMD:-"java"}
# Support $JAVA_OPTS for backwards-compatibility.
JVM_OPTS=${JVM_OPTS:-$JAVA_OPTS}
# If you're packaging this for a package manager (.deb, homebrew, etc)
# you need to remove the self-install and upgrade functionality.
if [ "$1" = "self-install" ]; then
2009-11-10 06:22:09 +00:00
echo "Downloading Leiningen now..."
LEIN_DIR=`dirname "$LEIN_JAR"`
mkdir -p "$LEIN_DIR"
2010-12-03 02:16:16 +00:00
LEIN_URL="https://github.com/downloads/technomancy/leiningen/leiningen-$LEIN_VERSION-standalone.jar"
$HTTP_CLIENT "$LEIN_JAR" "$LEIN_URL"
if [ $? != 0 ]; then
echo "Failed to download $LEIN_URL"
if [ $SNAPSHOT = "YES" ]; then
echo "If you have Maven installed, you can do"
echo "mvn dependency:copy-dependencies; mv target/dependency lib"
echo "See README.md for further SNAPSHOT build instructions."
fi
rm $LEIN_JAR 2> /dev/null
exit 1
fi
2010-02-12 08:41:12 +00:00
elif [ "$1" = "upgrade" ]; then
# TODO: ensure we're not running from a checkout
if [ $SNAPSHOT = "YES" ]; then
2010-02-12 08:41:12 +00:00
echo "The upgrade task is only meant for stable releases."
echo "See the \"Hacking\" section of the README."
exit 1
2009-11-10 06:22:09 +00:00
fi
if [ ! -w "$SCRIPT" ]; then
echo "You do not have permission to upgrade the installation in $SCRIPT"
exit 1
else
echo "The script at $SCRIPT will be upgraded to the latest stable version."
echo -n "Do you want to continue [Y/n]? "
read RESP
case "$RESP" in
y|Y|"")
echo
echo "Upgrading..."
TARGET="/tmp/lein-$$-upgrade"
2010-12-03 02:16:16 +00:00
LEIN_SCRIPT_URL="https://github.com/technomancy/leiningen/raw/stable/bin/lein"
$HTTP_CLIENT "$TARGET" "$LEIN_SCRIPT_URL" \
&& mv "$TARGET" "$SCRIPT" \
&& chmod +x "$SCRIPT" \
&& echo && $SCRIPT self-install && echo && echo "Now running" `$SCRIPT version`
exit $?;;
*)
echo "Aborted."
exit 1;;
esac
fi
else
if [ "$OSTYPE" = "cygwin" ]; then
# When running on Cygwin, use Windows-style paths for java
CLOJURE_JAR=`cygpath -w "$CLOJURE_JAR"`
ORIGINAL_PWD=`cygpath -w "$ORIGINAL_PWD"`
CLASSPATH=`cygpath -wp "$CLASSPATH"`
NULL_DEVICE=NUL
fi
if [ $DEBUG ]; then
echo $CLASSPATH
echo $CLOJURE_JAR
fi
JLINE=""
if ([ "$1" = "repl" ] || [ "$1" = "interactive" ] || [ "$1" = "int" ]) &&
2010-08-20 03:54:50 +00:00
[ -z $INSIDE_EMACS ] && [ "$TERM" != "dumb" ]; then
2010-06-22 02:21:22 +00:00
# Use rlwrap if it's available, otherwise fall back to JLine
RLWRAP=`which rlwrap`
2010-11-26 22:41:11 +00:00
if [ ! -x "$RLWRAP" ] || [ "$RLWRAP" = "" ]; then
2011-02-24 05:17:25 +00:00
if [ ! -r "$LEIN_HOME/.jline-warn" ]; then
echo "Using JLine for console I/O; install rlwrap for optimum experience."
touch "$LEIN_HOME/.jline-warn"
fi
RLWRAP=""
2010-06-22 02:21:22 +00:00
JLINE=jline.ConsoleRunner
if [ "$OSTYPE" = "cygwin" ]; then
2010-11-19 17:49:55 +00:00
JLINE="-Djline.terminal=jline.UnixTerminal jline.ConsoleRunner"
CYGWIN_JLINE=y
fi
else
RLWRAP="$RLWRAP -m -q '\"'"
2010-06-22 02:21:22 +00:00
fi
fi
# The -Xbootclasspath argument is optional here: if the jar
# doesn't exist everything will still work, it will just have a
# slower JVM boot.
test $CYGWIN_JLINE && stty -icanon min 1 -echo
exec $RLWRAP $JAVA_CMD -Xbootclasspath/a:"$CLOJURE_JAR" -client $JVM_OPTS \
-Dleiningen.original.pwd="$ORIGINAL_PWD" \
-cp "$CLASSPATH" $JLINE clojure.main -e "(use 'leiningen.core)(-main)" \
$NULL_DEVICE "$@"
test $CYGWIN_JLINE && stty icanon echo
fi