Skip to content

Instantly share code, notes, and snippets.

@alexandru
Last active September 26, 2018 06:24
Show Gist options
  • Save alexandru/3f338500aa84538f2164b40b8a61e186 to your computer and use it in GitHub Desktop.
Save alexandru/3f338500aa84538f2164b40b8a61e186 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# Script that detects if Scala's SBT is installed and if
# not then it automatically downloads and installs it at
# a specified path.
#
# Author: Alexandru Nedelcu (https://alexn.org)
#
set -e
VERSION="1.2.3"
SBT_DIR="$(dirname $0)/.sbt"
if [ -x "$(command -v sbt)" ]; then
SBT_COMMAND="sbt"
elif ! [ -d "${SBT_DIR}" ]; then
DIR="$(mktemp -d)"
echo "Downloading SBT (temp dir: ${DIR}), please wait..."
wget -q "https://piccolo.link/sbt-$VERSION.tgz" -O ${DIR}/sbt.tgz
echo "Uncompressing and copying SBT ..."
tar xzf "${DIR}/sbt.tgz" -C "${DIR}"
mv "${DIR}/sbt" "${SBT_DIR}"
rm -rf "${DIR}"
SBT_COMMAND="${SBT_DIR}/bin/sbt"
else
SBT_COMMAND="${SBT_DIR}/bin/sbt"
fi
echo "Using SBT command: ${SBT_COMMAND}"
exec "${SBT_COMMAND}" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment