leiningen/bin/lein

76 lines
2.4 KiB
Text
Raw Normal View History

2009-11-02 06:21:50 +00:00
#!/bin/bash
2009-11-20 01:22:52 +00:00
VERSION="1.0.0-SNAPSHOT"
LEIN_JAR="$HOME/.m2/repository/leiningen/leiningen/$VERSION/leiningen-$VERSION-standalone.jar"
CLOJURE_JAR="$HOME/.m2/repository/org/clojure/clojure/1.1.0-alpha-SNAPSHOT/clojure-1.1.0-alpha-SNAPSHOT.jar"
# 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 2> /dev/null 1 -maxdepth 1 -print0 | tr \\0 \:)"
CLASSPATH="$LEIN_DIR/src:$LEIN_LIBS"
if [ "$LEIN_LIBS" = "" -a "$1" != "self-install" ]; then
echo "Your Leiningen development checkout is missing its dependencies."
echo "Please download a stable version of Leiningen to fetch the deps."
echo "See the \"Hacking\" section of the readme for details."
exit 1
fi
else
# Not running from a checkout
CLASSPATH="$LEIN_JAR"
if [ ! -r "$LEIN_JAR" -a "$1" != "self-install" ]; then
2009-11-12 05:24:48 +00:00
echo "Leiningen is not installed. Please run \"lein self-install\"."
exit 1
2009-11-10 06:22:09 +00:00
fi
2009-11-02 06:21:50 +00:00
fi
2009-11-10 06:22:09 +00:00
if [ $DEBUG ]; then
echo $CLASSPATH
fi
# escape command-line arguments so they can be evaled as strings
ESCAPED_ARGS=""
for ARG in "$@"; do
ESCAPED_ARGS="$ESCAPED_ARGS"' "'$(echo $ARG | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g')'"'
done
if [ "$1" = "repl" ]; then
2009-11-29 05:35:19 +00:00
# TODO: use rlwrap if present
java -cp "$CLASSPATH" clojure.main
elif [ "$1" = "self-install" ]; then
2009-11-10 06:22:09 +00:00
echo "Downloading Leiningen now..."
mkdir -p `dirname "$LEIN_JAR"`
LEIN_URL="http://repo.technomancy.us/leiningen-$VERSION-standalone.jar"
if type -p curl >/dev/null 2>&1; then
exec curl -o "$LEIN_JAR" "$LEIN_URL"
2009-11-10 06:22:09 +00:00
else
exec wget -O "$LEIN_JAR" "$LEIN_URL"
2009-11-10 06:22:09 +00:00
fi
else
# Temporarily disabled while debugging NPE.
# exec java -Xbootclasspath/a:"$CLOJURE_JAR" -client -cp "$CLASSPATH" clojure.main -e "(use 'leiningen.core)(-main $ESCAPED_ARGS)"
exec java -client -cp "$CLASSPATH" clojure.main -e "(use 'leiningen.core)(-main $ESCAPED_ARGS)"
fi