3 # Ensure this file is executable via `chmod a+x lein`, then place it
4 # somewhere on your $PATH, like ~/bin. The rest of Leiningen will be
5 # installed upon first run into the ~/.lein/self-installs directory.
7 export LEIN_VERSION
="2.7.1"
10 *SNAPSHOT
) SNAPSHOT
="YES" ;;
14 if [[ "$OSTYPE" == "cygwin" ]] ||
[[ "$OSTYPE" == "msys" ]]; then
20 if [[ "$OSTYPE" == "cygwin" ]]; then
26 function command_not_found
{
27 >&2 echo "Leiningen coundn't find $1 in your \$PATH ($PATH), which is required."
31 function make_native_path
{
32 # ensure we have native paths
33 if $cygwin && [[ "$1" == /* ]]; then
34 echo -n "$(cygpath -wp "$1")"
35 elif [[ "$OSTYPE" == "msys" && "$1" == /?
/* ]]; then
36 echo -n "$(sh -c "(cd $1 2</dev
/null
&& pwd -W) ||
echo $1 |
sed 's/^\\/\([a-z]\)/\\1:/g'")"
42 # usage : add_path PATH_VAR [PATH]...
47 # http://bashify.com/?Useful_Techniques:Indirect_Variables:Indirect_Assignment
48 if [[ -z ${!path_var} ]]; then
49 export ${path_var}="$(make_native_path "$1")"
51 export ${path_var}="${!path_var}${delimiter}$
(make_native_path
"$1")"
57 function download_failed_message {
58 echo "Failed to download
$1 (exit code
$2)"
59 echo "It
's possible your HTTP client's certificate store does not have the
"
60 echo "correct certificate authority needed. This is often caused by an
"
61 echo "out-of-date version of libssl. It
's also possible that you're behind a
"
62 echo "firewall and haven
't set HTTP_PROXY and HTTPS_PROXY."
65 function self_install {
66 if [ -r "$LEIN_JAR" ]; then
67 echo "The self-install jar already exists at $LEIN_JAR."
68 echo "If you wish to re-download, delete it and rerun \"$0 self-install\"."
71 echo "Downloading Leiningen to $LEIN_JAR now..."
72 mkdir -p "$(dirname "$LEIN_JAR")"
73 LEIN_URL="https://github.com/technomancy/leiningen/releases/download/$LEIN_VERSION/leiningen-$LEIN_VERSION-standalone.zip"
74 $HTTP_CLIENT "$LEIN_JAR.pending" "$LEIN_URL"
76 if [ $exit_code == 0 ]; then
78 mv -f "$LEIN_JAR.pending" "$LEIN_JAR"
80 rm "$LEIN_JAR.pending" 2> /dev/null
81 download_failed_message "$LEIN_URL" "$exit_code"
88 # Thank you for the complexity, Solaris
89 if [ `uname` = "SunOS" -a -x /usr/xpg4/bin/id ]; then
90 user_id=$(/usr/xpg4/bin/id -u 2>/dev/null || echo 0)
92 user_id=$(id -u 2>/dev/null || echo 0)
94 [ $user_id -eq 0 -a "$LEIN_ROOT" = "" ] && return 0
99 echo "WARNING: You're currently running as root
; probably by accident.
"
100 echo "Press control-C to abort or Enter to
continue as root.
"
101 echo "Set LEIN_ROOT to disable this warning.
"
107 while [ ! -r "$PWD/project.clj
" ] && [ "$PWD" != "/" ] && [ $NOT_FOUND -ne 0 ]
110 if [ "$
(dirname "$PWD")" = "/" ]; then
116 export LEIN_HOME="${LEIN_HOME:-"$HOME/.lein"}"
118 for f in "/etc
/leinrc
" "$LEIN_HOME/leinrc
" ".leinrc
"; do
125 export LEIN_HOME=$(cygpath -w "$LEIN_HOME")
128 LEIN_JAR="$LEIN_HOME/self-installs
/leiningen-
$LEIN_VERSION-standalone.jar
"
130 # normalize $0 on certain BSDs
131 if [ "$
(dirname "$0")" = ".
" ]; then
132 SCRIPT="$
(which "$(basename "$0")")"
133 if [ -z "$SCRIPT" ]; then
140 # resolve symlinks to the script itself portably
141 while [ -h "$SCRIPT" ] ; do
142 ls=$(ls -ld "$SCRIPT")
143 link=$(expr "$ls" : '.*-> \(.*\)$')
144 if expr "$link" : '/.*' > /dev/null; then
147 SCRIPT="$
(dirname "$SCRIPT"$
)/$link"
151 BIN_DIR="$
(dirname "$SCRIPT")"
153 export LEIN_JVM_OPTS="${LEIN_JVM_OPTS-"-XX:+TieredCompilation -XX:TieredStopAtLevel=1"}"
155 # This needs to be defined before we call HTTP_CLIENT below
156 if [ "$HTTP_CLIENT" = "" ]; then
157 if type -p curl >/dev/null 2>&1; then
158 if [ "$https_proxy" != "" ]; then
159 CURL_PROXY="-x $https_proxy"
161 HTTP_CLIENT="curl
$CURL_PROXY -f -L -o"
163 HTTP_CLIENT="wget
-O"
168 # When :eval-in :classloader we need more memory
169 grep -E -q '^\s*:eval-in\s+:classloader\s*$' project.clj 2> /dev/null && \
170 export LEIN_JVM_OPTS="$LEIN_JVM_OPTS -Xms64m -Xmx512m"
172 if [ -r "$BIN_DIR/..
/src
/leiningen
/version.clj
" ]; then
173 # Running from source checkout
174 LEIN_DIR="$
(dirname "$BIN_DIR")"
176 # Need to use lein release to bootstrap the leiningen-core library (for aether)
177 if [ ! -r "$LEIN_DIR/leiningen-core
/.lein-bootstrap
" ]; then
178 echo "Leiningen is missing its dependencies.
"
179 echo "Please run
\"lein bootstrap
\" in the leiningen-core
/ directory
"
180 echo "with a stable release of Leiningen. See CONTRIBUTING.md
for details.
"
184 # If project.clj for lein or leiningen-core changes, we must recalculate
185 LAST_PROJECT_CHECKSUM=$(cat "$LEIN_DIR/.lein-project-checksum
" 2> /dev/null)
186 PROJECT_CHECKSUM=$(sum "$LEIN_DIR/project.clj
" "$LEIN_DIR/leiningen-core
/project.clj
")
187 if [ "$PROJECT_CHECKSUM" != "$LAST_PROJECT_CHECKSUM" ]; then
188 if [ -r "$LEIN_DIR/.lein-classpath
" ]; then
189 rm "$LEIN_DIR/.lein-classpath
"
193 # Use bin/lein to calculate its own classpath.
194 if [ ! -r "$LEIN_DIR/.lein-classpath
" ] && [ "$1" != "classpath
" ]; then
195 echo "Recalculating Leiningen
's classpath."
199 LEIN_NO_USER_PROFILES=1 $0 classpath .lein-classpath
200 sum "$LEIN_DIR/project.clj" "$LEIN_DIR/leiningen-core/project.clj" > \
201 .lein-project-checksum
205 mkdir -p "$LEIN_DIR/target/classes"
206 export LEIN_JVM_OPTS="$LEIN_JVM_OPTS -Dclojure.compile.path=$LEIN_DIR/target/classes"
207 add_path CLASSPATH "$LEIN_DIR/leiningen-core/src/" "$LEIN_DIR/leiningen-core/resources/" \
208 "$LEIN_DIR/test:$LEIN_DIR/target/classes" "$LEIN_DIR/src" ":$LEIN_DIR/resources"
210 if [ -r "$LEIN_DIR/.lein-classpath" ]; then
211 add_path CLASSPATH "$(cat "$LEIN_DIR/.lein-classpath" 2> /dev/null)"
213 add_path CLASSPATH "$(cat "$LEIN_DIR/leiningen-core/.lein-bootstrap" 2> /dev/null)"
215 else # Not running from a checkout
216 add_path CLASSPATH "$LEIN_JAR"
218 BOOTCLASSPATH="-Xbootclasspath/a:$LEIN_JAR"
220 if [ ! -r "$LEIN_JAR" -a "$1" != "self-install" ]; then
225 if [ ! -x "$JAVA_CMD" ] && ! type -f java >/dev/null
227 >&2 echo "Leiningen coundn't
find 'java' executable
, which is required.
"
228 >&2 echo "Please either
set JAVA_CMD or put java
(>=1.6) in your \
$PATH ($PATH).
"
232 export LEIN_JAVA_CMD="${LEIN_JAVA_CMD:-${JAVA_CMD:-java}}"
234 if [[ -z "${DRIP_INIT+x}" && "$
(basename "$LEIN_JAVA_CMD")" == *drip* ]]; then
235 export DRIP_INIT="$
(printf -- '-e\n(require (quote leiningen.repl))')"
236 export DRIP_INIT_CLASS="clojure.main
"
239 # Support $JAVA_OPTS for backwards-compatibility.
240 export JVM_OPTS="${JVM_OPTS:-"$JAVA_OPTS"}"
242 # Handle jline issue with cygwin not propagating OSTYPE through java subprocesses: https://github.com/jline/jline2/issues/62
246 rxvt* | xterm* | vt*) cygterm=true ;;
251 LEIN_JVM_OPTS="$LEIN_JVM_OPTS -Djline.terminal
=jline.UnixTerminal
"
252 stty -icanon min 1 -echo > /dev/null 2>&1
255 # TODO: investigate http://skife.org/java/unix/2011/06/20/really_executable_jars.html
256 # If you're packaging this for a package manager (.deb, homebrew, etc)
257 # you need to remove the self-install and upgrade functionality or see lein-pkg.
258 if [ "$1" = "self-install
" ]; then
259 if [ -r "$BIN_DIR/..
/src
/leiningen
/version.clj
" ]; then
260 echo "Running self-install from a checkout is not supported.
"
261 echo "See CONTRIBUTING.md
for SNAPSHOT-specific build instructions.
"
264 echo "Manual self-install is deprecated
; it will run automatically when necessary.
"
266 elif [ "$1" = "upgrade
" ] || [ "$1" = "downgrade
" ]; then
267 if [ "$LEIN_DIR" != "" ]; then
268 echo "The upgrade task is not meant to be run from a checkout.
"
271 if [ $SNAPSHOT = "YES
" ]; then
272 echo "The upgrade task is only meant
for stable releases.
"
273 echo "See the
\"Bootstrapping
\" section of CONTRIBUTING.md.
"
276 if [ ! -w "$SCRIPT" ]; then
277 echo "You
do not have permission to upgrade the installation
in $SCRIPT"
280 TARGET_VERSION="${2:-stable}"
281 echo "The
script at $SCRIPT will be upgraded to the latest
$TARGET_VERSION version.
"
282 echo -n "Do you want to
continue [Y
/n
]?
"
288 TARGET="/tmp
/lein-$$
-upgrade"
290 TARGET=$(cygpath -w "$TARGET")
292 LEIN_SCRIPT_URL="https
://github.com
/technomancy
/leiningen
/raw
/$TARGET_VERSION/bin
/lein
"
293 $HTTP_CLIENT "$TARGET" "$LEIN_SCRIPT_URL"
295 cmp -s "$TARGET" "$SCRIPT"
297 echo "Leiningen is already up-to-date.
"
299 mv "$TARGET" "$SCRIPT" && chmod +x "$SCRIPT"
300 exec "$SCRIPT" version
302 download_failed_message "$LEIN_SCRIPT_URL"
311 # When running on Cygwin, use Windows-style paths for java
312 ORIGINAL_PWD=$(cygpath -w "$ORIGINAL_PWD")
315 # apply context specific CLASSPATH entries
316 if [ -f .lein-classpath ]; then
317 add_path CLASSPATH "$
(cat .lein-classpath
)"
320 if [ -n "$DEBUG" ]; then
321 echo "Leiningen
's classpath: $CLASSPATH"
324 if [ -r .lein-fast-trampoline ]; then
325 export LEIN_FAST_TRAMPOLINE='y
'
328 if [ "$LEIN_FAST_TRAMPOLINE" != "" ] && [ -r project.clj ]; then
329 INPUTS="$* $(cat project.clj) $LEIN_VERSION $(test -f "$LEIN_HOME/profiles.clj" && cat "$LEIN_HOME/profiles.clj")"
331 if command -v shasum >/dev/null 2>&1; then
333 elif command -v sha1sum >/dev/null 2>&1; then
336 command_not_found "sha1sum or shasum"
339 export INPUT_CHECKSUM=$(echo "$INPUTS" | $SUM | cut -f 1 -d " ")
340 # Just don't change
:target-path
in project.clj
, mkay?
341 TRAMPOLINE_FILE
="target/trampolines/$INPUT_CHECKSUM"
343 if hash mktemp
2>/dev
/null
; then
344 # Check if mktemp is available before using it
345 TRAMPOLINE_FILE
="$(mktemp /tmp/lein-trampoline-XXXXXXXXXXXXX)"
347 TRAMPOLINE_FILE
="/tmp/lein-trampoline-$$"
349 trap "rm -f $TRAMPOLINE_FILE" EXIT
353 TRAMPOLINE_FILE
=$
(cygpath
-w "$TRAMPOLINE_FILE")
356 if [ "$INPUT_CHECKSUM" != "" ] && [ -r "$TRAMPOLINE_FILE" ]; then
357 if [ -n "$DEBUG" ]; then
358 echo "Fast trampoline with $TRAMPOLINE_FILE."
360 exec sh
-c "exec $(cat "$TRAMPOLINE_FILE")"
362 export TRAMPOLINE_FILE
364 "${BOOTCLASSPATH[@]}" \
365 -Dfile.encoding
=UTF-8 \
366 -Dmaven.wagon.http.ssl.easy
=false \
367 -Dmaven.wagon.rto
=10000 \
369 -Dleiningen.original.
pwd="$ORIGINAL_PWD" \
370 -Dleiningen.
script="$SCRIPT" \
371 -classpath "$CLASSPATH" \
372 clojure.main
-m leiningen.core.main
"$@"
377 stty icanon
echo > /dev
/null
2>&1
380 ## TODO: [ -r "$TRAMPOLINE_FILE" ] may be redundant? A trampoline file
381 ## is always generated these days.
382 if [ -r "$TRAMPOLINE_FILE" ] && [ "$LEIN_TRAMPOLINE_WARMUP" = "" ]; then
383 TRAMPOLINE
="$(cat "$TRAMPOLINE_FILE")"
384 if [ "$INPUT_CHECKSUM" = "" ]; then
385 rm "$TRAMPOLINE_FILE"
387 if [ "$TRAMPOLINE" = "" ]; then
390 exec sh
-c "exec $TRAMPOLINE"