Bug#876058: xvfb-run does not use /bin/bash in shebang line

2019-02-04 Thread Joel Rabinovitch
Hi,

As part of fixing issue 617851 in the xvfb-run script, I had added a check to 
make sure that the script is using a Korn(-like) shell.

Specifically, this code was added:

#
# Make sure we are running in a Korn(-like) shell.
#

set +e

HOME_DIR=`cd ~ 2>/dev/null`

if test $? -ne 0
then
   echo "$PROGNAME: This script must be run using a Korn or Bash shell."
   exit 7
fi

set -e

Thanks,

Joel





Bug#617851: xvfb-run only works on Linux systems

2011-03-11 Thread Joel Rabinovitch
Package: xvfb
Version: 1.9.4.901-1

It seems that there are differences between the Xvfb command for Linux
(Debian/RedHat), AIX and Solaris.

I have patched the script so that it works on AIX and Solaris, in
addition to Linux. I have tested the script on AIX 6.1 and Solaris Sparc
10.

The following changes were made:

 It checks if the script is running in a Korn(-like) or Bash(-like)
shell. If it isn't, exit code 7 is returned. The reason is that on
Solaris, /bin/sh is linked to the standard Bourne shell.

On AIX, there is no Xvfb command. The standard X command is used
instead.

The default arguments used by the xvfb-run script when running Xvfb are
different between Linux, AIX and Solaris. The script uses the correct
arguments based on the operating system being used.

It checks if the GNU version of getopt is installed. If it isn't, then,
the standard version of getopt is used and  long options are disabled.

It checks if the tempfile command is installed. If it is, it used,
otherwise, mktemp is used as it was in previous versions of the script.
I also ported a fix from RedHat's version of Xvfb-run in terms of using
the mktemp script. Details of the fix are here:
https://bugzilla.redhat.com/show_bug.cgi?id=508739 and here:
https://bugzilla.redhat.com/show_bug.cgi?id=632879.

If the mcookie utility is not installed, it is simulated based on code
found at the following URL:
http://git.debian.org/?p=pkg-xorg/app/xinit.git;a=blob_plain;f=configure
.ac;hb=HEAD. By default, I am using the /dev/urandom device. If security
is an issue, it can be changed to use the /dev/random device instead.

Here is the original version of the file:

Xvfb-run.orig


#!/bin/sh

# $Id: xvfb-run 2027 2004-11-16 14:54:16Z branden $

# 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 <>"$ERRORFILE"
2>&1
fi
if [ -n "$XVFB_RUN_TMPDIR" ]; then
if ! rm -r "$XVFB_RUN_TMPDIR"; then
error "problem while cleaning up temporary directory"
exit 5
fi
fi
}

# Parse the command line.
ARGS=$(getopt --options +ae:f:hn:lp:s:w: \
   --long
auto-servernum,error-file:,auth-file:,help,server-num:,listen-tcp,xauth-
protocol:,server-args:,wait: \
   --name "$PROGNAME" -- "$@")
GETOPT_STATUS=$?

if [ $GETOPT_STATUS -ne 0 ]; then
error "internal error; getopt exited with status $GETOPT_STATUS"
exit 6
fi

eval set -- "$ARGS"

while :; do
case "$1" in
-a|--auto-servernum) SERVERNUM=$(find_free_servernum);
AUTONUM="yes" ;;
-e|--error-file) ERRORFILE="$2"; shift ;;
-f|--auth-file) AUTHFILE="$2"; shift ;;
-h|--help) SHOWHELP="yes" ;;
-n|--server-num) SERVERNUM="$2"; shift ;;
-l|--listen-tcp) LISTENTCP="" ;;
-p|--xauth-protocol) XAUTHPROTO="$2"; shift ;;
-s|--server-args) XVFBARGS="$2"; shift ;;
-w|--wait) STARTWAIT="$2"; shift ;;
--) shift; break ;;
*) error "internal error; getopt permitted \"$1\" unexpectedly"
   exit 6
   ;;
esac
shift
done

if [ "$SHOWHELP" ]; then
usage
exit 0
fi

if [ -z "$*" ]; then
usage "need a command to run" >&2
exit 2
fi

if ! which xauth >/dev/null; then
error "xauth command not found"
exit 3
fi

# tidy up after ourselves
trap clean_up EXIT

# If the user did not specify an X authorization file to use, set up a
temporary
# directory to house one.
if [ -z "$AUTHFILE" ]; then
XVFB_RUN_TMPDIR="$(mktemp -d -t $PROGNAME.XX)"
# Create empty file to avoid xauth warning
AUTHFILE=$(tempfile -n "$XVFB_RUN_TMPDIR/Xauthority")
fi

# Start Xvfb.
MCOOKIE=$(mcookie)
tries=10
while [ $tries -gt 0 ]; do
tries=$(( $tries - 1 ))
XAUTHORITY=$AUTHFILE xauth source - << EOF >>"$ERRORFILE" 2>&1
add :$SERVERNUM $XAUTH