You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
990 B

7 years ago
7 years ago
  1. set -e
  2. # retrieve current file version
  3. # e.g. curl -R -I $1
  4. check_version() {
  5. # retrieves HTTP header of file URL response
  6. local httpHeader=$(curl -R -I $1 2>&1 | grep 'Last-Modified:')
  7. # Checks if field "Last-Modified" exists in HTTP header and transform it into timestamp string
  8. # if that field is not present, return current timestamp
  9. local dateVersionFormat="%Y%m%d%H%S"
  10. local dateString=$(date +"$dateVersionFormat")
  11. if [ ! -z "$httpHeader" ]
  12. then
  13. # echo "Last-Modified information returned for targeted file. Extract date, removing day of the week string
  14. local tmpDateString=$(echo "$httpHeader" | sed -e "s/Last-Modified: //" | cut -d',' -f 2)
  15. # rfc1123Format="%d\ %b\ %Y\ %H:%M:%S\ GMT" - in order to work in boot2docker, it has to be outside of quotes in the command below
  16. local dateString=$(date +"$dateVersionFormat" -D %d\ %b\ %Y\ %H:%M:%S\ GMT -d "$tmpDateString")
  17. fi
  18. echo "{\"version\":\"$dateString\"}" | jq --slurp .
  19. }