mill
author Tomas Zeman <tomas@functionals.cz>
Thu, 29 Aug 2019 22:08:50 +0200
changeset 2 b2f4b60986c8
parent 0 a3f8b52a99ca
child 11 4d14b8c6fe87
permissions -rwxr-xr-x
visjs: 0.1-SNAPSHOT -> 0.1

#!/usr/bin/env sh

# This is a wrapper script, that automatically download mill from GitHub release pages
# You can give the required mill version with MILL_VERSION env variable
# If no version is given, it falls back to the value of DEFAULT_MILL_VERSION
DEFAULT_MILL_VERSION=0.5.0

set -e

if [ -z "$MILL_VERSION" ] ; then
  if [ -f ".mill-version" ] ; then
    MILL_VERSION="$(head -n 1 .mill-version 2> /dev/null)"
  elif [ -f "mill" ] && [ "$BASH_SOURCE" != "mill" ] ; then
    MILL_VERSION=$(grep -F "DEFAULT_MILL_VERSION=" "mill" | head -n 1 | cut -d= -f2)
  else
    MILL_VERSION=$DEFAULT_MILL_VERSION
  fi
fi

MILL_DOWNLOAD_PATH="$HOME/.mill/download"
MILL_EXEC_PATH="${MILL_DOWNLOAD_PATH}/$MILL_VERSION"

if [ ! -x "$MILL_EXEC_PATH" ] ; then
  mkdir -p $MILL_DOWNLOAD_PATH
  DOWNLOAD_FILE=$MILL_EXEC_PATH-tmp-download
  MILL_DOWNLOAD_URL="https://github.com/lihaoyi/mill/releases/download/${MILL_VERSION%%-*}/$MILL_VERSION-assembly"
  curl --fail -L -o "$DOWNLOAD_FILE" "$MILL_DOWNLOAD_URL"
  chmod +x "$DOWNLOAD_FILE"
  mv "$DOWNLOAD_FILE" "$MILL_EXEC_PATH"
  unset DOWNLOAD_FILE
  unset MILL_DOWNLOAD_URL
fi

unset MILL_DOWNLOAD_PATH
unset MILL_VERSION

exec $MILL_EXEC_PATH "$@"