mill
changeset 17 4245abe80f45
parent 11 4d14b8c6fe87
equal deleted inserted replaced
16:e01a46f45b02 17:4245abe80f45
     1 #!/usr/bin/env sh
     1 #!/usr/bin/env sh
     2 
     2 
     3 # This is a wrapper script, that automatically download mill from GitHub release pages
     3 # This is a wrapper script, that automatically download mill from GitHub release pages
     4 # You can give the required mill version with MILL_VERSION env variable
     4 # You can give the required mill version with MILL_VERSION env variable
     5 # If no version is given, it falls back to the value of DEFAULT_MILL_VERSION
     5 # If no version is given, it falls back to the value of DEFAULT_MILL_VERSION
     6 DEFAULT_MILL_VERSION=0.6.3
       
     7 
     6 
     8 set -e
     7 set -e
       
     8 
       
     9 if [ -z "${DEFAULT_MILL_VERSION}" ] ; then
       
    10   DEFAULT_MILL_VERSION=0.10.10
       
    11 fi
     9 
    12 
    10 if [ -z "$MILL_VERSION" ] ; then
    13 if [ -z "$MILL_VERSION" ] ; then
    11   if [ -f ".mill-version" ] ; then
    14   if [ -f ".mill-version" ] ; then
    12     MILL_VERSION="$(head -n 1 .mill-version 2> /dev/null)"
    15     MILL_VERSION="$(head -n 1 .mill-version 2> /dev/null)"
    13   elif [ -f "mill" ] && [ "$BASH_SOURCE" != "mill" ] ; then
    16   elif [ -f ".config/mill-version" ] ; then
       
    17     MILL_VERSION="$(head -n 1 .config/mill-version 2> /dev/null)"
       
    18   elif [ -f "mill" ] && [ "$0" != "mill" ] ; then
    14     MILL_VERSION=$(grep -F "DEFAULT_MILL_VERSION=" "mill" | head -n 1 | cut -d= -f2)
    19     MILL_VERSION=$(grep -F "DEFAULT_MILL_VERSION=" "mill" | head -n 1 | cut -d= -f2)
    15   else
    20   else
    16     MILL_VERSION=$DEFAULT_MILL_VERSION
    21     MILL_VERSION=$DEFAULT_MILL_VERSION
    17   fi
    22   fi
    18 fi
    23 fi
    26 
    31 
    27 version_remainder="$MILL_VERSION"
    32 version_remainder="$MILL_VERSION"
    28 MILL_MAJOR_VERSION="${version_remainder%%.*}"; version_remainder="${version_remainder#*.}"
    33 MILL_MAJOR_VERSION="${version_remainder%%.*}"; version_remainder="${version_remainder#*.}"
    29 MILL_MINOR_VERSION="${version_remainder%%.*}"; version_remainder="${version_remainder#*.}"
    34 MILL_MINOR_VERSION="${version_remainder%%.*}"; version_remainder="${version_remainder#*.}"
    30 
    35 
    31 if [ ! -x "$MILL_EXEC_PATH" ] ; then
    36 if [ ! -s "$MILL_EXEC_PATH" ] ; then
    32   mkdir -p $MILL_DOWNLOAD_PATH
    37   mkdir -p "$MILL_DOWNLOAD_PATH"
    33   if [ "$MILL_MAJOR_VERSION" -gt 0 ] || [ "$MILL_MINOR_VERSION" -ge 5 ] ; then
    38   if [ "$MILL_MAJOR_VERSION" -gt 0 ] || [ "$MILL_MINOR_VERSION" -ge 5 ] ; then
    34     ASSEMBLY="-assembly"
    39     ASSEMBLY="-assembly"
    35   fi
    40   fi
    36   DOWNLOAD_FILE=$MILL_EXEC_PATH-tmp-download
    41   DOWNLOAD_FILE=$MILL_EXEC_PATH-tmp-download
    37   MILL_DOWNLOAD_URL="https://github.com/lihaoyi/mill/releases/download/${MILL_VERSION%%-*}/$MILL_VERSION${ASSEMBLY}"
    42   MILL_VERSION_TAG=$(echo $MILL_VERSION | sed -E 's/([^-]+)(-M[0-9]+)?(-.*)?/\1\2/')
       
    43   MILL_DOWNLOAD_URL="https://github.com/lihaoyi/mill/releases/download/${MILL_VERSION_TAG}/$MILL_VERSION${ASSEMBLY}"
    38   curl --fail -L -o "$DOWNLOAD_FILE" "$MILL_DOWNLOAD_URL"
    44   curl --fail -L -o "$DOWNLOAD_FILE" "$MILL_DOWNLOAD_URL"
    39   chmod +x "$DOWNLOAD_FILE"
    45   chmod +x "$DOWNLOAD_FILE"
    40   mv "$DOWNLOAD_FILE" "$MILL_EXEC_PATH"
    46   mv "$DOWNLOAD_FILE" "$MILL_EXEC_PATH"
    41   unset DOWNLOAD_FILE
    47   unset DOWNLOAD_FILE
    42   unset MILL_DOWNLOAD_URL
    48   unset MILL_DOWNLOAD_URL
    43 fi
    49 fi
    44 
    50 
       
    51 if [ -z "$MILL_MAIN_CLI" ] ; then
       
    52   MILL_MAIN_CLI="${0}"
       
    53 fi
       
    54 
       
    55 MILL_FIRST_ARG=""
       
    56 if [ "$1" = "--bsp" ] || [ "$1" = "-i" ] || [ "$1" = "--interactive" ] || [ "$1" = "--no-server" ] || [ "$1" = "--repl" ] || [ "$1" = "--help" ] ; then
       
    57   # Need to preserve the first position of those listed options
       
    58   MILL_FIRST_ARG=$1
       
    59   shift
       
    60 fi
       
    61 
    45 unset MILL_DOWNLOAD_PATH
    62 unset MILL_DOWNLOAD_PATH
    46 unset MILL_VERSION
    63 unset MILL_VERSION
    47 
    64 
    48 exec $MILL_EXEC_PATH "$@"
    65 exec $MILL_EXEC_PATH $MILL_FIRST_ARG -D "mill.main.cli=${MILL_MAIN_CLI}" "$@"