Create a gist now

Instantly share code, notes, and snippets.

gzip octopress files and sync them to S3 and CloudFront with s3cmd. Original script by Julian Schrittwieser (https://github.com/mononofu) - http://www.furida.mu/blog/2012/02/29/gzip-your-octopress.
#!/bin/bash
# compress the files if they aren't
find public/ -iname '*.html' -exec ./gzip_if_not_gzipped.sh {} \;
find public/ -iname '*.js' -exec ./gzip_if_not_gzipped.sh {} \;
find public/ -iname '*.css' -exec ./gzip_if_not_gzipped.sh {} \;
# change their name back
find public -iname '*.gz' -exec bash -c 'mv $0 ${0/.gz/}' {} \;
echo "gzipping successful"
echo "syncing gzipped files"
s3cmd sync --progress --acl-public --reduced-redundancy --cf-invalidate --verbose --cf-invalidate-default-index --add-header 'Content-Encoding:gzip' public/* s3://$1/ --exclude '*.*' --include '*.html' --include '*.js' --include '*.css'
echo "syncing gzipped files complete"
echo "syncing non-gzipped files"
s3cmd sync --progress --acl-public --reduced-redundancy --cf-invalidate --verbose public/* s3://$1/ --exclude '*.html' --exclude '*.js' --exclude '*.css'
echo "syncing non-gzipped files complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment