author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 10 Sep 2012 17:31:07 +0200 | |
changeset 8540 | fee98af8bb33 |
parent 8339 | 63348ead09fb |
child 8758 | 3a0d91237e2c |
permissions | -rwxr-xr-x |
8261
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
1 |
#!/bin/sh |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
2 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
3 |
# This script starts an instance of Xvfb, the "fake" X server, runs a command |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
4 |
# with that server available, and kills the X server when done. The return |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
5 |
# value of the command becomes the return value of this script. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
6 |
# |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
7 |
# If anyone is using this to build a Debian package, make sure the package |
8327
4d76492508f3
[devtools] make xvfb-run not wait 3s each time (closes #2265710)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8261
diff
changeset
|
8 |
# Build-Depends on xvfb and xauth. |
8261
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
9 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
10 |
set -e |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
11 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
12 |
PROGNAME=xvfb-run |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
13 |
SERVERNUM=99 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
14 |
AUTHFILE= |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
15 |
ERRORFILE=/dev/null |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
16 |
XVFBARGS="-screen 0 640x480x8" |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
17 |
LISTENTCP="-nolisten tcp" |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
18 |
XAUTHPROTO=. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
19 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
20 |
# Query the terminal to establish a default number of columns to use for |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
21 |
# displaying messages to the user. This is used only as a fallback in the event |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
22 |
# the COLUMNS variable is not set. ($COLUMNS can react to SIGWINCH while the |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
23 |
# script is running, and this cannot, only being calculated once.) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
24 |
DEFCOLUMNS=$(stty size 2>/dev/null | awk '{print $2}') || true |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
25 |
if ! expr "$DEFCOLUMNS" : "[[:digit:]]\+$" >/dev/null 2>&1; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
26 |
DEFCOLUMNS=80 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
27 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
28 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
29 |
# Display a message, wrapping lines at the terminal width. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
30 |
message () { |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
31 |
echo "$PROGNAME: $*" | fmt -t -w ${COLUMNS:-$DEFCOLUMNS} |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
32 |
} |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
33 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
34 |
# Display an error message. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
35 |
error () { |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
36 |
message "error: $*" >&2 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
37 |
} |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
38 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
39 |
# Display a usage message. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
40 |
usage () { |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
41 |
if [ -n "$*" ]; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
42 |
message "usage error: $*" |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
43 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
44 |
cat <<EOF |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
45 |
Usage: $PROGNAME [OPTION ...] COMMAND |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
46 |
Run COMMAND (usually an X client) in a virtual X server environment. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
47 |
Options: |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
48 |
-a --auto-servernum try to get a free server number, starting at |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
49 |
--server-num |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
50 |
-e FILE --error-file=FILE file used to store xauth errors and Xvfb |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
51 |
output (default: $ERRORFILE) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
52 |
-f FILE --auth-file=FILE file used to store auth cookie |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
53 |
(default: ./.Xauthority) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
54 |
-h --help display this usage message and exit |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
55 |
-n NUM --server-num=NUM server number to use (default: $SERVERNUM) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
56 |
-l --listen-tcp enable TCP port listening in the X server |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
57 |
-p PROTO --xauth-protocol=PROTO X authority protocol name to use |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
58 |
(default: xauth command's default) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
59 |
-s ARGS --server-args=ARGS arguments (other than server number and |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
60 |
"-nolisten tcp") to pass to the Xvfb server |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
61 |
(default: "$XVFBARGS") |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
62 |
EOF |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
63 |
} |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
64 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
65 |
# Find a free server number by looking at .X*-lock files in /tmp. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
66 |
find_free_servernum() { |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
67 |
# Sadly, the "local" keyword is not POSIX. Leave the next line commented in |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
68 |
# the hope Debian Policy eventually changes to allow it in /bin/sh scripts |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
69 |
# anyway. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
70 |
#local i |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
71 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
72 |
i=$SERVERNUM |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
73 |
while [ -f /tmp/.X$i-lock ]; do |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
74 |
i=$(($i + 1)) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
75 |
done |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
76 |
echo $i |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
77 |
} |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
78 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
79 |
# Clean up files |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
80 |
clean_up() { |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
81 |
if [ -e "$AUTHFILE" ]; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
82 |
XAUTHORITY=$AUTHFILE xauth remove ":$SERVERNUM" >>"$ERRORFILE" 2>&1 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
83 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
84 |
if [ -n "$XVFB_RUN_TMPDIR" ]; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
85 |
if ! rm -r "$XVFB_RUN_TMPDIR"; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
86 |
error "problem while cleaning up temporary directory" |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
87 |
exit 5 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
88 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
89 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
90 |
if [ -n "$XVFBPID" ]; then |
8327
4d76492508f3
[devtools] make xvfb-run not wait 3s each time (closes #2265710)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8261
diff
changeset
|
91 |
kill "$XVFBPID" |
8261
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
92 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
93 |
} |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
94 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
95 |
# Parse the command line. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
96 |
ARGS=$(getopt --options +ae:f:hn:lp:s:w: \ |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
97 |
--long auto-servernum,error-file:,auth-file:,help,server-num:,listen-tcp,xauth-protocol:,server-args:,wait: \ |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
98 |
--name "$PROGNAME" -- "$@") |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
99 |
GETOPT_STATUS=$? |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
100 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
101 |
if [ $GETOPT_STATUS -ne 0 ]; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
102 |
error "internal error; getopt exited with status $GETOPT_STATUS" |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
103 |
exit 6 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
104 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
105 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
106 |
eval set -- "$ARGS" |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
107 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
108 |
while :; do |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
109 |
case "$1" in |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
110 |
-a|--auto-servernum) SERVERNUM=$(find_free_servernum); AUTONUM="yes" ;; |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
111 |
-e|--error-file) ERRORFILE="$2"; shift ;; |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
112 |
-f|--auth-file) AUTHFILE="$2"; shift ;; |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
113 |
-h|--help) SHOWHELP="yes" ;; |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
114 |
-n|--server-num) SERVERNUM="$2"; shift ;; |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
115 |
-l|--listen-tcp) LISTENTCP="" ;; |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
116 |
-p|--xauth-protocol) XAUTHPROTO="$2"; shift ;; |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
117 |
-s|--server-args) XVFBARGS="$2"; shift ;; |
8327
4d76492508f3
[devtools] make xvfb-run not wait 3s each time (closes #2265710)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8261
diff
changeset
|
118 |
-w|--wait) shift ;; |
8261
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
119 |
--) shift; break ;; |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
120 |
*) error "internal error; getopt permitted \"$1\" unexpectedly" |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
121 |
exit 6 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
122 |
;; |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
123 |
esac |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
124 |
shift |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
125 |
done |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
126 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
127 |
if [ "$SHOWHELP" ]; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
128 |
usage |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
129 |
exit 0 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
130 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
131 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
132 |
if [ -z "$*" ]; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
133 |
usage "need a command to run" >&2 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
134 |
exit 2 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
135 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
136 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
137 |
if ! which xauth >/dev/null; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
138 |
error "xauth command not found" |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
139 |
exit 3 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
140 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
141 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
142 |
# tidy up after ourselves |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
143 |
trap clean_up EXIT |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
144 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
145 |
# If the user did not specify an X authorization file to use, set up a temporary |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
146 |
# directory to house one. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
147 |
if [ -z "$AUTHFILE" ]; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
148 |
XVFB_RUN_TMPDIR="$(mktemp -d -t $PROGNAME.XXXXXX)" |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
149 |
# Create empty file to avoid xauth warning |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
150 |
AUTHFILE=$(tempfile -n "$XVFB_RUN_TMPDIR/Xauthority") |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
151 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
152 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
153 |
# Start Xvfb. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
154 |
MCOOKIE=$(mcookie) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
155 |
tries=10 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
156 |
while [ $tries -gt 0 ]; do |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
157 |
tries=$(( $tries - 1 )) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
158 |
XAUTHORITY=$AUTHFILE xauth source - << EOF >>"$ERRORFILE" 2>&1 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
159 |
add :$SERVERNUM $XAUTHPROTO $MCOOKIE |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
160 |
EOF |
8327
4d76492508f3
[devtools] make xvfb-run not wait 3s each time (closes #2265710)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8261
diff
changeset
|
161 |
# handle SIGUSR1 so Xvfb knows to send a signal when it's ready to accept |
4d76492508f3
[devtools] make xvfb-run not wait 3s each time (closes #2265710)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8261
diff
changeset
|
162 |
# connections |
8339
63348ead09fb
[devtools] fix bashism in xvfb-run.sh
Julien Cristau <julien.cristau@logilab.fr>
parents:
8327
diff
changeset
|
163 |
trap : USR1 |
63348ead09fb
[devtools] fix bashism in xvfb-run.sh
Julien Cristau <julien.cristau@logilab.fr>
parents:
8327
diff
changeset
|
164 |
(trap '' USR1; XAUTHORITY=$AUTHFILE exec Xvfb ":$SERVERNUM" $XVFBARGS $LISTENTCP >>"$ERRORFILE" 2>&1) & |
8261
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
165 |
XVFBPID=$! |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
166 |
|
8327
4d76492508f3
[devtools] make xvfb-run not wait 3s each time (closes #2265710)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8261
diff
changeset
|
167 |
wait || : |
8261
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
168 |
if kill -0 $XVFBPID 2>/dev/null; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
169 |
break |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
170 |
elif [ -n "$AUTONUM" ]; then |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
171 |
# The display is in use so try another one (if '-a' was specified). |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
172 |
SERVERNUM=$((SERVERNUM + 1)) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
173 |
SERVERNUM=$(find_free_servernum) |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
174 |
continue |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
175 |
fi |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
176 |
error "Xvfb failed to start" >&2 |
8327
4d76492508f3
[devtools] make xvfb-run not wait 3s each time (closes #2265710)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8261
diff
changeset
|
177 |
XVFBPID= |
8261
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
178 |
exit 1 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
179 |
done |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
180 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
181 |
# Start the command and save its exit status. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
182 |
set +e |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
183 |
DISPLAY=:$SERVERNUM XAUTHORITY=$AUTHFILE "$@" 2>&1 |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
184 |
RETVAL=$? |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
185 |
set -e |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
186 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
187 |
# Return the executed command's exit status. |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
188 |
exit $RETVAL |
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
189 |
|
d4d9c88d4a5f
[devtools] make a copy of the xvfb-run script so we can kill it properly
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff
changeset
|
190 |
# vim:set ai et sts=4 sw=4 tw=80: |