#!/bin/sh # --- T2-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # T2 SDE: package/.../xorg-server/xvfb-run.sh # Copyright (C) 2005 The T2 SDE Project # Copyright (C) XXXX - 2005 Debian # # More information can be found in the files COPYING and README. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. A copy of the # GNU General Public License can be found in the file COPYING. # --- T2-COPYRIGHT-NOTE-END --- # $Id$ # from: http://necrotic.deadbeast.net/xsf/XFree86/trunk/debian/local/xvfb-run # This script starts an instance of Xvfb, the "fake" X server, runs a command # with that server available, and kills the X server when done. The return # value of the command becomes the return value of this script. # # If anyone is using this to build a Debian package, make sure the package # Build-Depends on xvfb, xbase-clients, and xfonts-base. set -e PROGNAME=xvfb-run SERVERNUM=99 AUTHFILE= ERRORFILE=/dev/null STARTWAIT=3 XVFBARGS="-screen 0 640x480x8" LISTENTCP="-nolisten tcp" XAUTHPROTO=. # Query the terminal to establish a default number of columns to use for # displaying messages to the user. This is used only as a fallback in the event # the COLUMNS variable is not set. ($COLUMNS can react to SIGWINCH while the # script is running, and this cannot, only being calculated once.) DEFCOLUMNS=$(stty size 2>/dev/null | awk '{print $2}') || true if ! expr "$DEFCOLUMNS" : "[[:digit:]]\+$" >/dev/null 2>&1; then DEFCOLUMNS=80 fi # Display a message, wrapping lines at the terminal width. message () { echo "$PROGNAME: $*" | fmt -t -w ${COLUMNS:-$DEFCOLUMNS} } # Display an error message. error () { message "error: $*" >&2 } # Display a usage message. usage () { if [ -n "$*" ]; then message "usage error: $*" fi cat <&2 exit 2 fi if ! which xauth >/dev/null; then error "xauth command not found" exit 3 fi # Set up the temp dir for the pid and X authorization file XVFB_RUN_TMPDIR="$(mktemp --directory --tmpdir $PROGNAME.XXXXXX)" # If the user did not specify an X authorization file to use, set up a temporary # directory to house one. if [ -z "$AUTHFILE" ]; then AUTHFILE=$(mktemp -p "$XVFB_RUN_TMPDIR" Xauthority.XXXXXX) fi # Start Xvfb. MCOOKIE=$(mcookie) if [ -z "$AUTO_DISPLAY" ]; then # Old style using a pre-computed SERVERNUM XAUTHORITY=$AUTHFILE Xvfb ":$SERVERNUM" $XVFBARGS $LISTENTCP >>"$ERRORFILE" \ 2>&1 & XVFBPID=$! else # New style using Xvfb to provide a free display PIDFILE=$(mktemp -p "$XVFB_RUN_TMPDIR" pid.XXXXXX) SERVERNUM=$(XAUTHORITY=$AUTHFILE Xvfb -displayfd 9 $XVFBARGS $LISTENTCP \ 9>&1 2>"$ERRORFILE" & echo $! > $PIDFILE) XVFBPID=$(cat $PIDFILE) fi sleep "$STARTWAIT" XAUTHORITY=$AUTHFILE xauth source - << EOF >>"$ERRORFILE" 2>&1 add :$SERVERNUM $XAUTHPROTO $MCOOKIE EOF # Start the command and save its exit status. set +e DISPLAY=:$SERVERNUM XAUTHORITY=$AUTHFILE "$@" 2>&1 RETVAL=$? set -e # Kill Xvfb now that the command has exited. kill $XVFBPID # Clean up. XAUTHORITY=$AUTHFILE xauth remove ":$SERVERNUM" >"$ERRORFILE" 2>&1 if [ -n "$XVFB_RUN_TMPDIR" ]; then if ! rm -r "$XVFB_RUN_TMPDIR"; then error "problem while cleaning up temporary directory" exit 5 fi fi # Return the executed command's exit status. exit $RETVAL # vim:set ai et sts=4 sw=4 tw=80: