#!/bin/sh
#
# Rob Ekl, October, 2001
#          October, 2004: better use of "find", etc
#
# This script will find all files greater than MIN_SIZE bytes
# whose mime type is one in the list and compressed it, saving
# the original file.  If the uncompressed file is newer than
# the compressed one, the compressed file will be overwritten
# by the newly compressed output.
# This is useful for web servers that want to send compressed
# content from an already-compressed file that matches a requested
# file.

MIN_SIZE=128

find /home/web/web-root/static/ \( -name \*.txt -or -name \*.html -or -name \*.htm -or -name \*.rtx -or -name \*.etx -or -name \*.tsv -or -name \*.css -or -name \*.xml -or -name \*.dtd -or -name \*.js \) -size +${MIN_SIZE}c -print | {
  while read a
  do
    if [ ! -f "${a}.gz" -o "${a}" -nt "${a}.gz" ]; then
      cat "${a}" | gzip -9 > "${a}.gz.tmp" && mv -f "${a}.gz.tmp" "${a}.gz"
    fi
  done
}

