From 5bb30430b04508c9b77b4ef7f32855f5ac036379 Mon Sep 17 00:00:00 2001 From: Wojtek Mach Date: Wed, 30 Oct 2024 13:28:59 +0100 Subject: [PATCH 1/5] Add elixir-lang.org/install.sh and install.bat --- install.bat | 164 +++++++++++++++++++++++++++++ install.markdown | 32 +++++- install.sh | 261 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 456 insertions(+), 1 deletion(-) create mode 100755 install.bat create mode 100755 install.sh diff --git a/install.bat b/install.bat new file mode 100755 index 000000000..40e07428e --- /dev/null +++ b/install.bat @@ -0,0 +1,164 @@ +@echo off +REM See latest version at: +REM https://github.com/elixir-lang/elixir-lang.github.com/blob/main/install.bat + +setlocal EnableDelayedExpansion + +set "otp_version=latest" +set "elixir_version=latest" +set "force=false" + +goto :main + +:usage +echo Usage: install.bat [arguments] [options] +echo. +echo Arguments: +echo. +echo elixir@VERSION Install specific version of Elixir +echo otp@VERSION Install specific version of Erlang/OTP +echo. +echo By default, elixir@latest and otp@latest are installed. +echo. +echo Options: +echo. +echo -f, --force Forces installation even if it was previously installed +echo -h, --help Prints this help +echo. +echo Examples: +echo. +echo install.bat +echo install.bat elixir@1.16.3 otp@26.2.5.4 +echo install.bat elixir@main +echo. +goto :eof + +:main +for %%i in (%*) do ( + set arg=%%i + + if "!arg:~0,7!" == "elixir@" ( + set "elixir_version=!arg:~7!" + ) else if "!arg:~0,4!" == "otp@" ( + set "otp_version=!arg:~4!" + ) else if "!arg!" == "-f" ( + set "force=true" + ) else if "!arg!" == "--force" ( + set "force=true" + ) else if "!arg!" == "-h" ( + call :usage + exit /b 0 + ) else if "!arg!" == "--help" ( + call :usage + exit /b 0 + ) else ( + echo error: unknown argument !arg! + exit /b 1 + ) +) + +if "!otp_version!" == "latest" ( + set "url=https://github.com/erlef/otp_builds/releases/latest" + for /f "tokens=2 delims= " %%a in ('curl -fsS --head "!url!" ^| findstr /I "^location:"') do set url=%%a + set "otp_version=!url:*releases/tag/OTP-=!" +) + +if "!elixir_version!" == "latest" ( + set "url=https://github.com/elixir-lang/elixir/releases/latest" + for /f "tokens=2 delims= " %%a in ('curl -fsS --head "!url!" ^| findstr /I "^location:"') do set url=%%a + set "elixir_version=!url:*releases/tag/v=!" +) + +for /f "tokens=1 delims=." %%A in ("!otp_version!") do set "elixir_otp_release=%%A" +for /f "tokens=1,2 delims=." %%A in ("!elixir_version!") do set "elixir_major_minor=%%A.%%B" +if "%elixir_major_minor%" == "1.15" ( + if %elixir_otp_release% GEQ 26 set "elixir_otp_release=26" +) else if "%elixir_major_minor%" == "1.16" ( + if %elixir_otp_release% GEQ 26 set "elixir_otp_release=26" +) else if "%elixir_major_minor%" == "1.14" ( + if %elixir_otp_release% GEQ 25 set "elixir_otp_release=25" +) + +set "root_dir=%USERPROFILE%\.elixir-install" +set "tmp_dir=%root_dir%\tmp" +mkdir %tmp_dir% 2>nul +set "otp_dir=%root_dir%\installs\otp\%otp_version%" +set "elixir_dir=%root_dir%\installs\elixir\%elixir_version%-otp-%elixir_otp_release%" + +call :install_otp +if %errorlevel% neq 0 exit /b 1 + +set /p="checking OTP... " curl.exe -fsSO {{ site.url }}/install.bat +> .\install.bat elixir@1.17.3 otp@27.1.2 +> $installs_dir = "$env:USERPROFILE\.elixir-install\installs" +> $env:PATH = "$installs_dir\otp\27.1.2\bin;$env:PATH" +> $env:PATH = "$installs_dir\elixir\1.17.3-otp-27\bin;$env:PATH" +> iex.bat +``` + +Use `install.sh --help` or `install.bat --help` to learn more about available arguments and options. + +Install scripts support installing Elixir 1.14+. + ## By Operating System Install Elixir according to your operating system and tool of choice. diff --git a/install.sh b/install.sh new file mode 100755 index 000000000..5599a92a4 --- /dev/null +++ b/install.sh @@ -0,0 +1,261 @@ +#!/bin/sh +# See latest version at: +# https://github.com/elixir-lang/elixir-lang.github.com/blob/main/install.sh + +set -eu + +otp_version=latest +elixir_version=latest +force=false + +usage() { + cat<&2 + exit 1 + ;; + esac + done + + root_dir="$HOME/.elixir-install" + tmp_dir="$root_dir/tmp" + mkdir -p "$tmp_dir" + + if [ "${otp_version}" = latest ]; then + url=$(curl -fsS --head https://github.com/erlef/otp_builds/releases/latest | grep -i '^location:' | awk '{print $2}' | tr -d '\r\n') + tag=$(basename "$url") + otp_version="${tag#OTP-}" + fi + + if [ "${elixir_version}" = latest ]; then + url=$(curl -fsS --head https://github.com/elixir-lang/elixir/releases/latest | grep -i '^location:' | awk '{print $2}' | tr -d '\r\n') + tag=$(basename "$url") + elixir_version="${tag#v}" + fi + + case "${otp_version}" in + master|maint*) + branch_version=$(curl -fsS https://raw.githubusercontent.com/erlang/otp/refs/heads/${otp_version}/OTP_VERSION | tr -d '\n') + elixir_otp_release="${branch_version%%.*}" + ;; + *) + elixir_otp_release="${otp_version%%.*}" + ;; + esac + + case "$elixir_version" in + 1.14.*) + [ "${elixir_otp_release}" -ge 25 ] && elixir_otp_release=25 + ;; + 1.15.*|1.16.*) + [ "${elixir_otp_release}" -ge 26 ] && elixir_otp_release=26 + ;; + *) + [ "${elixir_otp_release}" -ge 27 ] && elixir_otp_release=27 + ;; + esac + + otp_dir="$root_dir/installs/otp/$otp_version" + elixir_dir="${root_dir}/installs/elixir/${elixir_version}-otp-${elixir_otp_release}" + + install_otp & + install_elixir & + wait + + printf "checking OTP... " + export PATH="$otp_dir/bin:$PATH" + erl -noshell -eval 'io:put_chars(erlang:system_info(otp_release) ++ " ok\n"), halt().' + + printf "checking Elixir... " + "$elixir_dir/bin/elixir" -e 'IO.puts(System.version() <> " ok")' + + export PATH="$elixir_dir/bin:$PATH" +cat< Date: Thu, 31 Oct 2024 12:05:43 +0100 Subject: [PATCH 2/5] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: José Valim --- install.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.markdown b/install.markdown index 9cfd588fa..b247ef824 100644 --- a/install.markdown +++ b/install.markdown @@ -10,7 +10,7 @@ image: /images/social/elixir-og-card.jpg {% include toc.html %} -The quickest way to install Elixir is through install script, operating system package manager, or using one of the available installers. If such an option is not available, then we recommend using the precompiled packages or compiling the language yourself. All of these options are detailed next. +The quickest way to install Elixir is through install scripts, operating system package manager, or using one of the available installers. If such an option is not available, then we recommend using the precompiled packages or compiling the language yourself. All of these options are detailed next. Note that Elixir {{ stable.name }} requires Erlang {{ stable.minimum_otp }} or later. Many of the instructions below will automatically install Erlang for you. If they do not, the "Installing Erlang" section has you covered. From 42714d14f010e7703c6da0153d39eaf9adaca168 Mon Sep 17 00:00:00 2001 From: Wojtek Mach Date: Thu, 31 Oct 2024 12:15:36 +0100 Subject: [PATCH 3/5] Updates --- _data/elixir-versions.yml | 1 + install.bat | 4 ++-- install.markdown | 26 ++++++++++++++------------ install.sh | 2 +- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/_data/elixir-versions.yml b/_data/elixir-versions.yml index 93d640300..f8a2d9538 100644 --- a/_data/elixir-versions.yml +++ b/_data/elixir-versions.yml @@ -3,6 +3,7 @@ stable: v1_17 v1_17: name: v1.17 minimum_otp: 25.0 + recommended_otp: 27.1.2 otp_versions: [27, 26, 25] version: 1.17.3 diff --git a/install.bat b/install.bat index 40e07428e..476b69e4d 100755 --- a/install.bat +++ b/install.bat @@ -15,8 +15,8 @@ echo Usage: install.bat [arguments] [options] echo. echo Arguments: echo. -echo elixir@VERSION Install specific version of Elixir -echo otp@VERSION Install specific version of Erlang/OTP +echo elixir@VERSION Install specific Elixir version. The version can be X.Y.Z, latest, or main +echo otp@VERSION Install specific Erlang/OTP version. The version can be X.Y.Z or latest echo. echo By default, elixir@latest and otp@latest are installed. echo. diff --git a/install.markdown b/install.markdown index b247ef824..4a23f18fb 100644 --- a/install.markdown +++ b/install.markdown @@ -22,24 +22,26 @@ Elixir and Erlang/OTP can be quickly installed for macOS, Windows, or Ubuntu usi If you are using bash (macOS/Ubuntu/Windows), run: +{{ assign stable = site.data.elixir-versions[site.data.elixir-versions.stable] }} + ```sh -$ curl -fsSO {{ site.url }}/install.sh -$ sh install.sh elixir@1.17.3 otp@27.1.2 -$ installs_dir=$HOME/.elixir-install/installs -$ export PATH=$installs_dir/otp/27.1.2/bin:$PATH -$ export PATH=$installs_dir/elixir/1.17.3-otp-27/bin:$PATH -$ iex +curl -fsSO {{ site.url }}/install.sh +sh install.sh elixir@{{ stable.version }} otp@{{ stable.recommended_otp }} +installs_dir=$HOME/.elixir-install/installs +export PATH=$installs_dir/otp/{{ stable.recommended_otp }}/bin:$PATH +export PATH=$installs_dir/elixir/{{ stable.version }}-otp-{{ stable.otp_versions[0] }}/bin:$PATH +iex ``` If you are using PowerShell (Windows), run: ```pwsh -> curl.exe -fsSO {{ site.url }}/install.bat -> .\install.bat elixir@1.17.3 otp@27.1.2 -> $installs_dir = "$env:USERPROFILE\.elixir-install\installs" -> $env:PATH = "$installs_dir\otp\27.1.2\bin;$env:PATH" -> $env:PATH = "$installs_dir\elixir\1.17.3-otp-27\bin;$env:PATH" -> iex.bat +curl.exe -fsSO {{ site.url }}/install.bat +.\install.bat elixir@{{ stable.version }} otp@{{ stable.recommended_otp }} +$installs_dir = "$env:USERPROFILE\.elixir-install\installs" +$env:PATH = "$installs_dir\otp\{{ stable.recommended_otp }}\bin;$env:PATH" +$env:PATH = "$installs_dir\elixir\{{ stable.version }}-otp-{{ stable.otp_versions[0] }}\bin;$env:PATH" +iex.bat ``` Use `install.sh --help` or `install.bat --help` to learn more about available arguments and options. diff --git a/install.sh b/install.sh index 5599a92a4..e1a56160a 100755 --- a/install.sh +++ b/install.sh @@ -112,7 +112,7 @@ main() { export PATH="$elixir_dir/bin:$PATH" cat< Date: Thu, 31 Oct 2024 12:22:33 +0100 Subject: [PATCH 4/5] up --- install.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index e1a56160a..46e52d6b6 100755 --- a/install.sh +++ b/install.sh @@ -14,8 +14,9 @@ Usage: install.sh [arguments] [options] Arguments: - elixir@VERSION Install specific Elixir version - otp@VERSION Install specific Erlang/OTP version + elixir@VERSION Install specific Elixir version. The version can be X.Y.Z, latest, or main + otp@VERSION Install specific Erlang/OTP version. The version can be X.Y.Z, latest, + master, maint, or maint-RELEASE (e.g. maint-27) By default, elixir@latest and otp@latest are installed. From fd348c4383618310e60d6056cbe90d5673b74595 Mon Sep 17 00:00:00 2001 From: Wojtek Mach Date: Thu, 31 Oct 2024 12:25:41 +0100 Subject: [PATCH 5/5] up --- install.markdown | 2 -- 1 file changed, 2 deletions(-) diff --git a/install.markdown b/install.markdown index 4a23f18fb..b168c92d0 100644 --- a/install.markdown +++ b/install.markdown @@ -22,8 +22,6 @@ Elixir and Erlang/OTP can be quickly installed for macOS, Windows, or Ubuntu usi If you are using bash (macOS/Ubuntu/Windows), run: -{{ assign stable = site.data.elixir-versions[site.data.elixir-versions.stable] }} - ```sh curl -fsSO {{ site.url }}/install.sh sh install.sh elixir@{{ stable.version }} otp@{{ stable.recommended_otp }}