--- /dev/null
+#!/bin/sh\r
+# --- T2-COPYRIGHT-NOTE-BEGIN ---\r
+# This copyright note is auto-generated by ./scripts/Create-CopyPatch.\r
+# \r
+# T2 SDE: package/.../xorg-server/xvfb-run.sh\r
+# Copyright (C) 2005 The T2 SDE Project\r
+# Copyright (C) XXXX - 2005 Debian\r
+# \r
+# More information can be found in the files COPYING and README.\r
+# \r
+# This program is free software; you can redistribute it and/or modify\r
+# it under the terms of the GNU General Public License as published by\r
+# the Free Software Foundation; version 2 of the License. A copy of the\r
+# GNU General Public License can be found in the file COPYING.\r
+# --- T2-COPYRIGHT-NOTE-END ---\r
+\r
+# $Id: xvfb-run 2166 2005-01-27 07:54:19Z branden $\r
+# from: http://necrotic.deadbeast.net/xsf/XFree86/trunk/debian/local/xvfb-run\r
+\r
+# This script starts an instance of Xvfb, the "fake" X server, runs a command\r
+# with that server available, and kills the X server when done. The return\r
+# value of the command becomes the return value of this script.\r
+#\r
+# If anyone is using this to build a Debian package, make sure the package\r
+# Build-Depends on xvfb, xbase-clients, and xfonts-base.\r
+\r
+set -e\r
+\r
+PROGNAME=xvfb-run\r
+SERVERNUM=99\r
+AUTHFILE=\r
+ERRORFILE=/dev/null\r
+STARTWAIT=3\r
+XVFBARGS="-screen 0 640x480x8"\r
+LISTENTCP="-nolisten tcp"\r
+XAUTHPROTO=.\r
+\r
+# Query the terminal to establish a default number of columns to use for\r
+# displaying messages to the user. This is used only as a fallback in the event\r
+# the COLUMNS variable is not set. ($COLUMNS can react to SIGWINCH while the\r
+# script is running, and this cannot, only being calculated once.)\r
+DEFCOLUMNS=$(stty size 2>/dev/null | awk '{print $2}') || true\r
+if ! expr "$DEFCOLUMNS" : "[[:digit:]]\+$" >/dev/null 2>&1; then\r
+ DEFCOLUMNS=80\r
+fi\r
+\r
+# Display a message, wrapping lines at the terminal width.\r
+message () {\r
+ echo "$PROGNAME: $*" | fmt -t -w ${COLUMNS:-$DEFCOLUMNS}\r
+}\r
+\r
+# Display an error message.\r
+error () {\r
+ message "error: $*" >&2\r
+}\r
+\r
+# Display a usage message.\r
+usage () {\r
+ if [ -n "$*" ]; then\r
+ message "usage error: $*"\r
+ fi\r
+ cat <<EOF\r
+Usage: $PROGNAME [OPTION ...] COMMAND\r
+Run COMMAND (usually an X client) in a virtual X server environment.\r
+Options:\r
+-a --auto-servernum try to get a free server number, starting at\r
+ --server-num\r
+-e FILE --error-file=FILE file used to store xauth errors and Xvfb\r
+ output (default: $ERRORFILE)\r
+-f FILE --auth-file=FILE file used to store auth cookie\r
+ (default: ./.Xauthority)\r
+-h --help display this usage message and exit\r
+-n NUM --server-num=NUM server number to use (default: $SERVERNUM)\r
+-l --listen-tcp enable TCP port listening in the X server\r
+-p PROTO --xauth-protocol=PROTO X authority protocol name to use\r
+ (default: xauth command's default)\r
+-s ARGS --server-args=ARGS arguments (other than server number and\r
+ "-nolisten tcp") to pass to the Xvfb server\r
+ (default: "$XVFBARGS")\r
+-w DELAY --wait=DELAY delay in seconds to wait for Xvfb to start\r
+ before running COMMAND (default: $STARTWAIT)\r
+EOF\r
+}\r
+\r
+# Find a free server number by looking at .X*-lock files in /tmp.\r
+find_free_servernum() {\r
+ # Sadly, the "local" keyword is not POSIX. Leave the next line commented in\r
+ # the hope Debian Policy eventually changes to allow it in /bin/sh scripts\r
+ # anyway.\r
+ #local i\r
+\r
+ i=$SERVERNUM\r
+ while [ -f /tmp/.X$i-lock ]; do\r
+ i=$(($i + 1))\r
+ done\r
+ echo $i\r
+}\r
+\r
+# Parse the command line.\r
+ARGS=$(getopt --options +ae:f:hn:lp:s:w: \\r
+ --long auto-servernum,error-file:auth-file:,help,server-num:,listen-tcp,xauth-protocol:,server-args:,wait: \\r
+ --name "$PROGNAME" -- "$@")\r
+GETOPT_STATUS=$?\r
+\r
+if [ $GETOPT_STATUS -ne 0 ]; then\r
+ error "internal error; getopt exited with status $GETOPT_STATUS"\r
+ exit 6\r
+fi\r
+\r
+eval set -- "$ARGS"\r
+\r
+while :; do\r
+ case "$1" in\r
+ -a|--auto-servernum) SERVERNUM=$(find_free_servernum) ;;\r
+ -e|--error-file) ERRORFILE="$2"; shift ;;\r
+ -f|--auth-file) AUTHFILE="$2"; shift ;;\r
+ -h|--help) SHOWHELP="yes" ;;\r
+ -n|--server-num) SERVERNUM="$2"; shift ;;\r
+ -l|--listen-tcp) LISTENTCP="" ;;\r
+ -p|--xauth-protocol) XAUTHPROTO="$2"; shift ;;\r
+ -s|--server-args) XVFBARGS="$2"; shift ;;\r
+ -w|--wait) STARTWAIT="$2"; shift ;;\r
+ --) shift; break ;;\r
+ *) error "internal error; getopt permitted \"$1\" unexpectedly"\r
+ exit 6\r
+ ;;\r
+ esac\r
+ shift\r
+done\r
+\r
+if [ "$SHOWHELP" ]; then\r
+ usage\r
+ exit 0\r
+fi\r
+\r
+if [ -z "$*" ]; then\r
+ usage "need a command to run" >&2\r
+ exit 2\r
+fi\r
+\r
+if ! which xauth >/dev/null; then\r
+ error "xauth command not found"\r
+ exit 3\r
+fi\r
+\r
+# If the user did not specify an X authorization file to use, set up a temporary\r
+# directory to house one.\r
+if [ -z "$AUTHFILE" ]; then\r
+ XVFB_RUN_TMPDIR="${TMPDIR:-/tmp}/$PROGNAME.$$"\r
+ if ! mkdir -p -m 700 "$XVFB_RUN_TMPDIR"; then\r
+ error "temporary directory $XVFB_RUN_TMPDIR already exists"\r
+ exit 4\r
+ fi\r
+ AUTHFILE=$(mktemp -p "$XVFB_RUN_TMPDIR" Xauthority)\r
+fi\r
+\r
+# Start Xvfb.\r
+MCOOKIE=$(mcookie)\r
+XAUTHORITY=$AUTHFILE xauth add ":$SERVERNUM" "$XAUTHPROTO" "$MCOOKIE" \\r
+ >"$ERRORFILE" 2>&1\r
+XAUTHORITY=$AUTHFILE Xvfb ":$SERVERNUM" $XVFBARGS $LISTENTCP >"$ERRORFILE" \\r
+ 2>&1 &\r
+XVFBPID=$!\r
+sleep "$STARTWAIT"\r
+\r
+# Start the command and save its exit status.\r
+set +e\r
+DISPLAY=:$SERVERNUM XAUTHORITY=$AUTHFILE "$@" 2>&1\r
+RETVAL=$?\r
+set -e\r
+\r
+# Kill Xvfb now that the command has exited.\r
+kill $XVFBPID\r
+\r
+# Clean up.\r
+XAUTHORITY=$AUTHFILE xauth remove ":$SERVERNUM" >"$ERRORFILE" 2>&1\r
+if [ -n "$XVFB_RUN_TMPDIR" ]; then\r
+ if ! rm -r "$XVFB_RUN_TMPDIR"; then\r
+ error "problem while cleaning up temporary directory"\r
+ exit 5\r
+ fi\r
+fi\r
+\r
+# Return the executed command's exit status.\r
+exit $RETVAL\r
+\r
+# vim:set ai et sts=4 sw=4 tw=80:\r