Files
runner-images/images/linux/scripts/installers/julia.sh
T

64 lines
2.3 KiB
Bash
Raw Normal View History

2020-02-09 19:37:43 +01:00
#!/bin/bash
################################################################################
## File: julia.sh
## Desc: Installs Julia, and adds Julia to the path
################################################################################
# Source the helpers for use with the script
source $HELPER_SCRIPTS/document.sh
2020-02-11 14:01:38 +01:00
# This function fetches the latest Julia release from the GitHub API
# Based on https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c
function GetLatestJuliaRelease () {
curl --silent "https://api.github.com/repos/julialang/julia/releases/latest" |
grep '"tag_name":' |
sed -E 's/.*"([^"]+)".*/\1/' |
sed 's/v//' # remove v prefix
}
2020-02-09 19:37:43 +01:00
# This function installs Julia using the specified arguments:
2020-02-11 14:01:38 +01:00
# $1=MajorAndMinorVersion (1.3.1)
# $2=IsDefaultVersion (true or false)
2020-02-09 19:37:43 +01:00
function InstallJulia () {
2020-02-11 14:01:38 +01:00
# Extract Major and Minor version from full version string
2020-03-02 14:44:14 +03:00
juliaMajorAndMinorVersion="$(cut -d. -f1,2 <<< $1)"
juliaInstallationPath="/usr/local/julia$1"
2020-02-11 14:01:38 +01:00
curl -sL "https://julialang-s3.julialang.org/bin/linux/x64/$juliaMajorAndMinorVersion/julia-$1-linux-x86_64.tar.gz" -o "julia-$1-linux-x86_64.tar.gz"
2020-03-02 14:44:14 +03:00
mkdir -p "$juliaInstallationPath"
tar -C "$juliaInstallationPath" -xzf "julia-$1-linux-x86_64.tar.gz" --strip-components=1
2020-02-11 14:01:38 +01:00
rm "julia-$1-linux-x86_64.tar.gz"
2020-02-09 19:37:43 +01:00
# If this version of Julia is to be the default version,
# symlink it into the path
2020-02-11 14:01:38 +01:00
if [ "$2" = true ]; then
2020-03-02 14:44:14 +03:00
ln -s "$juliaInstallationPath/bin/julia" /usr/bin/julia
2020-02-09 19:37:43 +01:00
fi
# Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work"
# If this version of Julia is to be the default version,
# check that it has been added to PATH
2020-02-11 14:01:38 +01:00
if [ "$2" = true ]; then
2020-02-09 19:37:43 +01:00
if ! command -v julia; then
echo "Julia was not installed or found on PATH"
exit 1
fi
fi
# Verify output of julia --version
2020-03-02 14:44:14 +03:00
if [ ! "$($juliaInstallationPath/bin/julia --version)" = "julia version $1" ]; then
2020-02-09 19:37:43 +01:00
echo "Julia was not installed correctly"
exit 1
fi
# Document what was added to the image
echo "Lastly, documenting what we added to the metadata file"
DocumentInstalledItem "Julia ($(julia --version))"
}
2020-02-11 14:01:38 +01:00
InstallJulia "$(GetLatestJuliaRelease)" true