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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
| #!/usr/bin/env sh
#
# Name: websiteGen
#
# Description: This script downloads a website and prepares a static version
# suitable for mirroring.
#
# Synopsis: websiteGen sitedir [host:port] [dir] [-h help]
#
# Copyright: Anntoin Wilkinson (2013)
help()
{
echo >&2 "usage: $0 sitedir [host:port] [dir] [-h help]"
exit 1
}
# Variables with sensible defaults
HOST='localhost:5001'
# Random dir in tmp to prevent file conflicts e.g. script has been used and tmp
# not cleared.
DIR="/tmp/$(head -c 12 /dev/urandom | tr -cd [:alnum:])"
# Get arguments
if [ $1 ]; then
SITEDIR=$1
else
help
fi
if [ $2 ]; then
HOST=$2
fi
if [ $3 ]; then
DIR=$3
fi
while getopts h opt
do
case "$opt" in
h) help;;
\?) # unknown flag
help;;
esac
done
shift `expr $OPTIND - 1`
# Test if SITEDIR exists and is a directory
if [ ! -d $BACKUPDIR ]; then
echo "Not a valid directory"; help
else
echo "Installing static site to $SITEDIR"
fi
PWD=`pwd`
DATE=`date +%R-%d-%b-%Y`
LOGFILE=$PWD/websiteGen-$DATE.log
mkdir -p $DIR
cd $DIR
# Wget option descriptions
# E adjusts the file extension to .html if required
# r recursive download
# p get all the required page prerequists
# k convert links to relative links
# nH no host directories created
wget -rpkE -nH http://$HOST &> $LOGFILE
# Find all the javascript and minify/compress
find . -type f -regex '.*.js' -exec yuicompressor {} -o {} \; &>> $LOGFILE
# Remove all html comments using html tidy
# Issue with javascript menu getting wrecked when using html tidy.
#find . -type f -regex '.*.html' -exec tidy -m --hide-comments true {} \; &>> $LOGFILE
# gzip all html,javascript and css
find . -type f -regex '.*.\(js\|css\|html\)' -exec gzip --best {} \; &>> $LOGFILE
# Move to site using install (To make sure permissions are correct)
# Using -C flag so files are only copied if different.
find . -type f -exec install -C -D -m644 {} $SITEDIR/{} \; &>> $LOGFILE
cd $PWD
|