|
| 1 | +@echo off |
| 2 | +REM See latest version at: |
| 3 | +REM https://github.com/elixir-lang/elixir-lang.github.com/blob/main/install.bat |
| 4 | + |
| 5 | +setlocal EnableDelayedExpansion |
| 6 | + |
| 7 | +set "otp_version=latest" |
| 8 | +set "elixir_version=latest" |
| 9 | +set "force=false" |
| 10 | + |
| 11 | +goto :main |
| 12 | + |
| 13 | +:usage |
| 14 | +echo Usage: install.bat [arguments] [options] |
| 15 | +echo. |
| 16 | +echo Arguments: |
| 17 | +echo. |
| 18 | +echo elixir@VERSION Install specific Elixir version. The version can be X.Y.Z, latest, or main |
| 19 | +echo otp@VERSION Install specific Erlang/OTP version. The version can be X.Y.Z or latest |
| 20 | +echo. |
| 21 | +echo By default, elixir@latest and otp@latest are installed. |
| 22 | +echo. |
| 23 | +echo Options: |
| 24 | +echo. |
| 25 | +echo -f, --force Forces installation even if it was previously installed |
| 26 | +echo -h, --help Prints this help |
| 27 | +echo. |
| 28 | +echo Examples: |
| 29 | +echo. |
| 30 | +echo install.bat |
| 31 | + |
| 32 | +echo install.bat elixir@main |
| 33 | +echo. |
| 34 | +goto :eof |
| 35 | + |
| 36 | +:main |
| 37 | +for %%i in (%*) do ( |
| 38 | + set arg=%%i |
| 39 | + |
| 40 | + if "!arg:~0,7!" == "elixir@" ( |
| 41 | + set "elixir_version=!arg:~7!" |
| 42 | + ) else if "!arg:~0,4!" == "otp@" ( |
| 43 | + set "otp_version=!arg:~4!" |
| 44 | + ) else if "!arg!" == "-f" ( |
| 45 | + set "force=true" |
| 46 | + ) else if "!arg!" == "--force" ( |
| 47 | + set "force=true" |
| 48 | + ) else if "!arg!" == "-h" ( |
| 49 | + call :usage |
| 50 | + exit /b 0 |
| 51 | + ) else if "!arg!" == "--help" ( |
| 52 | + call :usage |
| 53 | + exit /b 0 |
| 54 | + ) else ( |
| 55 | + echo error: unknown argument !arg! |
| 56 | + exit /b 1 |
| 57 | + ) |
| 58 | +) |
| 59 | + |
| 60 | +if "!otp_version!" == "latest" ( |
| 61 | + set "url=https://github.com/erlef/otp_builds/releases/latest" |
| 62 | + for /f "tokens=2 delims= " %%a in ('curl -fsS --head "!url!" ^| findstr /I "^location:"') do set url=%%a |
| 63 | + set "otp_version=!url:*releases/tag/OTP-=!" |
| 64 | +) |
| 65 | + |
| 66 | +if "!elixir_version!" == "latest" ( |
| 67 | + set "url=https://github.com/elixir-lang/elixir/releases/latest" |
| 68 | + for /f "tokens=2 delims= " %%a in ('curl -fsS --head "!url!" ^| findstr /I "^location:"') do set url=%%a |
| 69 | + set "elixir_version=!url:*releases/tag/v=!" |
| 70 | +) |
| 71 | + |
| 72 | +for /f "tokens=1 delims=." %%A in ("!otp_version!") do set "elixir_otp_release=%%A" |
| 73 | +for /f "tokens=1,2 delims=." %%A in ("!elixir_version!") do set "elixir_major_minor=%%A.%%B" |
| 74 | +if "%elixir_major_minor%" == "1.15" ( |
| 75 | + if %elixir_otp_release% GEQ 26 set "elixir_otp_release=26" |
| 76 | +) else if "%elixir_major_minor%" == "1.16" ( |
| 77 | + if %elixir_otp_release% GEQ 26 set "elixir_otp_release=26" |
| 78 | +) else if "%elixir_major_minor%" == "1.14" ( |
| 79 | + if %elixir_otp_release% GEQ 25 set "elixir_otp_release=25" |
| 80 | +) |
| 81 | + |
| 82 | +set "root_dir=%USERPROFILE%\.elixir-install" |
| 83 | +set "tmp_dir=%root_dir%\tmp" |
| 84 | +mkdir %tmp_dir% 2>nul |
| 85 | +set "otp_dir=%root_dir%\installs\otp\%otp_version%" |
| 86 | +set "elixir_dir=%root_dir%\installs\elixir\%elixir_version%-otp-%elixir_otp_release%" |
| 87 | + |
| 88 | +call :install_otp |
| 89 | +if %errorlevel% neq 0 exit /b 1 |
| 90 | + |
| 91 | +set /p="checking OTP... "<nul |
| 92 | +set "PATH=%otp_dir%\bin;%PATH%" |
| 93 | +"%otp_dir%\bin\erl.exe" -noshell -eval "io:put_chars(erlang:system_info(otp_release) ++ "" ok\n""), halt()." |
| 94 | + |
| 95 | +call :install_elixir |
| 96 | +if %errorlevel% neq 0 exit /b 1 |
| 97 | + |
| 98 | +set /p="checking Elixir... "<nul |
| 99 | +call "%elixir_dir%\bin\elixir.bat" -e "IO.write(System.version())" |
| 100 | +echo. ok |
| 101 | + |
| 102 | +echo. |
| 103 | +echo If you are using powershell, run this (or add to your $PROFILE): |
| 104 | +echo. |
| 105 | +echo $env:PATH = "$env:USERPROFILE\.elixir-install\installs\otp\!otp_version!\bin;$env:PATH" |
| 106 | +echo $env:PATH = "$env:USERPROFILE\.elixir-install\installs\elixir\!elixir_version!-otp-%elixir_otp_release%\bin;$env:PATH" |
| 107 | +echo. |
| 108 | +echo If you are using cmd, run this: |
| 109 | +echo. |
| 110 | +echo set PATH=%%USERPROFILE%%\.elixir-install\installs\otp\!otp_version!\bin;%%PATH%% |
| 111 | +echo set PATH=%%USERPROFILE%%\.elixir-install\installs\elixir\!elixir_version!-otp-%elixir_otp_release%\bin;%%PATH%% |
| 112 | +echo. |
| 113 | +goto :eof |
| 114 | + |
| 115 | +:install_otp |
| 116 | +set "otp_zip=otp_win64_%otp_version%.zip" |
| 117 | + |
| 118 | +if "%force%" == "true" ( |
| 119 | + if exist "%otp_dir%" ( |
| 120 | + rmdir /s /q "%otp_dir%" |
| 121 | + ) |
| 122 | +) |
| 123 | + |
| 124 | +if not exist "%otp_dir%\bin" ( |
| 125 | + if exist "%otp_dir%" ( |
| 126 | + rmdir /s /q "%otp_dir%" |
| 127 | + ) |
| 128 | + |
| 129 | + set otp_url=https://github.com/erlang/otp/releases/download/OTP-!otp_version!/%otp_zip% |
| 130 | + echo downloading !otp_url!... |
| 131 | + curl.exe -fsSLo %tmp_dir%\%otp_zip% "!otp_url!" || exit /b 1 |
| 132 | + |
| 133 | + echo unpacking %tmp_dir%\%otp_zip% |
| 134 | + powershell -Command "Expand-Archive -LiteralPath %tmp_dir%\%otp_zip% -DestinationPath %otp_dir%" |
| 135 | + del /f /q "%tmp_dir%\%otp_zip%" |
| 136 | + cd /d "%otp_dir%" |
| 137 | + |
| 138 | + if not exist "c:\windows\system32\vcruntime140.dll" ( |
| 139 | + echo Installing VC++ Redistributable... |
| 140 | + .\vc_redist.exe /quiet /norestart |
| 141 | + ) |
| 142 | +) |
| 143 | +exit /b 0 |
| 144 | +goto :eof |
| 145 | + |
| 146 | +:install_elixir |
| 147 | +set "elixir_zip=elixir-!elixir_version!-otp-!elixir_otp_release!.zip" |
| 148 | + |
| 149 | +if "%force%" == "true" ( |
| 150 | + if exist "%elixir_dir%" ( |
| 151 | + rmdir /s /q "%elixir_dir%" |
| 152 | + ) |
| 153 | +) |
| 154 | + |
| 155 | +if not exist "%elixir_dir%\bin" ( |
| 156 | + set "elixir_url=https://github.com/elixir-lang/elixir/releases/download/v!elixir_version!/elixir-otp-%elixir_otp_release%.zip" |
| 157 | + echo downloading !elixir_url!... |
| 158 | + curl.exe -fsSLo "%tmp_dir%\%elixir_zip%" "!elixir_url!" || exit /b 1 |
| 159 | + |
| 160 | + echo unpacking %tmp_dir%\%elixir_zip% |
| 161 | + powershell -Command "Expand-Archive -LiteralPath %tmp_dir%\%elixir_zip% -DestinationPath %elixir_dir%" |
| 162 | + del /f /q %tmp_dir%\%elixir_zip% |
| 163 | +) |
| 164 | +goto :eof |
0 commit comments