cdn_upload_batch 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/bash
  2. set -e
  3. content_type=$1
  4. bucket=$2
  5. text_extension=$3
  6. shift 3
  7. content_type_options=""
  8. if [[ "$content_type" != "-" ]]; then
  9. content_type_options="-h Content-Type:${content_type};charset=utf-8"
  10. fi
  11. # DOCS for gsutil -- it does not have long command line flags!
  12. ## global flags
  13. # -h NAME:VALUE add header, can occur multiples times
  14. # -m upload with multiple threads
  15. ## rsync flags
  16. # -c use checksums for determining changed files (mtime is not stable)
  17. # -r traverse into directories recursively
  18. # -x Python regex for excluding files from the sync
  19. if [[ "$text_extension" == "-" || $(find /tmp/public -type f -name "*$text_extension" | wc -l) != "0" ]]; then
  20. # Potentially skip upload of non-compressed .js/.css files.
  21. # shellcheck disable=SC2086
  22. gsutil \
  23. -h "Cache-Control:public, max-age=31536000" \
  24. ${content_type_options} \
  25. -m \
  26. rsync \
  27. -c \
  28. -r \
  29. "$@" \
  30. "/tmp/public/" \
  31. "${bucket}/public/"
  32. fi
  33. # shellcheck disable=SC2086
  34. gsutil \
  35. -h "Cache-Control:public, max-age=31536000" \
  36. -h "Content-Encoding:gzip" \
  37. ${content_type_options} \
  38. -m \
  39. rsync \
  40. -c \
  41. -r \
  42. "$@" \
  43. "/tmp/compressed/public/" \
  44. "${bucket}/public/"