-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
129 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.9.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#!/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 parameter | ||
# If no version is given, it falls back to the value of DEFAULT_MILL_VERSION | ||
# | ||
# Project page: https://github.com/lefou/millw | ||
# | ||
# If you want to improve this script, please also contribute your changes back! | ||
# | ||
# Licensed under the Apache License, Version 2.0 | ||
|
||
|
||
DEFAULT_MILL_VERSION=0.5.0 | ||
|
||
set -e | ||
|
||
# Explicit commandline argument takes precedence over all other methods | ||
if [ "x$1" = "x--mill-version" ] ; then | ||
shift | ||
if [ "x$1" != "x" ] ; then | ||
MILL_VERSION="$1" | ||
shift | ||
else | ||
echo "You specified --mill-version without a version." | ||
echo "Please provide a version that matches one provided on" | ||
echo "https://github.com/lihaoyi/mill/releases" | ||
false | ||
fi | ||
fi | ||
|
||
# Please note, that if a MILL_VERSION is already set in the environment, | ||
# We reuse it's value and skip searching for a value. | ||
|
||
# If not already set, read .mill-version file | ||
if [ "x${MILL_VERSION}" = "x" ] ; then | ||
if [ -f ".mill-version" ] ; then | ||
MILL_VERSION="$(head -n 1 .mill-version 2> /dev/null)" | ||
fi | ||
fi | ||
|
||
if [ "x${XDG_CACHE_HOME}" != "x" ] ; then | ||
MILL_DOWNLOAD_PATH="${XDG_CACHE_HOME}/mill/download" | ||
else | ||
MILL_DOWNLOAD_PATH="${HOME}/.cache/mill/download" | ||
fi | ||
|
||
# If not already set, try to fetch newest from Github | ||
if [ "x${MILL_VERSION}" = "x" ] ; then | ||
# TODO: try to load latest version from release page | ||
echo "No mill version specified." | ||
echo "You should provide a version via '.mill-version' file or --mill-version option." | ||
|
||
mkdir -p "${MILL_DOWNLOAD_PATH}" | ||
LANG=C touch -d '1 hour ago' "${MILL_DOWNLOAD_PATH}/.expire_latest" | ||
if [ "${MILL_DOWNLOAD_PATH}/.latest" -nt "${MILL_DOWNLOAD_PATH}/.expire_latest" ] ; then | ||
# we know a current latest version | ||
MILL_VERSION="$(head -n 1 ${MILL_DOWNLOAD_PATH}/.latest 2> /dev/null)" | ||
fi | ||
|
||
if [ "x${MILL_VERSION}" = "x" ] ; then | ||
# we don't know a current latest version | ||
echo "Retrieving latest mill version ..." | ||
LANG=C curl -s -i -f -I https://github.com/lihaoyi/mill/releases/latest 2> /dev/null | grep --ignore-case Location: | sed s'/^.*tag\///' | tr -d '\r\n' > "${MILL_DOWNLOAD_PATH}/.latest" | ||
MILL_VERSION="$(head -n 1 ${MILL_DOWNLOAD_PATH}/.latest 2> /dev/null)" | ||
fi | ||
|
||
if [ "x${MILL_VERSION}" = "x" ] ; then | ||
# Last resort | ||
MILL_VERSION="${DEFAULT_MILL_VERSION}" | ||
echo "Falling back to hardcoded mill version ${MILL_VERSION}" | ||
else | ||
echo "Using mill version ${MILL_VERSION}" | ||
fi | ||
fi | ||
|
||
MILL="${MILL_DOWNLOAD_PATH}/${MILL_VERSION}" | ||
|
||
# If not already downloaded, download it | ||
if [ ! -s "${MILL}" ] ; then | ||
|
||
# support old non-XDG download dir | ||
MILL_OLD_DOWNLOAD_PATH="${HOME}/.mill/download" | ||
OLD_MILL="${MILL_OLD_DOWNLOAD_PATH}/${MILL_VERSION}" | ||
if [ -x "${OLD_MILL}" ] ; then | ||
MILL="${OLD_MILL}" | ||
else | ||
VERSION_PREFIX="$(echo -n $MILL_VERSION | cut -b -4)" | ||
case $VERSION_PREFIX in | ||
0.0. | 0.1. | 0.2. | 0.3. | 0.4. ) | ||
DOWNLOAD_SUFFIX="" | ||
;; | ||
*) | ||
DOWNLOAD_SUFFIX="-assembly" | ||
;; | ||
esac | ||
unset VERSION_PREFIX | ||
|
||
DOWNLOAD_FILE=$(mktemp mill.XXXX) | ||
# TODO: handle command not found | ||
echo "Downloading mill ${MILL_VERSION} from https://github.com/lihaoyi/mill/releases ..." | ||
curl -L -o "${DOWNLOAD_FILE}" "https://github.com/lihaoyi/mill/releases/download/${MILL_VERSION%%-*}/${MILL_VERSION}${DOWNLOAD_SUFFIX}" | ||
chmod +x "${DOWNLOAD_FILE}" | ||
mkdir -p "${MILL_DOWNLOAD_PATH}" | ||
mv "${DOWNLOAD_FILE}" "${MILL}" | ||
|
||
unset DOWNLOAD_FILE | ||
unset DOWNLOAD_SUFFIX | ||
fi | ||
fi | ||
|
||
unset MILL_DOWNLOAD_PATH | ||
unset MILL_OLD_DOWNLOAD_PATH | ||
unset OLD_MILL | ||
unset MILL_VERSION | ||
|
||
exec $MILL "$@" |