-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgzip_static_files.sh
30 lines (26 loc) · 1.05 KB
/
gzip_static_files.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#! /bin/bash
# this script checks a list of directories for a list of extensions and
# generated gzipped versions of the files that are found
#
# if the modification date of a file is newer than its gzipped version
# then the gzip file is regenerated
# specify a filetype like *.css or a filename like index.html
# leave one space between entries
FILETYPES="*.css *.jpg *.jpeg *.gif *.png *.js *.html"
# specify a list of directories to check recursively
DIRECTORIES=$1
for currentdir in $DIRECTORIES
do
for extension in $FILETYPES
do
find $currentdir -iname $extension -exec bash -c 'PLAINFILE={};GZIPPEDFILE={}.gz; \
if [ -e $GZIPPEDFILE ]; \
then if [ `stat --printf=%Y $PLAINFILE` -gt `stat --printf=%Y $GZIPPEDFILE` ]; \
then echo "$GZIPPEDFILE outdated, regenerating"; \
gzip -9 -f -n -c $PLAINFILE > $GZIPPEDFILE; \
fi; \
else echo "$GZIPPEDFILE is missing, creating it"; \
gzip -9 -n -c $PLAINFILE > $GZIPPEDFILE; \
fi' \;
done
done