forked from HL7/ig-publisher-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_updatePublisher.bat
153 lines (116 loc) · 3.21 KB
/
_updatePublisher.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
@ECHO OFF
SETLOCAL
SET dlurl=https://github.com/HL7/fhir-ig-publisher/releases/latest/download/publisher.jar
SET publisher_jar=publisher.jar
SET scriptfolder=%~dp0
SET scriptfolder=%scriptfolder:~0,-1%
SET input_cache_path=%scriptfolder%\input-cache\
SET skipPrompts=false
IF "%~1"=="/f" SET skipPrompts=y
ECHO.
ECHO Checking internet connection...
PING tx.fhir.org -4 -n 1 -w 1000 | FINDSTR TTL && GOTO isonline
ECHO We're offline, nothing to do...
GOTO end
:isonline
ECHO We're online
:processflags
SET ARG=%1
IF DEFINED ARG (
IF "%ARG%"=="-f" SET FORCE=true
IF "%ARG%"=="--force" SET FORCE=true
SHIFT
GOTO processflags
)
FOR %%x IN ("%CD%") DO SET upper_path=%%~dpx
ECHO.
IF NOT EXIST "%input_cache_path%%publisher_jar%" (
IF NOT EXIST "%upper_path%%publisher_jar%" (
SET jarlocation="%input_cache_path%%publisher_jar%"
SET jarlocationname=Input Cache
ECHO IG Publisher is not yet in input-cache or parent folder.
REM we don't use jarlocation below because it will be empty because we're in a bracketed if statement
GOTO create
) ELSE (
ECHO IG Publisher FOUND in parent folder
SET jarlocation="%upper_path%%publisher_jar%"
SET jarlocationname=Parent folder
GOTO upgrade
)
) ELSE (
ECHO IG Publisher FOUND in input-cache
SET jarlocation="%input_cache_path%%publisher_jar%"
SET jarlocationname=Input Cache
GOTO upgrade
)
:create
IF DEFINED FORCE (
MKDIR "%input_cache_path%" 2> NUL
GOTO download
)
IF "%skipPrompts%"=="y" (
SET create=Y
) ELSE (
SET /p create="Ok? (Y/N) "
)
IF /I "%create%"=="Y" (
ECHO Will place publisher jar here: %input_cache_path%%publisher_jar%
MKDIR "%input_cache_path%" 2> NUL
GOTO download
)
GOTO done
:upgrade
IF "%skipPrompts%"=="y" (
SET overwrite=Y
) ELSE (
SET /p overwrite="Overwrite %jarlocation%? (Y/N) "
)
IF /I "%overwrite%"=="Y" (
GOTO download
)
GOTO done
:download
ECHO Downloading most recent publisher to %jarlocationname% - it's ~100 MB, so this may take a bit
FOR /f "tokens=4-5 delims=. " %%i IN ('ver') DO SET VERSION=%%i.%%j
IF "%version%" == "10.0" GOTO win10
IF "%version%" == "6.3" GOTO win8.1
IF "%version%" == "6.2" GOTO win8
IF "%version%" == "6.1" GOTO win7
IF "%version%" == "6.0" GOTO vista
ECHO Unrecognized version: %version%
GOTO done
:win10
CALL POWERSHELL -command if ('System.Net.WebClient' -as [type]) {(new-object System.Net.WebClient).DownloadFile(\"%dlurl%\",\"%jarlocation%\") } else { Invoke-WebRequest -Uri "%dlurl%" -Outfile "%jarlocation%" }
GOTO done
:win7
rem this may be triggering the antivirus - bitsadmin.exe is a known threat
rem CALL bitsadmin /transfer GetPublisher /download /priority normal "%dlurl%" "%jarlocation%"
rem this didn't work in win 10
rem CALL Start-BitsTransfer /priority normal "%dlurl%" "%jarlocation%"
rem this should work - untested
call (New-Object Net.WebClient).DownloadFile('%dlurl%', '%jarlocation%')
GOTO done
:win8.1
:win8
:vista
GOTO done
:done
ECHO.
ECHO Updating scripts
IF "%skipPrompts%"=="y" (
SET updateScripts=Y
) ELSE (
SET /p updateScripts="Update scripts? (Y/N) "
)
IF /I "%updateScripts%"=="Y" (
GOTO scripts
)
GOTO end
:scripts
REM Download all batch files (and this one with a new name)
SETLOCAL DisableDelayedExpansion
cd /d %scriptfolder%
git pull
IF "%skipPrompts%"=="true" (
PAUSE
)