-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.bat
95 lines (68 loc) · 2.85 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
@echo off
SETLOCAL
:: Log file
SET ORIGIN=%cd%
call :joinpath "%ORIGIN%" "chi2comb_install.log"
SET LOG_FILE=%Result%
:: Configuration
set VERSION_URL=https://raw.githubusercontent.com/limix/chi2comb/master/VERSION
call :winget "%VERSION_URL%" >>%LOG_FILE% 2>&1
set /p VERSION=<VERSION && del VERSION
set FILE=chi2comb-%VERSION%.zip
set DIR=chi2comb-%VERSION%
set URL=https://github.com/limix/chi2comb/archive/%VERSION%.zip
IF "%ARCH%"=="" set ARCH=x64
IF "%CHI2COMB_INSTALL_PREFIX%"=="" (
set install_prefix_opt=-DCMAKE_INSTALL_PREFIX="%programfiles%\chi2comb"
) else (
echo Using environment variable CHI2COMB_INSTALL_PREFIX.
set install_prefix_opt=-DCMAKE_INSTALL_PREFIX=%CHI2COMB_INSTALL_PREFIX%
)
echo [0/4] Library(chi2comb==%VERSION%)
:: Cleaning up previous mess
del /Q %FILE% ! >nul 2>&1
rd /S /Q %DIR% >nul 2>&1
del /Q %LOG_FILE% ! >nul 2>&1
copy /y nul %LOG_FILE% >nul 2>&1
echo|set /p="[1/4] Downloading... "
echo Fetching %URL% >>%LOG_FILE% 2>&1
call :winget "%URL%" >>%LOG_FILE% 2>&1
if %ERRORLEVEL% NEQ 0 (echo FAILED. && type %LOG_FILE% && exit /B 1) else (echo done.)
echo|set /p="[2/4] Extracting... "
powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('%FILE%', '.'); }"
if %ERRORLEVEL% NEQ 0 (echo FAILED. && type %LOG_FILE% && exit /B 1) else (echo done.)
cd %DIR% && mkdir build && cd build
echo|set /p="[3/4] Configuring... "
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR_PLATFORM=%ARCH% %install_prefix_opt% >>%LOG_FILE% 2>&1
if %ERRORLEVEL% NEQ 0 (echo FAILED. && type %LOG_FILE% && exit /B 1) else (echo done.)
echo|set /p="[4/4] Compiling and installing... "
cmake --build . --config Release --target install >>%LOG_FILE% 2>&1
if %ERRORLEVEL% NEQ 0 (echo FAILED. && type %LOG_FILE% && exit /B 1) else (echo done.)
cd %ORIGIN% >nul 2>&1
del /Q %FILE% >nul 2>&1
rd /S /Q %DIR% >nul 2>&1
echo Details can be found at %LOG_FILE%.
@echo on
@goto :eof
:joinpath
set Path1=%~1
set Path2=%~2
if {%Path1:~-1,1%}=={\} (set Result=%Path1%%Path2%) else (set Result=%Path1%\%Path2%)
goto :eof
:winget - download file given url
set URL=%~1
for %%F in (%URL%) do set FILE=%%~nxF
setlocal EnableDelayedExpansion
set multiLine=$security_protcols = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::SystemDefault^
if ([Net.SecurityProtocolType].GetMember('Tls11').Count -gt 0) {^
$security_protcols = $security_protcols -bor [Net.SecurityProtocolType]::Tls11^
}^
if ([Net.SecurityProtocolType].GetMember('Tls12').Count -gt 0) {^
$security_protcols = $security_protcols -bor [Net.SecurityProtocolType]::Tls12^
}^
[Net.ServicePointManager]::SecurityProtocol = $security_protcols^
Write-Host 'Downloading %URL%... ' -NoNewLine^
(New-Object Net.WebClient).DownloadFile('%URL%', '%FILE%')^
Write-Host 'done.'
powershell -Command !multiLine!
goto:eof