Created
August 11, 2014 13:58
-
-
Save pavel-arapov/860727bff0f739aa2bea to your computer and use it in GitHub Desktop.
Create gzip version of static files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| FILETYPES=( "*.html" "*.css" "*.js" "*.xml" "*.txt" ) | |
| DIRECTORIES="/path/to/site/dir/" | |
| MIN_SIZE=512 | |
| for currentDir in $DIRECTORIES; | |
| do | |
| for f in "${FILETYPES[@]}"; | |
| do | |
| files="$(find $currentDir -iname "$f")"; | |
| echo "$files" | while read file; | |
| do | |
| PLAINFILE=$file; | |
| GZIPPEDFILE=$file.gz; | |
| if [[ -e "$GZIPPEDFILE" ]]; then | |
| if [[ `stat --printf=%Y "$PLAINFILE"` -gt `stat --printf=%Y "$GZIPPEDFILE"` ]]; then | |
| #echo .gz is older, updating $GZIPPEDFILE; | |
| gzip -2 -f -c "$PLAINFILE" > "$GZIPPEDFILE"; | |
| fi; | |
| if [[ `stat --printf=%s "$PLAINFILE"` -le $MIN_SIZE ]]; then | |
| echo Uncompressed size is less than minimum "("$(stat –printf=%s "$PLAINFILE")")", removing | |
| rm -f "$GZIPPEDFILE"; | |
| fi; | |
| elif [[ `stat --printf=%s "$PLAINFILE"` -gt $MIN_SIZE ]]; then | |
| echo Creating .gz "for" "$PLAINFILE"; | |
| gzip -2 -c "$PLAINFILE" > "$GZIPPEDFILE"; | |
| fi; | |
| done | |
| done | |
| done | |
| exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment