cdn_upload_batch 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. gsutil \
  22. -h "Cache-Control:public, max-age=31536000" \
  23. ${content_type_options} \
  24. -m \
  25. rsync \
  26. -c \
  27. -r \
  28. "$@" \
  29. "/tmp/public/" \
  30. "${bucket}/public/"
  31. fi
  32. gsutil \
  33. -h "Cache-Control:public, max-age=31536000" \
  34. -h "Content-Encoding:gzip" \
  35. ${content_type_options} \
  36. -m \
  37. rsync \
  38. -c \
  39. -r \
  40. "$@" \
  41. "/tmp/compressed/public/" \
  42. "${bucket}/public/"