|
| 1 | +#!/bin/bash |
| 2 | +pubsource=https://github.com/HL7/fhir-ig-publisher/releases/latest/download/ |
| 3 | +publisher_jar=publisher.jar |
| 4 | +dlurl=$pubsource$publisher_jar |
| 5 | + |
| 6 | +input_cache_path=$PWD/input-cache/ |
| 7 | + |
| 8 | +scriptdlroot=https://raw.githubusercontent.com/HL7/ig-publisher-scripts/main |
| 9 | +update_bat_url=$scriptdlroot/_updatePublisher.bat |
| 10 | +gen_bat_url=$scriptdlroot/_genonce.bat |
| 11 | +gencont_bat_url=$scriptdlroot/_gencontinuous.bat |
| 12 | +gencont_sh_url=$scriptdlroot/_gencontinuous.sh |
| 13 | +gen_sh_url=$scriptdlroot/_genonce.sh |
| 14 | +update_sh_url=$scriptdlroot/_updatePublisher.sh |
| 15 | + |
| 16 | +skipPrompts=false |
| 17 | +FORCE=false |
| 18 | + |
| 19 | +if ! type "curl" > /dev/null; then |
| 20 | + echo "ERROR: Script needs curl to download latest IG Publisher. Please install curl." |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +while [ "$#" -gt 0 ]; do |
| 25 | + case $1 in |
| 26 | + -f|--force) FORCE=true ;; |
| 27 | + -y|--yes) skipPrompts=true ; FORCE=true ;; |
| 28 | + *) echo "Unknown parameter passed: $1. Exiting"; exit 1 ;; |
| 29 | + esac |
| 30 | + shift |
| 31 | +done |
| 32 | + |
| 33 | +echo "Checking internet connection" |
| 34 | +curl -sSf tx.fhir.org > /dev/null |
| 35 | + |
| 36 | +if [ $? -ne 0 ] ; then |
| 37 | + echo "Offline (or the terminology server is down), unable to update. Exiting" |
| 38 | + exit 1 |
| 39 | +fi |
| 40 | + |
| 41 | +if [ ! -d "$input_cache_path" ] ; then |
| 42 | + if [ $FORCE != true ]; then |
| 43 | + echo "$input_cache_path does not exist" |
| 44 | + message="create it?" |
| 45 | + read -r -p "$message" response |
| 46 | + else |
| 47 | + response=y |
| 48 | + fi |
| 49 | +fi |
| 50 | + |
| 51 | +if [[ $response =~ ^[yY].*$ ]] ; then |
| 52 | + mkdir ./input-cache |
| 53 | +fi |
| 54 | + |
| 55 | +publisher="$input_cache_path$publisher_jar" |
| 56 | + |
| 57 | +if test -f "$publisher" ; then |
| 58 | + echo "IG Publisher FOUND in input-cache" |
| 59 | + jarlocation="$publisher" |
| 60 | + jarlocationname="Input Cache" |
| 61 | + upgrade=true |
| 62 | +else |
| 63 | + publisher="../$publisher_jar" |
| 64 | + upgrade=true |
| 65 | + if test -f "$publisher"; then |
| 66 | + echo "IG Publisher FOUND in parent folder" |
| 67 | + jarlocation="$publisher" |
| 68 | + jarlocationname="Parent Folder" |
| 69 | + upgrade=true |
| 70 | + else |
| 71 | + echo "IG Publisher NOT FOUND in input-cache or parent folder" |
| 72 | + jarlocation=$input_cache_path$publisher_jar |
| 73 | + jarlocationname="Input Cache" |
| 74 | + upgrade=false |
| 75 | + fi |
| 76 | +fi |
| 77 | + |
| 78 | +if [[ $skipPrompts == false ]]; then |
| 79 | + |
| 80 | + if [[ $upgrade == true ]]; then |
| 81 | + message="Overwrite $jarlocation? (Y/N) " |
| 82 | + else |
| 83 | + echo Will place publisher jar here: "$jarlocation" |
| 84 | + message="Ok (enter 'y' or 'Y' to continue, any other key to cancel)?" |
| 85 | + fi |
| 86 | + read -r -p "$message" response |
| 87 | +else |
| 88 | + response=y |
| 89 | +fi |
| 90 | +if [[ $skipPrompts == true ]] || [[ $response =~ ^[yY].*$ ]]; then |
| 91 | + |
| 92 | + echo "Downloading most recent publisher to $jarlocationname - it's ~100 MB, so this may take a bit" |
| 93 | + curl -L $dlurl -o "$jarlocation" --create-dirs |
| 94 | +else |
| 95 | + echo cancelled publisher update |
| 96 | +fi |
| 97 | + |
| 98 | +if [[ $skipPrompts != true ]]; then |
| 99 | + message="Update scripts? (enter 'y' or 'Y' to continue, any other key to cancel)?" |
| 100 | + read -r -p "$message" response |
| 101 | + fi |
| 102 | + |
| 103 | +if [[ $skipPrompts == true ]] || [[ $response =~ ^[yY].*$ ]]; then |
| 104 | + echo "Downloading most recent scripts " |
| 105 | + |
| 106 | + curl -L $update_bat_url -o /tmp/_updatePublisher.new |
| 107 | + cp /tmp/_updatePublisher.new _updatePublisher.bat |
| 108 | + rm /tmp/_updatePublisher.new |
| 109 | + |
| 110 | + curl -L $gen_bat_url -o /tmp/_genonce.new |
| 111 | + cp /tmp/_genonce.new _genonce.bat |
| 112 | + rm /tmp/_genonce.new |
| 113 | + |
| 114 | + curl -L $gencont_bat_url -o /tmp/_gencontinuous.new |
| 115 | + cp /tmp/_gencontinuous.new _gencontinuous.bat |
| 116 | + rm /tmp/_gencontinuous.new |
| 117 | + |
| 118 | + curl -L $gencont_sh_url -o /tmp/_gencontinuous.new |
| 119 | + cp /tmp/_gencontinuous.new _gencontinuous.sh |
| 120 | + rm /tmp/_gencontinuous.new |
| 121 | + |
| 122 | + curl -L $gen_sh_url -o /tmp/_genonce.new |
| 123 | + cp /tmp/_genonce.new _genonce.sh |
| 124 | + rm /tmp/_genonce.new |
| 125 | + |
| 126 | + curl -L $update_sh_url -o /tmp/_updatePublisher.new |
| 127 | + cp /tmp/_updatePublisher.new _updatePublisher.sh |
| 128 | + rm /tmp/_updatePublisher.new |
| 129 | +fi |
0 commit comments