-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.cmd
60 lines (54 loc) · 1.6 KB
/
update.cmd
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
@echo off
cd %~dp0
echo Finding latest version...
call generic\github-find-latest-artifact.cmd syncthing syncthing "syncthing-windows-amd64"
if %errorlevel% NEQ 0 call :fail-with-errormessage "Unable to find latest version of Syncthing!"
goto found
:found
echo - found: %ARTIFACT_TAGNAME%
if exist syncthing\version.txt set /p current-version=<syncthing\version.txt
call :trim current-version %current-version%
if "%current-version%" NEQ "%ARTIFACT_TAGNAME%" goto check-running
echo.
echo Latest version already installed !
echo.
exit /b 0
:check-running
echo Check if already running...
set was-running=0
call generic\is-executable-running.cmd syncthing.exe
if %errorlevel% == 1 goto update
if %errorlevel% == 2 call :fail-with-errormessage "Unable to test if Syncthing is running!"
call stop.cmd
:check-again
timeout /T 1 /NOBREAK > nul
call generic\is-executable-running.cmd syncthing.exe
if %errorlevel% == 0 goto check-again
set was-running=1
goto update
:update
if exist syncthing (
echo Removing old version...
rmdir /s /q syncthing
)
echo Downloading %ARTIFACT_URL%...
curl -kOL %ARTIFACT_URL%
echo Extracting...
mkdir syncthing
tar -xf %ARTIFACT_FILENAME% -C syncthing --strip-components=1
echo %ARTIFACT_TAGNAME% >syncthing\version.txt
if exist %ARTIFACT_FILENAME% del /f /q %ARTIFACT_FILENAME%
if %was-running% == 1 call start.cmd
echo.
echo Updated to %ARTIFACT_TAGNAME% !
echo.
exit /b 0
:fail-with-errormessage
echo.
echo ERROR: %~1
echo.
exit /b 1
:trim
setlocal enabledelayedexpansion
for /f "tokens=1*" %%a in ("%*") do endlocal & set %1=%%b
goto :eof