#!/usr/bin/env bash # Ensure this file is executable via `chmod a+x fractl`, then place it # somewhere on your $PATH, like ~/bin. The rest of Leiningen will be # installed upon first run into the ~/.fractl/self-installs directory. function msg { echo "$@" 1>&2 } export FRACTL_VERSION="0.5.1" # Must be sha256sum export FRACTL_CHECKSUM='73559e4f39ffbb6a97ec09e2aa86f97b75b02411088957254f146c338f68f4a8' if [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]]; then delimiter=";" else delimiter=":" fi if [[ "$OSTYPE" == "cygwin" ]]; then cygwin=true else cygwin=false fi function command_not_found { msg "Fractl couldn't find $1 in your \$PATH ($PATH), which is required." exit 1 } function make_native_path { # ensure we have native paths if $cygwin && [[ "$1" == /* ]]; then echo -n "$(cygpath -wp "$1")" elif [[ "$OSTYPE" == "msys" && "$1" == /?/* ]]; then echo -n "$(sh -c "(cd $1 2&2 Failed to download $1 (exit code $2) It's possible your HTTP client's certificate store does not have the correct certificate authority needed. This is often caused by an out-of-date version of libssl. It's also possible that you're behind a firewall and haven't set HTTP_PROXY and HTTPS_PROXY. EOS } function checksum_failed_message { cat <<-EOS 1>&2 Failed to properly download $1 The checksum was mismatched. and we could not verify the downloaded file. We expected a sha256 of $2 and actually had $3. We used '$SHASUM_CMD' to verify the downloaded file. EOS } function self_install { if [ -r "$FRACTL_JAR" ]; then cat <<-EOS 1>&2 The self-install jar already exists at $FRACTL_JAR. If you wish to re-download, delete it and rerun "$0 self-install". EOS exit 1 fi msg "Downloading Fractl to $FRACTL_JAR now..." mkdir -p "$(dirname "$FRACTL_JAR")" FRACTL_URL="https://github.com/fractl-io/fractl/releases/download/$FRACTL_VERSION/fractl-$FRACTL_VERSION-standalone.jar" echo "$HTTP_CLIENT $FRACTL_JAR.pending $FRACTL_URL" $HTTP_CLIENT "$FRACTL_JAR.pending" "$FRACTL_URL" local exit_code=$? if [ $exit_code == 0 ]; then printf "$FRACTL_CHECKSUM $FRACTL_JAR.pending\n" > "$FRACTL_JAR.pending.shasum" $SHASUM_CMD -c "$FRACTL_JAR.pending.shasum" if [ $? == 0 ]; then mv -f "$FRACTL_JAR.pending" "$FRACTL_JAR" else got_sum="$($SHASUM_CMD "$FRACTL_JAR.pending" | cut -f 1 -d ' ')" checksum_failed_message "$FRACTL_URL" "$FRACTL_CHECKSUM" "$got_sum" rm "$FRACTL_JAR.pending" 2> /dev/null exit 1 fi else rm "$FRACTL_JAR.pending" 2> /dev/null download_failed_message "$FRACTL_URL" "$exit_code" exit 1 fi } export FRACTL_HOME="${FRACTL_HOME:-"$HOME/.fractl"}" if $cygwin; then export FRACTL_HOME=$(cygpath -w "$FRACTL_HOME") fi FRACTL_JAR="$FRACTL_HOME/self-installs/fractl-$FRACTL_VERSION-standalone.jar" # normalize $0 on certain BSDs if [ "$(dirname "$0")" = "." ]; then SCRIPT="$(which "$(basename "$0")")" if [ -z "$SCRIPT" ]; then SCRIPT="$0" fi 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")" # This needs to be defined before we call HTTP_CLIENT below if [ "$HTTP_CLIENT" = "" ]; then if type -p curl >/dev/null 2>&1; then if [ "$https_proxy" != "" ]; then CURL_PROXY="-x $https_proxy" fi HTTP_CLIENT="curl $CURL_PROXY -f -L -o" else HTTP_CLIENT="wget -O" fi fi # This needs to be defined before we call SHASUM_CMD below if [ "$SHASUM_CMD" = "" ]; then if type -p sha256sum >/dev/null 2>&1; then export SHASUM_CMD="sha256sum" elif type -p shasum >/dev/null 2>&1; then export SHASUM_CMD="shasum --algorithm 256" else command_not_found sha256sum fi fi if [ ! -x "$JAVA_CMD" ] && ! type -f java >/dev/null then msg "Fractl couldn't find 'java' executable, which is required." msg "Please either set JAVA_CMD or put java (>=1.6) in your \$PATH ($PATH)." exit 1 fi export FRACTL_JAVA_CMD="${FRACTL_JAVA_CMD:-${JAVA_CMD:-java}}" # Handle jline issue with cygwin not propagating OSTYPE through java subprocesses: https://github.com/jline/jline2/issues/62 cygterm=false if $cygwin; then case "$TERM" in rxvt* | xterm* | vt*) cygterm=true ;; esac fi export FRACTL_JVM_OPTS="${FRACTL_JVM_OPTS-"-XX:+TieredCompilation -XX:TieredStopAtLevel=1"}" if $cygterm; then FRACTL_JVM_OPTS="$FRACTL_JVM_OPTS -Djline.terminal=jline.UnixTerminal" stty -icanon min 1 -echo > /dev/null 2>&1 fi if [ ! -r "$FRACTL_JAR" ]; then self_install present_dir=`pwd` rm -rf $FRACTL_HOME/self-installs/fractl-lein-template cd $FRACTL_HOME/self-installs git clone https://github.com/fractl-io/fractl-lein-template.git || exit 1 cd $FRACTL_HOME/self-installs/fractl-lein-template/fractl-model lein install || exit 1 cd ${present_dir} fi $FRACTL_JAVA_CMD $FRACTL_JVM_OPTS -jar ${FRACTL_JAR} "$@"