Created
March 23, 2021 16:07
-
-
Save staticfloat/196bea18b214f5859ef85e83356445eb to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
OS=$(uname) | |
ARCH="$(uname -m)" | |
get_julia_url() { | |
local VERSION=${1} | |
local MAJMIN="${VERSION%.*}" | |
if [[ "$OS" == "Linux" ]]; then | |
if [[ "$ARCH" == "x86_64" ]]; then | |
if [[ "${VERSION}" == "master" ]]; then | |
echo "https://julialangnightlies-s3.julialang.org/bin/linux/x64/julia-latest-linux64.tar.gz" | |
else | |
echo "https://julialang-s3.julialang.org/bin/linux/x64/${MAJMIN}/julia-${VERSION}-linux-x86_64.tar.gz" | |
fi | |
elif [[ "$ARCH" == "i686" ]]; then | |
if [[ "${VERSION}" == "master" ]]; then | |
echo "https://julialangnightlies-s3.julialang.org/bin/linux/x86/julia-latest-linux32.tar.gz" | |
else | |
echo "https://julialang-s3.julialang.org/bin/linux/x86/${MAJMIN}/julia-${VERSION}-linux-i686.tar.gz" | |
fi | |
elif [[ "$ARCH" == "armhf" ]] || [[ "$ARCH" == "armv7l" ]]; then | |
if [[ "${VERSION}" == "master" ]]; then | |
echo "https://julialangnightlies-s3.julialang.org/bin/linux/armv7l/julia-latest-linuxarmv7l.tar.gz" | |
else | |
echo "https://julialang.julialang.org/bin/linux/armv7l/${MAJMIN}/julia-${VERSION}-linux-armv7l.tar.gz" | |
fi | |
elif [[ "$ARCH" == "aarch64" ]]; then | |
if [[ "${VERSION}" == "master" ]]; then | |
echo "https://julialangnightlies-s3.julialang.org/bin/linux/x86/julia-latest-linuxaarch64.tar.gz" | |
else | |
echo "https://julialang-s3.julialang.org/bin/linux/aarch64/${MAJMIN}/julia-${VERSION}-linux-aarch64.tar.gz" | |
fi | |
else | |
echo "Architecture $ARCH unsupported on $OS" >&2 | |
exit 1 | |
fi | |
elif [[ "$OS" == "Darwin" ]]; then | |
if [[ "$ARCH" == "x86_64" ]]; then | |
if [[ "${VERSION}" == "master" ]]; then | |
echo "https://julialangnightlies-s3.julialang.org/bin/mac/x64/julia-latest-mac64.dmg" | |
else | |
echo "https://julialang-s3.julialang.org/bin/mac/x64/${MAJMIN}/julia-${VERSION}-mac64.dmg" | |
fi | |
else | |
echo "Architecture $ARCH unsupported on $OS" >&2 | |
exit 1 | |
fi | |
elif [[ "$OS" == "FreeBSD" ]]; then | |
if [[ "$ARCH" == "amd64" ]]; then | |
if [[ "${VERSION}" == "master" ]]; then | |
echo "https://julialangnightlies-s3.julialang.org/bin/freebsd/x64/julia-latest-freebsd64.tar.gz" | |
else | |
echo "https://julialang-s3.julialang.org/bin/freebsd/x64/${MAJMIN}/julia-${VERSION}-freebsd-x86_64.tar.gz" | |
fi | |
else | |
echo "Architecture $ARCH unsupported on $OS" >&2 | |
exit 1 | |
fi | |
else | |
echo "Platform $OS unsupported" | |
exit 1 | |
fi | |
} | |
FORCE=no | |
ARGS=() | |
while [[ $# -gt 0 ]]; do | |
case "$1" in | |
--force) | |
FORCE=yes | |
shift | |
;; | |
*) | |
ARGS+=("$1") | |
shift | |
;; | |
esac | |
done | |
VERSION=${ARGS[0]:-1.5.3} | |
JULIA_URL=$(get_julia_url ${VERSION}) | |
DESTDIR=~/dist/${ARCH}/julia-${VERSION} | |
if [[ -d ${DESTDIR} ]]; then | |
if [[ "${FORCE}" == "yes" ]]; then | |
rm -rf ${DESTDIR} | |
else | |
echo "${DESTDIR} already exists" >&2 | |
exit 0 | |
fi | |
fi | |
mkdir -p ${DESTDIR} | |
echo "Downloading ${JULIA_URL}" | |
if [[ "$OS" == "Linux" ]] || [[ "$OS" == "FreeBSD" ]]; then | |
# Download, unpack Julia version into the destination directory | |
curl -# -L "$JULIA_URL" | tar -C $DESTDIR --strip-components=1 -f- -zxv | |
elif [[ "$OS" == "Darwin" ]]; then | |
# Download, unpack Julia version into the destination directory | |
curl -L "$JULIA_URL" -o ${DESTDIR}/julia-installer.dmg | |
hdiutil mount ${DESTDIR}/julia-installer.dmg | |
cp -Ra /Volumes/Julia-*/Julia-*.app/Contents/Resources/julia/* ${DESTDIR} | |
for j in /Volumes/Julia-*; do | |
hdiutil detach "$j" | |
done | |
rm -f ${DESTDIR}/julia-installer.dmg | |
else | |
echo "Platform $OS unsupported" | |
exit 1 | |
fi | |
# Link julia into our local bin directory | |
mkdir -p ~/local/bin | |
LN_FORCE_FLAG="" | |
if [[ "${FORCE}" == "yes" ]]; then | |
LN_FORCE_FLAG="-f" | |
fi | |
if [[ "${VERSION}" != "master" ]]; then | |
ln -sf ${DESTDIR}/bin/julia ~/local/bin/julia-${VERSION} | |
ln -s ${LN_FORCE_FLAG} ${DESTDIR}/bin/julia ~/local/bin/julia-${VERSION%.*} | |
ln -s ${LN_FORCE_FLAG} ${DESTDIR}/bin/julia ~/local/bin/ | |
else | |
ln -sf ${DESTDIR}/bin/julia ~/local/bin/julia-master | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment