3 # This script starts an instance of Xvfb, the "fake" X server, runs a command
 
   4 # with that server available, and kills the X server when done.  The return
 
   5 # value of the command becomes the return value of this script.
 
   7 # This is a stripped-down version of the 'xvfb-run' script provided by
 
   8 # Debian's 'xvfb' package which itself is licensed under the GPL, just as
 
   9 # Lx-Office is. It is unclear who wrote the original script, but the
 
  10 # CVS Id tag mentioned 'branden'.
 
  19 XVFBARGS="-screen 0 640x480x8"
 
  20 LISTENTCP="-nolisten tcp"
 
  23 # Query the terminal to establish a default number of columns to use for
 
  24 # displaying messages to the user.  This is used only as a fallback in the event
 
  25 # the COLUMNS variable is not set.  ($COLUMNS can react to SIGWINCH while the
 
  26 # script is running, and this cannot, only being calculated once.)
 
  27 DEFCOLUMNS=$(stty size 2>/dev/null | awk '{print $2}') || true
 
  28 if ! expr "$DEFCOLUMNS" : "[[:digit:]]\+$" >/dev/null 2>&1; then
 
  32 # Display a message, wrapping lines at the terminal width.
 
  34     echo "$PROGNAME: $*" | fmt -t -w ${COLUMNS:-$DEFCOLUMNS}
 
  37 # Display an error message.
 
  39     message "error: $*" >&2
 
  42 # Find a free server number by looking at .X*-lock files in /tmp.
 
  43 find_free_servernum() {
 
  44     # Sadly, the "local" keyword is not POSIX.  Leave the next line commented in
 
  45     # the hope Debian Policy eventually changes to allow it in /bin/sh scripts
 
  50     while [ -f /tmp/.X$i-lock ]; do
 
  56 SERVERNUM=$(find_free_servernum)
 
  58 PATH=$PATH:/usr/bin/x11:/usr/X11R6/bin
 
  60 if ! which xauth >/dev/null; then
 
  61     error "xauth command not found"
 
  65 # If the user did not specify an X authorization file to use, set up a temporary
 
  66 # directory to house one.
 
  67 XVFB_RUN_TMPDIR="${TMPDIR:-/tmp}/$PROGNAME.$$"
 
  68 if ! mkdir -p -m 700 "$XVFB_RUN_TMPDIR"; then
 
  69   error "temporary directory $XVFB_RUN_TMPDIR already exists"
 
  72 AUTHFILE=$(tempfile -n "$XVFB_RUN_TMPDIR/Xauthority")
 
  76 XAUTHORITY=$AUTHFILE xauth add ":$SERVERNUM" "$XAUTHPROTO" "$MCOOKIE" \
 
  78 XAUTHORITY=$AUTHFILE Xvfb ":$SERVERNUM" $XVFBARGS $LISTENTCP >"$ERRORFILE" \
 
  83 # Start the command and save its exit status.
 
  85 DISPLAY=:$SERVERNUM XAUTHORITY=$AUTHFILE "$@" 2>&1
 
  89 # Kill Xvfb now that the command has exited.
 
  93 XAUTHORITY=$AUTHFILE xauth remove ":$SERVERNUM" >"$ERRORFILE" 2>&1
 
  94 if [ -n "$XVFB_RUN_TMPDIR" ]; then
 
  95     if ! rm -r "$XVFB_RUN_TMPDIR"; then
 
  96         error "problem while cleaning up temporary directory"
 
 101 # Return the executed command's exit status.