-
Notifications
You must be signed in to change notification settings - Fork 824
/
install.bat
executable file
·172 lines (145 loc) · 4.9 KB
/
install.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
@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="
set "elixir_version="
set "force=false"
goto :main
:usage
echo Usage: install.bat elixir@ELIXIR_VERSION otp@OTP_VERSION [options]
echo.
echo ELIXIR_VERSION can be X.Y.Z, latest, or main.
echo OTP_VERSION can be X.Y.Z or latest.
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 [email protected] [email protected]
echo install.bat elixir@latest otp@latest
echo install.bat elixir@main otp@latest
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 "%elixir_version%" == "" (
call :usage
echo error: missing elixir@VERSION argument
exit /b 1
)
if "%otp_version%" == "" (
call :usage
echo error: missing otp@VERSION argument
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... "<nul
set "PATH=%otp_dir%\bin;%PATH%"
"%otp_dir%\bin\erl.exe" -noshell -eval "io:put_chars(erlang:system_info(otp_release) ++ "" ok\n""), halt()."
call :install_elixir
if %errorlevel% neq 0 exit /b 1
set /p="checking Elixir... "<nul
call "%elixir_dir%\bin\elixir.bat" -e "IO.write(System.version())"
echo. ok
echo.
echo If you are using powershell, run this (or add to your $PROFILE):
echo.
echo $env:PATH = "$env:USERPROFILE\.elixir-install\installs\otp\!otp_version!\bin;$env:PATH"
echo $env:PATH = "$env:USERPROFILE\.elixir-install\installs\elixir\!elixir_version!-otp-%elixir_otp_release%\bin;$env:PATH"
echo.
echo If you are using cmd, run this:
echo.
echo set PATH=%%USERPROFILE%%\.elixir-install\installs\otp\!otp_version!\bin;%%PATH%%
echo set PATH=%%USERPROFILE%%\.elixir-install\installs\elixir\!elixir_version!-otp-%elixir_otp_release%\bin;%%PATH%%
echo.
goto :eof
:install_otp
set "otp_zip=otp_win64_%otp_version%.zip"
if "%force%" == "true" (
if exist "%otp_dir%" (
rmdir /s /q "%otp_dir%"
)
)
if not exist "%otp_dir%\bin" (
if exist "%otp_dir%" (
rmdir /s /q "%otp_dir%"
)
set otp_url=https://github.com/erlang/otp/releases/download/OTP-!otp_version!/%otp_zip%
echo downloading !otp_url!...
curl.exe -fsSLo %tmp_dir%\%otp_zip% "!otp_url!" || exit /b 1
echo unpacking %tmp_dir%\%otp_zip%
powershell -Command "Expand-Archive -LiteralPath %tmp_dir%\%otp_zip% -DestinationPath %otp_dir%"
del /f /q "%tmp_dir%\%otp_zip%"
cd /d "%otp_dir%"
if not exist "c:\windows\system32\vcruntime140.dll" (
echo Installing VC++ Redistributable...
.\vc_redist.exe /quiet /norestart
)
)
exit /b 0
goto :eof
:install_elixir
set "elixir_zip=elixir-!elixir_version!-otp-!elixir_otp_release!.zip"
if "%force%" == "true" (
if exist "%elixir_dir%" (
rmdir /s /q "%elixir_dir%"
)
)
if not exist "%elixir_dir%\bin" (
set "elixir_url=https://github.com/elixir-lang/elixir/releases/download/v!elixir_version!/elixir-otp-%elixir_otp_release%.zip"
echo downloading !elixir_url!...
curl.exe -fsSLo "%tmp_dir%\%elixir_zip%" "!elixir_url!" || exit /b 1
echo unpacking %tmp_dir%\%elixir_zip%
powershell -Command "Expand-Archive -LiteralPath %tmp_dir%\%elixir_zip% -DestinationPath %elixir_dir%"
del /f /q %tmp_dir%\%elixir_zip%
)
goto :eof