|
| 1 | +@ECHO OFF |
| 2 | + |
| 3 | +SETLOCAL |
| 4 | + |
| 5 | +SET dlurl=https://github.com/HL7/fhir-ig-publisher/releases/latest/download/publisher.jar |
| 6 | +SET publisher_jar=publisher.jar |
| 7 | +SET input_cache_path=%CD%\input-cache\ |
| 8 | +SET skipPrompts=false |
| 9 | + |
| 10 | +SET scriptdlroot=https://raw.githubusercontent.com/HL7/ig-publisher-scripts/main |
| 11 | +SET update_bat_url=%scriptdlroot%/_updatePublisher.bat |
| 12 | +SET gen_bat_url=%scriptdlroot%/_genonce.bat |
| 13 | +SET gencont_bat_url=%scriptdlroot%/_gencontinuous.bat |
| 14 | +SET gencont_sh_url=%scriptdlroot%/_gencontinuous.sh |
| 15 | +SET gen_sh_url=%scriptdlroot%/_genonce.sh |
| 16 | +SET update_sh_url=%scriptdlroot%/_updatePublisher.sh |
| 17 | + |
| 18 | +IF "%~1"=="/f" SET skipPrompts=y |
| 19 | + |
| 20 | + |
| 21 | +ECHO. |
| 22 | +ECHO Checking internet connection... |
| 23 | +PING tx.fhir.org -4 -n 1 -w 1000 | FINDSTR TTL && GOTO isonline |
| 24 | +ECHO We're offline, nothing to do... |
| 25 | +GOTO end |
| 26 | + |
| 27 | +:isonline |
| 28 | +ECHO We're online |
| 29 | + |
| 30 | + |
| 31 | +:processflags |
| 32 | +SET ARG=%1 |
| 33 | +IF DEFINED ARG ( |
| 34 | + IF "%ARG%"=="-f" SET FORCE=true |
| 35 | + IF "%ARG%"=="--force" SET FORCE=true |
| 36 | + SHIFT |
| 37 | + GOTO processflags |
| 38 | +) |
| 39 | + |
| 40 | +FOR %%x IN ("%CD%") DO SET upper_path=%%~dpx |
| 41 | + |
| 42 | +ECHO. |
| 43 | +IF NOT EXIST "%input_cache_path%%publisher_jar%" ( |
| 44 | + IF NOT EXIST "%upper_path%%publisher_jar%" ( |
| 45 | + SET jarlocation="%input_cache_path%%publisher_jar%" |
| 46 | + SET jarlocationname=Input Cache |
| 47 | + ECHO IG Publisher is not yet in input-cache or parent folder. |
| 48 | + REM we don't use jarlocation below because it will be empty because we're in a bracketed if statement |
| 49 | + GOTO create |
| 50 | + ) ELSE ( |
| 51 | + ECHO IG Publisher FOUND in parent folder |
| 52 | + SET jarlocation="%upper_path%%publisher_jar%" |
| 53 | + SET jarlocationname=Parent folder |
| 54 | + GOTO upgrade |
| 55 | + ) |
| 56 | +) ELSE ( |
| 57 | + ECHO IG Publisher FOUND in input-cache |
| 58 | + SET jarlocation="%input_cache_path%%publisher_jar%" |
| 59 | + SET jarlocationname=Input Cache |
| 60 | + GOTO upgrade |
| 61 | +) |
| 62 | + |
| 63 | +:create |
| 64 | +IF DEFINED FORCE ( |
| 65 | + MKDIR "%input_cache_path%" 2> NUL |
| 66 | + GOTO download |
| 67 | +) |
| 68 | + |
| 69 | +IF "%skipPrompts%"=="y" ( |
| 70 | + SET create=Y |
| 71 | +) ELSE ( |
| 72 | + SET /p create="Ok? (Y/N) " |
| 73 | +) |
| 74 | +IF /I "%create%"=="Y" ( |
| 75 | + ECHO Will place publisher jar here: %input_cache_path%%publisher_jar% |
| 76 | + MKDIR "%input_cache_path%" 2> NUL |
| 77 | + GOTO download |
| 78 | +) |
| 79 | +GOTO done |
| 80 | + |
| 81 | +:upgrade |
| 82 | +IF "%skipPrompts%"=="y" ( |
| 83 | + SET overwrite=Y |
| 84 | +) ELSE ( |
| 85 | + SET /p overwrite="Overwrite %jarlocation%? (Y/N) " |
| 86 | +) |
| 87 | + |
| 88 | +IF /I "%overwrite%"=="Y" ( |
| 89 | + GOTO download |
| 90 | +) |
| 91 | +GOTO done |
| 92 | + |
| 93 | +:download |
| 94 | +ECHO Downloading most recent publisher to %jarlocationname% - it's ~100 MB, so this may take a bit |
| 95 | + |
| 96 | +FOR /f "tokens=4-5 delims=. " %%i IN ('ver') DO SET VERSION=%%i.%%j |
| 97 | +IF "%version%" == "10.0" GOTO win10 |
| 98 | +IF "%version%" == "6.3" GOTO win8.1 |
| 99 | +IF "%version%" == "6.2" GOTO win8 |
| 100 | +IF "%version%" == "6.1" GOTO win7 |
| 101 | +IF "%version%" == "6.0" GOTO vista |
| 102 | + |
| 103 | +ECHO Unrecognized version: %version% |
| 104 | +GOTO done |
| 105 | + |
| 106 | +:win10 |
| 107 | +CALL POWERSHELL -command if ('System.Net.WebClient' -as [type]) {(new-object System.Net.WebClient).DownloadFile(\"%dlurl%\",\"%jarlocation%\") } else { Invoke-WebRequest -Uri "%dlurl%" -Outfile "%jarlocation%" } |
| 108 | + |
| 109 | +GOTO done |
| 110 | + |
| 111 | +:win7 |
| 112 | +rem this may be triggering the antivirus - bitsadmin.exe is a known threat |
| 113 | +rem CALL bitsadmin /transfer GetPublisher /download /priority normal "%dlurl%" "%jarlocation%" |
| 114 | + |
| 115 | +rem this didn't work in win 10 |
| 116 | +rem CALL Start-BitsTransfer /priority normal "%dlurl%" "%jarlocation%" |
| 117 | + |
| 118 | +rem this should work - untested |
| 119 | +call (New-Object Net.WebClient).DownloadFile('%dlurl%', '%jarlocation%') |
| 120 | +GOTO done |
| 121 | + |
| 122 | +:win8.1 |
| 123 | +:win8 |
| 124 | +:vista |
| 125 | +GOTO done |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | +:done |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | +ECHO. |
| 135 | +ECHO Updating scripts |
| 136 | +IF "%skipPrompts%"=="y" ( |
| 137 | + SET updateScripts=Y |
| 138 | +) ELSE ( |
| 139 | + SET /p updateScripts="Update scripts? (Y/N) " |
| 140 | +) |
| 141 | +IF /I "%updateScripts%"=="Y" ( |
| 142 | + GOTO scripts |
| 143 | +) |
| 144 | +GOTO end |
| 145 | + |
| 146 | + |
| 147 | +:scripts |
| 148 | + |
| 149 | +REM Download all batch files (and this one with a new name) |
| 150 | + |
| 151 | +SETLOCAL DisableDelayedExpansion |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | +:dl_script_1 |
| 156 | +ECHO Updating _updatePublisher.sh |
| 157 | +call POWERSHELL -command if ('System.Net.WebClient' -as [type]) {(new-object System.Net.WebClient).DownloadFile(\"%update_sh_url%\",\"_updatePublisher.new.sh\") } else { Invoke-WebRequest -Uri "%update_sh_url%" -Outfile "_updatePublisher.new.sh" } |
| 158 | +if %ERRORLEVEL% == 0 goto upd_script_1 |
| 159 | +echo "Errors encountered during download: %errorlevel%" |
| 160 | +goto dl_script_2 |
| 161 | +:upd_script_1 |
| 162 | +start copy /y "_updatePublisher.new.sh" "_updatePublisher.sh" ^&^& del "_updatePublisher.new.sh" ^&^& exit |
| 163 | + |
| 164 | + |
| 165 | +:dl_script_2 |
| 166 | +ECHO Updating _genonce.bat |
| 167 | +call POWERSHELL -command if ('System.Net.WebClient' -as [type]) {(new-object System.Net.WebClient).DownloadFile(\"%gen_bat_url%\",\"_genonce.new.bat\") } else { Invoke-WebRequest -Uri "%gen_bat_url%" -Outfile "_genonce.bat" } |
| 168 | +if %ERRORLEVEL% == 0 goto upd_script_2 |
| 169 | +echo "Errors encountered during download: %errorlevel%" |
| 170 | +goto dl_script_3 |
| 171 | +:upd_script_2 |
| 172 | +start copy /y "_genonce.new.bat" "_genonce.bat" ^&^& del "_genonce.new.bat" ^&^& exit |
| 173 | + |
| 174 | +:dl_script_3 |
| 175 | +ECHO Updating _gencontinuous.bat |
| 176 | +call POWERSHELL -command if ('System.Net.WebClient' -as [type]) {(new-object System.Net.WebClient).DownloadFile(\"%gencont_bat_url%\",\"_gencontinuous.new.bat\") } else { Invoke-WebRequest -Uri "%gencont_bat_url%" -Outfile "_gencontinuous.bat" } |
| 177 | +if %ERRORLEVEL% == 0 goto upd_script_3 |
| 178 | +echo "Errors encountered during download: %errorlevel%" |
| 179 | +goto dl_script_4 |
| 180 | +:upd_script_3 |
| 181 | +start copy /y "_gencontinuous.new.bat" "_gencontinuous.bat" ^&^& del "_gencontinuous.new.bat" ^&^& exit |
| 182 | + |
| 183 | + |
| 184 | +:dl_script_4 |
| 185 | +ECHO Updating _genonce.sh |
| 186 | +call POWERSHELL -command if ('System.Net.WebClient' -as [type]) {(new-object System.Net.WebClient).DownloadFile(\"%gen_sh_url%\",\"_genonce.new.sh\") } else { Invoke-WebRequest -Uri "%gen_sh_url%" -Outfile "_genonce.sh" } |
| 187 | +if %ERRORLEVEL% == 0 goto upd_script_4 |
| 188 | +echo "Errors encountered during download: %errorlevel%" |
| 189 | +goto dl_script_5 |
| 190 | +:upd_script_4 |
| 191 | +start copy /y "_genonce.new.sh" "_genonce.sh" ^&^& del "_genonce.new.sh" ^&^& exit |
| 192 | + |
| 193 | +:dl_script_5 |
| 194 | +ECHO Updating _gencontinuous.sh |
| 195 | +call POWERSHELL -command if ('System.Net.WebClient' -as [type]) {(new-object System.Net.WebClient).DownloadFile(\"%gencont_sh_url%\",\"_gencontinuous.new.sh\") } else { Invoke-WebRequest -Uri "%gencont_sh_url%" -Outfile "_gencontinuous.sh" } |
| 196 | +if %ERRORLEVEL% == 0 goto upd_script_5 |
| 197 | +echo "Errors encountered during download: %errorlevel%" |
| 198 | +goto dl_script_6 |
| 199 | +:upd_script_5 |
| 200 | +start copy /y "_gencontinuous.new.sh" "_gencontinuous.sh" ^&^& del "_gencontinuous.new.sh" ^&^& exit |
| 201 | + |
| 202 | + |
| 203 | + |
| 204 | +:dl_script_6 |
| 205 | +ECHO Updating _updatePublisher.bat |
| 206 | +call POWERSHELL -command if ('System.Net.WebClient' -as [type]) {(new-object System.Net.WebClient).DownloadFile(\"%update_bat_url%\",\"_updatePublisher.new.bat\") } else { Invoke-WebRequest -Uri "%update_bat_url%" -Outfile "_updatePublisher.new.bat" } |
| 207 | +if %ERRORLEVEL% == 0 goto upd_script_6 |
| 208 | +echo "Errors encountered during download: %errorlevel%" |
| 209 | +goto end |
| 210 | +:upd_script_6 |
| 211 | +start copy /y "_updatePublisher.new.bat" "_updatePublisher.bat" ^&^& del "_updatePublisher.new.bat" ^&^& exit |
| 212 | + |
| 213 | + |
| 214 | +:end |
| 215 | + |
| 216 | + |
| 217 | +IF "%skipPrompts%"=="true" ( |
| 218 | + PAUSE |
| 219 | +) |
0 commit comments