2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 # T2 SDE: package/.../xorg-server/xvfb-run.sh
6 # Copyright (C) 2005 The T2 SDE Project
7 # Copyright (C) XXXX - 2005 Debian
9 # More information can be found in the files COPYING and README.
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; version 2 of the License. A copy of the
14 # GNU General Public License can be found in the file COPYING.
15 # --- T2-COPYRIGHT-NOTE-END ---
17 # $Id: xvfb-run 2166 2005-01-27 07:54:19Z branden $
18 # from: http://necrotic.deadbeast.net/xsf/XFree86/trunk/debian/local/xvfb-run
20 # This script starts an instance of Xvfb, the "fake" X server, runs a command
21 # with that server available, and kills the X server when done. The return
22 # value of the command becomes the return value of this script.
24 # If anyone is using this to build a Debian package, make sure the package
25 # Build-Depends on xvfb, xbase-clients, and xfonts-base.
34 XVFBARGS
="-screen 0 640x480x8"
35 LISTENTCP
="-nolisten tcp"
38 # Query the terminal to establish a default number of columns to use for
39 # displaying messages to the user. This is used only as a fallback in the event
40 # the COLUMNS variable is not set. ($COLUMNS can react to SIGWINCH while the
41 # script is running, and this cannot, only being calculated once.)
42 DEFCOLUMNS
=$
(stty size
2>/dev
/null |
awk '{print $2}') || true
43 if ! expr "$DEFCOLUMNS" : "[[:digit:]]\+$" >/dev
/null
2>&1; then
47 # Display a message, wrapping lines at the terminal width.
49 echo "$PROGNAME: $*" |
fmt -t -w ${COLUMNS:-$DEFCOLUMNS}
52 # Display an error message.
54 message
"error: $*" >&2
57 # Display a usage message.
60 message
"usage error: $*"
63 Usage: $PROGNAME [OPTION ...] COMMAND
64 Run COMMAND (usually an X client) in a virtual X server environment.
66 -a --auto-servernum try to get a free server number, starting at
68 -e FILE --error-file=FILE file used to store xauth errors and Xvfb
69 output (default: $ERRORFILE)
70 -f FILE --auth-file=FILE file used to store auth cookie
71 (default: ./.Xauthority)
72 -h --help display this usage message and exit
73 -n NUM --server-num=NUM server number to use (default: $SERVERNUM)
74 -l --listen-tcp enable TCP port listening in the X server
75 -p PROTO --xauth-protocol=PROTO X authority protocol name to use
76 (default: xauth command's default)
77 -s ARGS --server-args=ARGS arguments (other than server number and
78 "-nolisten tcp") to pass to the Xvfb server
79 (default: "$XVFBARGS")
80 -w DELAY --wait=DELAY delay in seconds to wait for Xvfb to start
81 before running COMMAND (default: $STARTWAIT)
85 # Find a free server number by looking at .X*-lock files in /tmp.
86 find_free_servernum
() {
87 # Sadly, the "local" keyword is not POSIX. Leave the next line commented in
88 # the hope Debian Policy eventually changes to allow it in /bin/sh scripts
93 while [ -f /tmp
/.X
$i-lock ]; do
99 # Parse the command line.
100 ARGS
=$
(getopt
--options +ae
:f
:hn
:lp:s
:w
: \
101 --long auto-servernum
,error-file
:auth-file
:,help,server-num
:,listen-tcp
,xauth-protocol
:,server-args
:,wait: \
102 --name "$PROGNAME" -- "$@")
105 if [ $GETOPT_STATUS -ne 0 ]; then
106 error
"internal error; getopt exited with status $GETOPT_STATUS"
114 -a|
--auto-servernum) SERVERNUM
=$
(find_free_servernum
) ;;
115 -e|
--error-file) ERRORFILE
="$2"; shift ;;
116 -f|
--auth-file) AUTHFILE
="$2"; shift ;;
117 -h|
--help) SHOWHELP
="yes" ;;
118 -n|
--server-num) SERVERNUM
="$2"; shift ;;
119 -l|
--listen-tcp) LISTENTCP
="" ;;
120 -p|
--xauth-protocol) XAUTHPROTO
="$2"; shift ;;
121 -s|
--server-args) XVFBARGS
="$2"; shift ;;
122 -w|
--wait) STARTWAIT
="$2"; shift ;;
124 *) error
"internal error; getopt permitted \"$1\" unexpectedly"
131 if [ "$SHOWHELP" ]; then
137 usage
"need a command to run" >&2
141 if ! which xauth
>/dev
/null
; then
142 error
"xauth command not found"
146 # If the user did not specify an X authorization file to use, set up a temporary
147 # directory to house one.
148 if [ -z "$AUTHFILE" ]; then
149 XVFB_RUN_TMPDIR
="${TMPDIR:-/tmp}/$PROGNAME.$$"
150 if ! mkdir
-p -m 700 "$XVFB_RUN_TMPDIR"; then
151 error
"temporary directory $XVFB_RUN_TMPDIR already exists"
154 AUTHFILE
=$
(mktemp
-p "$XVFB_RUN_TMPDIR" Xauthority
)
159 XAUTHORITY
=$AUTHFILE xauth add
":$SERVERNUM" "$XAUTHPROTO" "$MCOOKIE" \
161 XAUTHORITY
=$AUTHFILE Xvfb
":$SERVERNUM" $XVFBARGS $LISTENTCP >"$ERRORFILE" \
166 # Start the command and save its exit status.
168 DISPLAY
=:$SERVERNUM XAUTHORITY
=$AUTHFILE "$@" 2>&1
172 # Kill Xvfb now that the command has exited.
176 XAUTHORITY
=$AUTHFILE xauth remove
":$SERVERNUM" >"$ERRORFILE" 2>&1
177 if [ -n "$XVFB_RUN_TMPDIR" ]; then
178 if ! rm -r "$XVFB_RUN_TMPDIR"; then
179 error
"problem while cleaning up temporary directory"
184 # Return the executed command's exit status.
187 # vim:set ai et sts=4 sw=4 tw=80: