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 ---
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 640x480x24"
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
67 --server-num (deprecated, use --auto-display
69 -d --auto-display use the X server to find a display number
71 -e FILE --error-file=FILE file used to store xauth errors and Xvfb
72 output (default: $ERRORFILE)
73 -f FILE --auth-file=FILE file used to store auth cookie
74 (default: ./.Xauthority)
75 -h --help display this usage message and exit
76 -n NUM --server-num=NUM server number to use (default: $SERVERNUM)
77 -l --listen-tcp enable TCP port listening in the X server
78 -p PROTO --xauth-protocol=PROTO X authority protocol name to use
79 (default: xauth command's default)
80 -s ARGS --server-args=ARGS arguments (other than server number and
81 "-nolisten tcp") to pass to the Xvfb server
82 (default: "$XVFBARGS")
83 -w DELAY --wait=DELAY delay in seconds to wait for Xvfb to start
84 before running COMMAND (default: $STARTWAIT)
88 # Find a free server number by looking at .X*-lock files in /tmp.
89 find_free_servernum
() {
90 # Sadly, the "local" keyword is not POSIX. Leave the next line commented in
91 # the hope Debian Policy eventually changes to allow it in /bin/sh scripts
96 while [ -f /tmp
/.X
$i-lock ]; do
102 # Parse the command line.
103 ARGS
=$
(getopt
--options +ade
:f
:hn
:lp:s
:w
: \
104 --long auto-servernum
,auto-display
,error-file
:,auth-file
:,help,server-num
:,listen-tcp
,xauth-protocol
:,server-args
:,wait: \
105 --name "$PROGNAME" -- "$@")
108 if [ $GETOPT_STATUS -ne 0 ]; then
109 error
"internal error; getopt exited with status $GETOPT_STATUS"
117 -a|
--auto-servernum) SERVERNUM
=$
(find_free_servernum
) ;;
118 -d|
--auto-display) AUTO_DISPLAY
=1 ;;
119 -e|
--error-file) ERRORFILE
="$2"; shift ;;
120 -f|
--auth-file) AUTHFILE
="$2"; shift ;;
121 -h|
--help) SHOWHELP
="yes" ;;
122 -n|
--server-num) SERVERNUM
="$2"; shift ;;
123 -l|
--listen-tcp) LISTENTCP
="" ;;
124 -p|
--xauth-protocol) XAUTHPROTO
="$2"; shift ;;
125 -s|
--server-args) XVFBARGS
="$2"; shift ;;
126 -w|
--wait) STARTWAIT
="$2"; shift ;;
128 *) error
"internal error; getopt permitted \"$1\" unexpectedly"
135 if [ "$SHOWHELP" ]; then
141 usage
"need a command to run" >&2
145 if ! type xauth
>/dev
/null
; then
146 error
"xauth command not found"
150 # Set up the temp dir for the pid and X authorization file
151 XVFB_RUN_TMPDIR
="$(mktemp --directory --tmpdir $PROGNAME.XXXXXX)"
152 # If the user did not specify an X authorization file to use, set up a temporary
153 # directory to house one.
154 if [ -z "$AUTHFILE" ]; then
155 AUTHFILE
=$
(mktemp
-p "$XVFB_RUN_TMPDIR" Xauthority.XXXXXX
)
161 if [ -z "$AUTO_DISPLAY" ]; then
162 # Old style using a pre-computed SERVERNUM
163 XAUTHORITY
=$AUTHFILE Xvfb
":$SERVERNUM" $XVFBARGS $LISTENTCP >>"$ERRORFILE" \
167 # New style using Xvfb to provide a free display
168 PIDFILE
=$
(mktemp
-p "$XVFB_RUN_TMPDIR" pid.XXXXXX
)
169 SERVERNUM
=$
(XAUTHORITY
=$AUTHFILE Xvfb
-displayfd 1 $XVFBARGS $LISTENTCP \
170 2>"$ERRORFILE" & echo $
! > $PIDFILE)
171 XVFBPID
=$
(cat $PIDFILE)
175 XAUTHORITY
=$AUTHFILE xauth
source - << EOF >>"$ERRORFILE" 2>&1
176 add :$SERVERNUM $XAUTHPROTO $MCOOKIE
179 # Start the command and save its exit status.
181 DISPLAY
=:$SERVERNUM XAUTHORITY
=$AUTHFILE "$@"
185 # Kill Xvfb now that the command has exited.
189 XAUTHORITY
=$AUTHFILE xauth remove
":$SERVERNUM" >"$ERRORFILE" 2>&1
190 if [ -n "$XVFB_RUN_TMPDIR" ]; then
191 if ! rm -r "$XVFB_RUN_TMPDIR"; then
192 error
"problem while cleaning up temporary directory"
197 # Return the executed command's exit status.
200 # vim:set ai et sts=4 sw=4 tw=80: