33 |
# and then resize it to (comment out to disable) |
# and then resize it to (comment out to disable) |
34 |
#RESIZE=200x |
#RESIZE=200x |
35 |
|
|
36 |
|
# turn locally visible Xnest server to watch progress |
37 |
|
DEBUG=0 |
38 |
|
test ! -z "$3" && DEBUG=1 |
39 |
|
|
40 |
|
# wait for $WAIT seconds for page to load |
41 |
|
WAIT=30 |
42 |
|
|
43 |
# some configurable paths |
# some configurable paths |
44 |
BROWSER=mozilla-firefox |
BROWSER=mozilla-firefox |
45 |
XSERVER=Xvfb |
XSERVER=Xvfb |
51 |
PROFILE_DIR=`mktemp -d` |
PROFILE_DIR=`mktemp -d` |
52 |
PORT=8888 |
PORT=8888 |
53 |
|
|
54 |
|
LOCAL_DISPLAY=$DISPLAY |
55 |
|
|
56 |
if [ -z "$URL" ] ; then |
if [ -z "$URL" ] ; then |
57 |
echo "usage: $0 http://url.to.capture [screenshot.jpg]" |
echo "usage: $0 http://url.to.capture [screenshot.jpg]" |
58 |
exit 1 |
exit 1 |
68 |
exit 1 |
exit 1 |
69 |
fi |
fi |
70 |
|
|
71 |
|
while netstat -ln | grep ":$PORT " >/dev/null ; do |
72 |
|
PORT=`expr $PORT + 1` |
73 |
|
done |
74 |
|
|
75 |
|
echo "### using port $PORT" |
76 |
|
|
77 |
echo -n "testing URL $URL " |
echo -n "testing URL $URL " |
78 |
if HEAD $URL >/dev/null ; then |
if HEAD $URL >/dev/null ; then |
79 |
echo "ok" |
echo "ok" |
86 |
|
|
87 |
export DISPLAY=:42 |
export DISPLAY=:42 |
88 |
|
|
89 |
$XSERVER -ac -screen 0 ${W}x${H}x24 $DISPLAY & |
|
90 |
# debug server |
if [ "$DEBUG" == 1 ] ; then |
91 |
#Xnest -display :0 -ac -geometry ${W}x${H} -depth 24 $DISPLAY & |
echo "Using locally visible debug server on $LOCAL_DISPLAY" |
92 |
|
Xnest -display $LOCAL_DISPLAY -ac -geometry ${W}x${H} -depth 24 $DISPLAY 2>/dev/null & |
93 |
|
else |
94 |
|
$XSERVER -ac -screen 0 ${W}x${H}x24 $DISPLAY 2>/dev/null & |
95 |
|
fi |
96 |
|
|
97 |
XSERVER_PID=$! |
XSERVER_PID=$! |
98 |
echo "using pid $xserver_pid for X server" |
echo "using pid $XSERVER_PID for X server" |
99 |
|
|
100 |
function kill_x_server() { |
function kill_x_server() { |
101 |
kill $BROWSER_PID |
echo "Killing server $XSERVER_PID" |
102 |
kill $XSERVER_PID |
kill $XSERVER_PID |
103 |
rm -f $FRAMESET |
rm -f $FRAMESET |
104 |
rm -fr $PROFILE_DIR |
rm -fr $PROFILE_DIR |
105 |
|
exit 1 |
106 |
} |
} |
107 |
trap 'echo "QUIT!" >&2; kill_x_server; exit 1' INT QUIT TERM SEGV |
trap 'kill_x_server' INT QUIT TERM SEGV EXIT |
108 |
|
|
109 |
# create frameset to load site and after site is loaded trigger this script |
# create frameset to load site and after site is loaded trigger this script |
110 |
cat > $FRAMESET <<END_OF_FRAMESET |
cat > $FRAMESET <<END_OF_FRAMESET |
123 |
echo "preview available with: xwd -display $DISPLAY -root | xwud" |
echo "preview available with: xwd -display $DISPLAY -root | xwud" |
124 |
|
|
125 |
echo "making 'Screenshot' profile in $PROFILE_DIR" |
echo "making 'Screenshot' profile in $PROFILE_DIR" |
126 |
$BROWSER -CreateProfile "Screenshot $PROFILE_DIR" | grep Success |
$BROWSER -CreateProfile "Screenshot $PROFILE_DIR" 2>/dev/null | grep Success |
127 |
|
|
128 |
echo "launching browser $BROWSER with $URL" |
echo "launching browser $BROWSER with $URL" |
129 |
$BROWSER -P Screenshot -width $W -height $H $FRAMESET & |
$BROWSER -P Screenshot -width $W -height $H $FRAMESET 2>/dev/null & |
130 |
BROWSER_PID=$! |
BROWSER_PID=$! |
131 |
|
|
132 |
echo "staring web server (wait for page to load)" |
function kill_browser() { |
133 |
|
echo "Killing browser $BROWSER_PID" |
134 |
|
kill $BROWSER_PID |
135 |
|
echo "Killing server $XSERVER_PID" |
136 |
|
kill $XSERVER_PID |
137 |
|
rm -f $FRAMESET |
138 |
|
rm -fr $PROFILE_DIR |
139 |
|
exit 1 |
140 |
|
} |
141 |
|
trap 'kill_browser' INT QUIT TERM SEGV EXIT |
142 |
|
|
143 |
|
echo "waiting for on_load event from browser $BROWSER_PID for ${WAIT}s" |
144 |
|
|
145 |
# there is hard-coded limit here: |
# there is hard-coded limit here: |
146 |
# we will wait 60sec for page to load and render |
# we will wait $WAIT sec for page to load and render |
147 |
|
|
148 |
echo -e "HTTP/1.0 304 Not modified\r\n\r\n" | nc -l -w 60 -p $PORT >/dev/null |
echo -e "HTTP/1.0 304 Not modified\r\n\r\n" | nc -l -w $WAIT -p $PORT >/dev/null || echo "Timeout after $WAIT sec!" |
149 |
|
|
150 |
# get Mozilla Firefox window id (for resize) |
# get Mozilla Firefox window id (for resize) |
151 |
WINDOW_ID=`xwininfo -display $DISPLAY -root -tree | grep gecko | cut -d\" -f1 | sort -n | head -1` |
WINDOW_ID=`xwininfo -display $DISPLAY -root -tree | grep gecko | cut -d\" -f1 | sort -n | head -1` |
186 |
|
|
187 |
import -window $DUMP_ID $RESIZE $FILE |
import -window $DUMP_ID $RESIZE $FILE |
188 |
|
|
|
kill_x_server |
|
|
|
|