From b98eec89d4711feb96541bd67fa45cd79e55d180 Mon Sep 17 00:00:00 2001 From: Sascha Mann Date: Sun, 9 Feb 2020 19:37:43 +0100 Subject: [PATCH 1/7] Add Julia 1.3.1 --- images/linux/scripts/installers/julia.sh | 50 +++++++++++++++ .../win/scripts/Installers/Install-Julia.ps1 | 62 +++++++++++++++++++ .../win/scripts/Installers/Validate-Julia.ps1 | 49 +++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 images/linux/scripts/installers/julia.sh create mode 100644 images/win/scripts/Installers/Install-Julia.ps1 create mode 100644 images/win/scripts/Installers/Validate-Julia.ps1 diff --git a/images/linux/scripts/installers/julia.sh b/images/linux/scripts/installers/julia.sh new file mode 100644 index 00000000..849ff8f2 --- /dev/null +++ b/images/linux/scripts/installers/julia.sh @@ -0,0 +1,50 @@ +#!/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 + +# This function installs Julia using the specified arguments: +# $1=MajorVersion (1.3) +# $2=MajorAndMinorVersion (1.3.1) +# $3=IsDefaultVersion (true or false) + +function InstallJulia () { + curl -sL "https://julialang-s3.julialang.org/bin/linux/x64/$1/julia-$2-linux-x86_64.tar.gz" -o "julia-$2-linux-x86_64.tar.gz" + mkdir -p "/usr/local/julia$1" + tar -C "/usr/local/julia$1" -xzf "julia-$2-linux-x86_64.tar.gz" --strip-components=1 julia + rm "julia-$2-linux-x86_64.tar.gz" + + # If this version of Julia is to be the default version, + # symlink it into the path + if [ "$3" = true ]; then + ln -s "/usr/local/julia$1/bin/julia" /usr/bin/julia + 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 + if [ "$3" = true ]; then + if ! command -v julia; then + echo "Julia was not installed or found on PATH" + exit 1 + fi + fi + + # Verify output of julia --version + if [ ! "$(/usr/local/julia"$1"/bin/julia --version)" = "julia version $2" ]; then + 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))" +} + +InstallJulia 1.3 1.3.1 true diff --git a/images/win/scripts/Installers/Install-Julia.ps1 b/images/win/scripts/Installers/Install-Julia.ps1 new file mode 100644 index 00000000..cde01e69 --- /dev/null +++ b/images/win/scripts/Installers/Install-Julia.ps1 @@ -0,0 +1,62 @@ +################################################################################ +## File: Install-Julia.ps1 +## Desc: Install Julia +################################################################################ + +Import-Module -Name ImageHelpers -Force +function Install-JuliaVersion +{ + Param + ( + [String]$juliaVersion, + [Switch]$addToDefaultPath + ) + + # Split versions. + $juliaMajorVersion = $juliaVersion.split(".")[0] + "." + $juliaVersion.split(".")[1] + + # Download the Julia installer. + Write-Host "Downloading Julia $juliaVersion..." + $ProgressPreference = 'SilentlyContinue' + Invoke-WebRequest -UseBasicParsing -Uri "https://julialang-s3.julialang.org/bin/winnt/x64/$juliaMajorVersion/julia-$juliaVersion-win64.exe" -OutFile "julia-$juliaVersion-win64.exe" + + # Install Julia. + # The installer will change in Julia 1.4. For future-proofing, a version check is run. + if ( $juliaMajorVersion -ge "1.4") + { + Start-Process -FilePath "julia-$juliaVersion-win64.exe" -ArgumentList "/SILENT /dir=C:\Julia" -NoNewWindow -Wait + } + else + { + Start-Process -FilePath "julia-$juliaVersion-win64.exe" -ArgumentList "/S /D=C:\Julia" -NoNewWindow -Wait + } + + # Delete unnecessary files to conserve space. + Write-Host "Deleting downloaded installer..." + Remove-Item "julia-$juliaVersion-win64.exe" + + # Make this the default version of Julia? + if ($addToDefaultPath) + { + Write-Host "Adding Julia $juliaVersion to the path..." + # Add the Julia binaries to the path. + Add-MachinePathItem "C:\Julia\Julia-$juliaVersion\bin" | Out-Null + } + + # Done + Write-Host "Done installing Julia $juliaVersion." + return "C:\Julia\Julia-$juliaVersion" +} + +# Install Julia +$juliaVersionsToInstall = $env:JULIA_VERSIONS.split(",") + +foreach($julia in $juliaVersionsToInstall) { + Write-Host "Installing Julia ${julia}" + if($julia -eq $env:JULIA_DEFAULT) { + $installDirectory = Install-JuliaVersion -juliaVersion $julia -addToDefaultPath + } else { + $installDirectory = Install-JuliaVersion -juliaVersion $julia + } + setx $envName "$installDirectory" /M +} diff --git a/images/win/scripts/Installers/Validate-Julia.ps1 b/images/win/scripts/Installers/Validate-Julia.ps1 new file mode 100644 index 00000000..e3c8973c --- /dev/null +++ b/images/win/scripts/Installers/Validate-Julia.ps1 @@ -0,0 +1,49 @@ +################################################################################ +## File: Validate-Julia.ps1 +## Desc: Validate Julia +################################################################################ + +# Verify that julia.exe is on the path +if(Get-Command -Name 'julia') +{ + Write-Host "$(julia --version) is on the path." +} +else +{ + Write-Host "Julia is not on the path." + exit 1 +} + +# Add details of available versions in Markdown +$tmplMark = @" +#### {0} + +_Environment:_ +* {1}: root directory of the Julia {0} installation + +"@ + +$tmplMarkRoot = @" +#### {0} + +_Environment:_ +* PATH: contains the location of julia.exe version {0} +* {1}: root directory of the Julia {0} installation +"@ + +$SoftwareName = "Julia (x64)" +$Description = New-Object System.Text.StringBuilder +$juliaVersionsToInstall = $env:JULIA_VERSIONS.split(",") + +foreach($julia in $juliaVersionsToInstall) { + $juliaVersion = Get-JuliaVersion + if ($juliaVersion -eq $julia) { + if($julia -eq $env:JULIA_DEFAULT) { + $null = $Description.AppendLine(($tmplMarkRoot -f $juliaVersion)) + } else { + $null = $Description.AppendLine(($tmplMark -f $juliaVersion)) + } + } +} + +Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description.ToString() From dd2c76c8a3a1f2d8cde5f4cdfbc40549c2576843 Mon Sep 17 00:00:00 2001 From: Sascha Mann Date: Tue, 11 Feb 2020 13:28:38 +0100 Subject: [PATCH 2/7] Use choco to install Julia --- .../win/scripts/Installers/Install-Julia.ps1 | 58 +------------------ 1 file changed, 1 insertion(+), 57 deletions(-) diff --git a/images/win/scripts/Installers/Install-Julia.ps1 b/images/win/scripts/Installers/Install-Julia.ps1 index cde01e69..0090d530 100644 --- a/images/win/scripts/Installers/Install-Julia.ps1 +++ b/images/win/scripts/Installers/Install-Julia.ps1 @@ -3,60 +3,4 @@ ## Desc: Install Julia ################################################################################ -Import-Module -Name ImageHelpers -Force -function Install-JuliaVersion -{ - Param - ( - [String]$juliaVersion, - [Switch]$addToDefaultPath - ) - - # Split versions. - $juliaMajorVersion = $juliaVersion.split(".")[0] + "." + $juliaVersion.split(".")[1] - - # Download the Julia installer. - Write-Host "Downloading Julia $juliaVersion..." - $ProgressPreference = 'SilentlyContinue' - Invoke-WebRequest -UseBasicParsing -Uri "https://julialang-s3.julialang.org/bin/winnt/x64/$juliaMajorVersion/julia-$juliaVersion-win64.exe" -OutFile "julia-$juliaVersion-win64.exe" - - # Install Julia. - # The installer will change in Julia 1.4. For future-proofing, a version check is run. - if ( $juliaMajorVersion -ge "1.4") - { - Start-Process -FilePath "julia-$juliaVersion-win64.exe" -ArgumentList "/SILENT /dir=C:\Julia" -NoNewWindow -Wait - } - else - { - Start-Process -FilePath "julia-$juliaVersion-win64.exe" -ArgumentList "/S /D=C:\Julia" -NoNewWindow -Wait - } - - # Delete unnecessary files to conserve space. - Write-Host "Deleting downloaded installer..." - Remove-Item "julia-$juliaVersion-win64.exe" - - # Make this the default version of Julia? - if ($addToDefaultPath) - { - Write-Host "Adding Julia $juliaVersion to the path..." - # Add the Julia binaries to the path. - Add-MachinePathItem "C:\Julia\Julia-$juliaVersion\bin" | Out-Null - } - - # Done - Write-Host "Done installing Julia $juliaVersion." - return "C:\Julia\Julia-$juliaVersion" -} - -# Install Julia -$juliaVersionsToInstall = $env:JULIA_VERSIONS.split(",") - -foreach($julia in $juliaVersionsToInstall) { - Write-Host "Installing Julia ${julia}" - if($julia -eq $env:JULIA_DEFAULT) { - $installDirectory = Install-JuliaVersion -juliaVersion $julia -addToDefaultPath - } else { - $installDirectory = Install-JuliaVersion -juliaVersion $julia - } - setx $envName "$installDirectory" /M -} +choco install julia -y From b6d99efb99160747a93761607c77e57fa1dd3d25 Mon Sep 17 00:00:00 2001 From: Sascha Mann Date: Tue, 11 Feb 2020 13:35:42 +0100 Subject: [PATCH 3/7] Simplify Validate-Julia.ps1 script --- .../win/scripts/Installers/Validate-Julia.ps1 | 36 ++++--------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/images/win/scripts/Installers/Validate-Julia.ps1 b/images/win/scripts/Installers/Validate-Julia.ps1 index e3c8973c..fa4a26e1 100644 --- a/images/win/scripts/Installers/Validate-Julia.ps1 +++ b/images/win/scripts/Installers/Validate-Julia.ps1 @@ -14,36 +14,12 @@ else exit 1 } -# Add details of available versions in Markdown -$tmplMark = @" -#### {0} - -_Environment:_ -* {1}: root directory of the Julia {0} installation - -"@ - -$tmplMarkRoot = @" -#### {0} - -_Environment:_ -* PATH: contains the location of julia.exe version {0} -* {1}: root directory of the Julia {0} installation -"@ - +# Add description of the software to Markdown $SoftwareName = "Julia (x64)" -$Description = New-Object System.Text.StringBuilder -$juliaVersionsToInstall = $env:JULIA_VERSIONS.split(",") +$juliaVersion = $(julia --version) -match "\d+\.\d+\.\d+" -foreach($julia in $juliaVersionsToInstall) { - $juliaVersion = Get-JuliaVersion - if ($juliaVersion -eq $julia) { - if($julia -eq $env:JULIA_DEFAULT) { - $null = $Description.AppendLine(($tmplMarkRoot -f $juliaVersion)) - } else { - $null = $Description.AppendLine(($tmplMark -f $juliaVersion)) - } - } -} +$Description = @" +_Version:_ $juliaVersion
+"@ -Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description.ToString() +Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description From be9cfd7f930da345abf37e420c7ffe92fc31cdac Mon Sep 17 00:00:00 2001 From: Sascha Mann Date: Tue, 11 Feb 2020 14:01:38 +0100 Subject: [PATCH 4/7] Fetch latest Julia version from GitHub API --- images/linux/scripts/installers/julia.sh | 36 ++++++++++++++++-------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/images/linux/scripts/installers/julia.sh b/images/linux/scripts/installers/julia.sh index 849ff8f2..eabcc63f 100644 --- a/images/linux/scripts/installers/julia.sh +++ b/images/linux/scripts/installers/julia.sh @@ -7,21 +7,33 @@ # Source the helpers for use with the script source $HELPER_SCRIPTS/document.sh +# 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 +} + + # This function installs Julia using the specified arguments: -# $1=MajorVersion (1.3) -# $2=MajorAndMinorVersion (1.3.1) -# $3=IsDefaultVersion (true or false) +# $1=MajorAndMinorVersion (1.3.1) +# $2=IsDefaultVersion (true or false) function InstallJulia () { - curl -sL "https://julialang-s3.julialang.org/bin/linux/x64/$1/julia-$2-linux-x86_64.tar.gz" -o "julia-$2-linux-x86_64.tar.gz" - mkdir -p "/usr/local/julia$1" - tar -C "/usr/local/julia$1" -xzf "julia-$2-linux-x86_64.tar.gz" --strip-components=1 julia - rm "julia-$2-linux-x86_64.tar.gz" + # Extract Major and Minor version from full version string + juliaMajorAndMinorVersion="$(sed 's/\.*[0-9]//3' <<< $1)" + + 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" + mkdir -p "/usr/local/julia$juliaMajorAndMinorVersion" + tar -C "/usr/local/julia$juliaMajorAndMinorVersion" -xzf "julia-$1-linux-x86_64.tar.gz" --strip-components=1 julia + rm "julia-$1-linux-x86_64.tar.gz" # If this version of Julia is to be the default version, # symlink it into the path - if [ "$3" = true ]; then - ln -s "/usr/local/julia$1/bin/julia" /usr/bin/julia + if [ "$2" = true ]; then + ln -s "/usr/local/julia$juliaMajorAndMinorVersion/bin/julia" /usr/bin/julia fi # Run tests to determine that the software installed as expected @@ -29,7 +41,7 @@ function InstallJulia () { # If this version of Julia is to be the default version, # check that it has been added to PATH - if [ "$3" = true ]; then + if [ "$2" = true ]; then if ! command -v julia; then echo "Julia was not installed or found on PATH" exit 1 @@ -37,7 +49,7 @@ function InstallJulia () { fi # Verify output of julia --version - if [ ! "$(/usr/local/julia"$1"/bin/julia --version)" = "julia version $2" ]; then + if [ ! "$(/usr/local/julia"$juliaMajorAndMinorVersion"/bin/julia --version)" = "julia version $1" ]; then echo "Julia was not installed correctly" exit 1 fi @@ -47,4 +59,4 @@ function InstallJulia () { DocumentInstalledItem "Julia ($(julia --version))" } -InstallJulia 1.3 1.3.1 true +InstallJulia "$(GetLatestJuliaRelease)" true From e11f4638dc7f0b1a3d3f8267379240085f06567d Mon Sep 17 00:00:00 2001 From: Sascha Mann Date: Tue, 11 Feb 2020 14:38:33 +0100 Subject: [PATCH 5/7] Fix Major.Minor version regex --- images/linux/scripts/installers/julia.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/linux/scripts/installers/julia.sh b/images/linux/scripts/installers/julia.sh index eabcc63f..1ca45032 100644 --- a/images/linux/scripts/installers/julia.sh +++ b/images/linux/scripts/installers/julia.sh @@ -23,7 +23,7 @@ function GetLatestJuliaRelease () { function InstallJulia () { # Extract Major and Minor version from full version string - juliaMajorAndMinorVersion="$(sed 's/\.*[0-9]//3' <<< $1)" + juliaMajorAndMinorVersion="$(sed 's/\.[^.]*$//' <<< $1)" 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" mkdir -p "/usr/local/julia$juliaMajorAndMinorVersion" From 68fb8ac37ca6a4778ce938bf5d87fd1fbe7b084e Mon Sep 17 00:00:00 2001 From: Sascha Mann Date: Wed, 12 Feb 2020 15:03:26 +0100 Subject: [PATCH 6/7] Fix Julia markdown description --- images/win/scripts/Installers/Validate-Julia.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/win/scripts/Installers/Validate-Julia.ps1 b/images/win/scripts/Installers/Validate-Julia.ps1 index fa4a26e1..e31bd39f 100644 --- a/images/win/scripts/Installers/Validate-Julia.ps1 +++ b/images/win/scripts/Installers/Validate-Julia.ps1 @@ -16,7 +16,7 @@ else # Add description of the software to Markdown $SoftwareName = "Julia (x64)" -$juliaVersion = $(julia --version) -match "\d+\.\d+\.\d+" +$juliaVersion = $(julia --version).split() -match "\d+\.\d+\.\d+" $Description = @" _Version:_ $juliaVersion
From 036ff7c43c3c2e54050d040d3577b479a899b5bc Mon Sep 17 00:00:00 2001 From: Sascha Mann Date: Wed, 12 Feb 2020 15:17:05 +0100 Subject: [PATCH 7/7] Change Julia install directory --- images/win/scripts/Installers/Install-Julia.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/win/scripts/Installers/Install-Julia.ps1 b/images/win/scripts/Installers/Install-Julia.ps1 index 0090d530..90547472 100644 --- a/images/win/scripts/Installers/Install-Julia.ps1 +++ b/images/win/scripts/Installers/Install-Julia.ps1 @@ -3,4 +3,4 @@ ## Desc: Install Julia ################################################################################ -choco install julia -y +choco install julia -y --ia "/D=C:\Julia"