BD-Core-FHIR-IG/_updatePublisher.sh
Carl Anderson 52e1448ba5
Follow 302 redirects with curl
I noticed that, after running this script, the jar file was only 144 bytes.  Running the commented-out `wget` command worked for me, so I re-ran the `curl` command with `-v`.  I noticed that the first response was a 302 redirect.  It seemed that `curl` needs an extra nudge to follow redirects.  Looking in the man page I found `-L`, which worked for me.
2020-07-01 16:26:59 -05:00

65 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
dlurl=https://github.com/HL7/fhir-ig-publisher/releases/latest/download/publisher.jar
publisher_jar=org.hl7.fhir.publisher.jar
input_cache_path=./input-cache/
set -e
if ! type "curl" > /dev/null; then
echo "ERROR: Script needs curl to download latest IG Publisher. Please install curl."
exit 1
fi
FORCE=false
while :; do
case $1 in
-f|--force) FORCE=true ;;
--)
shift
break
;;
*) break
esac
shift
done
publisher="$input_cache_path$publisher_jar"
if test -f "$publisher"; then
echo "IG Publisher FOUND in input-cache"
jarlocation="$publisher"
jarlocationname="Input Cache"
upgrade=true
else
publisher="../$publisher_jar"
upgrade=true
if test -f "$publisher"; then
echo "IG Publisher FOUND in parent folder"
jarlocation="$publisher"
jarlocationname="Parent Folder"
upgrade=true
else
echo IG Publisher NOT FOUND in input-cache or parent folder...
jarlocation=$input_cache_path$publisher_jar
jarlocationname="Input Cache"
upgrade=false
fi
fi
if [[ "$FORCE" != true ]]; then
if "$upgrade"; then
message="Overwrite $jarlocation? (Y/N) "
else
echo Will place publisher jar here: "$jarlocation"
message="Ok (enter 'y' or 'Y' to continue, any other key to cancel)?"
fi
read -r -p "$message" response
fi
if [[ "$FORCE" == true ]] || [[ "$response" =~ ^([yY])$ ]]; then
echo "Downloading most recent publisher to $jarlocationname - it's ~100 MB, so this may take a bit"
# wget "https://fhir.github.io/latest-ig-publisher/org.hl7.fhir.publisher.jar" -O "$jarlocation"
curl -L $dlurl -o "$jarlocation" --create-dirs
else
echo cancel...
fi