-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7844e1
commit d14205e
Showing
3 changed files
with
354 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
#!/bin/sh | ||
|
||
# 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 and xauth. | ||
|
||
set -e | ||
|
||
PROGNAME=xvfb-run | ||
SERVERNUM=99 | ||
AUTHFILE= | ||
ERRORFILE=/dev/null | ||
XVFBARGS="-screen 0 1280x1024x24" | ||
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 | ||
case "$DEFCOLUMNS" in | ||
*[!0-9]*|'') DEFCOLUMNS=80 ;; | ||
esac | ||
|
||
# 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 <<EOF | ||
Usage: $PROGNAME [OPTION ...] COMMAND | ||
Run COMMAND (usually an X client) in a virtual X server environment. | ||
Options: | ||
-a --auto-servernum try to get a free server number, starting at | ||
--server-num | ||
-e FILE --error-file=FILE file used to store xauth errors and Xvfb | ||
output (default: $ERRORFILE) | ||
-f FILE --auth-file=FILE file used to store auth cookie | ||
(default: ./.Xauthority) | ||
-h --help display this usage message and exit | ||
-n NUM --server-num=NUM server number to use (default: $SERVERNUM) | ||
-l --listen-tcp enable TCP port listening in the X server | ||
-p PROTO --xauth-protocol=PROTO X authority protocol name to use | ||
(default: xauth command's default) | ||
-s ARGS --server-args=ARGS arguments (other than server number and | ||
"-nolisten tcp") to pass to the Xvfb server | ||
(default: "$XVFBARGS") | ||
EOF | ||
} | ||
|
||
# Find a free server number by looking at .X*-lock files in /tmp. | ||
find_free_servernum() { | ||
# Sadly, the "local" keyword is not POSIX. Leave the next line commented in | ||
# the hope Debian Policy eventually changes to allow it in /bin/sh scripts | ||
# anyway. | ||
#local i | ||
|
||
i=$SERVERNUM | ||
while [ -f /tmp/.X$i-lock ]; do | ||
i=$(($i + 1)) | ||
done | ||
echo $i | ||
} | ||
|
||
# Clean up files | ||
clean_up() { | ||
if [ -e "$AUTHFILE" ]; then | ||
XAUTHORITY=$AUTHFILE xauth remove ":$SERVERNUM" >>"$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 | ||
if [ -n "$XVFBPID" ]; then | ||
kill "$XVFBPID" >>"$ERRORFILE" 2>&1 | ||
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) 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 ! command -v 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.XXXXXX)" | ||
AUTHFILE="$XVFB_RUN_TMPDIR/Xauthority" | ||
# Create empty file to avoid xauth warning | ||
touch "$AUTHFILE" | ||
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 $XAUTHPROTO $MCOOKIE | ||
EOF | ||
# handle SIGUSR1 so Xvfb knows to send a signal when it's ready to accept | ||
# connections | ||
trap : USR1 | ||
(trap '' USR1; exec Xvfb ":$SERVERNUM" $XVFBARGS $LISTENTCP -auth $AUTHFILE >>"$ERRORFILE" 2>&1) & | ||
XVFBPID=$! | ||
|
||
wait || : | ||
if kill -0 $XVFBPID 2>/dev/null; then | ||
break | ||
elif [ -n "$AUTONUM" ]; then | ||
# The display is in use so try another one (if '-a' was specified). | ||
SERVERNUM=$((SERVERNUM + 1)) | ||
SERVERNUM=$(find_free_servernum) | ||
continue | ||
fi | ||
error "Xvfb failed to start" >&2 | ||
XVFBPID= | ||
exit 1 | ||
done | ||
|
||
# Start the command and save its exit status. | ||
set +e | ||
DISPLAY=:$SERVERNUM XAUTHORITY=$AUTHFILE "$@" | ||
RETVAL=$? | ||
set -e | ||
|
||
# Return the executed command's exit status. | ||
exit $RETVAL | ||
|
||
# vim:set ai et sts=4 sw=4 tw=80: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
{ | ||
"name": "xvfb", | ||
"buildsystem": "meson", | ||
"build-options": { | ||
"prepend-path": "/app/build_staging/xvfb/bin", | ||
"prepend-ld-library-path": "/app/build_staging/xvfb/lib", | ||
"prepend-pkg-config-path": "/app/build_staging/xvfb/lib/pkgconfig", | ||
"env": { | ||
"LPATH": "/app/build_staging/xvfb/lib" | ||
} | ||
}, | ||
"config-opts": [ | ||
"--prefix=/app/build_staging/xvfb", | ||
"-Dxorg=true", | ||
"-Dxvfb=true", | ||
"-Dhal=false" | ||
], | ||
"sources": [ | ||
{ | ||
"type": "archive", | ||
"url": "https://gitlab.freedesktop.org/xorg/xserver/-/archive/xorg-server-21.1.9/xserver-xorg-server-21.1.9.tar.bz2", | ||
"sha256": "6039a5f77e3936a51fac7eb17b719f5e97c846c24094555c482efd648b9479c0" | ||
}, | ||
{ | ||
"type": "file", | ||
"path": "xvfb-run" | ||
} | ||
], | ||
"post-install": [ | ||
"install -c -m 755 ${FLATPAK_BUILDER_BUILDDIR}/xvfb-run /app/build_staging/xvfb/bin/xvfb-run" | ||
], | ||
"modules": [ | ||
{ | ||
"name": "libxcvt", | ||
"buildsystem": "meson", | ||
"sources": [ | ||
{ | ||
"type": "archive", | ||
"url": "https://gitlab.freedesktop.org/xorg/lib/libxcvt/-/archive/libxcvt-0.1.2/libxcvt-libxcvt-0.1.2.tar.bz2", | ||
"sha256": "590e5a6da87ace7aa7857026b207a2c4d378620035441e20ea97efedd15d6d4a" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "xvfb-libXmu", | ||
"buildsystem": "simple", | ||
"build-commands": [ | ||
"./configure --prefix=/app/build_staging/xvfb --exec_prefix=/app/build_staging/xvfb", | ||
"make", | ||
"make install" | ||
], | ||
"sources": [ | ||
{ | ||
"type": "archive", | ||
"url": "https://xorg.freedesktop.org/archive/individual/lib/libXmu-1.1.3.tar.gz", | ||
"sha256": "5bd9d4ed1ceaac9ea023d86bf1c1632cd3b172dce4a193a72a94e1d9df87a62e" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "xvfb-libfontenc", | ||
"buildsystem": "simple", | ||
"build-commands": [ | ||
"./configure --prefix=/app/build_staging/xvfb --exec_prefix=/app/build_staging/xvfb", | ||
"make", | ||
"make install" | ||
], | ||
"sources": [ | ||
{ | ||
"type": "archive", | ||
"url": "https://xorg.freedesktop.org/archive/individual/lib/libfontenc-1.1.4.tar.bz2", | ||
"sha256": "2cfcce810ddd48f2e5dc658d28c1808e86dcf303eaff16728b9aa3dbc0092079" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "xvfb-libtirpc", | ||
"buildsystem": "simple", | ||
"build-commands": [ | ||
"./configure --prefix=/app/build_staging/xvfb --exec_prefix=/app/build_staging/xvfb --disable-gssapi", | ||
"make", | ||
"make install" | ||
], | ||
"sources": [ | ||
{ | ||
"type": "archive", | ||
"url": "https://downloads.sourceforge.net/sourceforge/libtirpc/libtirpc-1.3.2.tar.bz2", | ||
"sha256": "e24eb88b8ce7db3b7ca6eb80115dd1284abc5ec32a8deccfed2224fc2532b9fd" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "xvfb-font-util", | ||
"buildsystem": "simple", | ||
"build-commands": [ | ||
"./configure --prefix=/app/build_staging/xvfb --exec_prefix=/app/build_staging/xvfb", | ||
"make", | ||
"make install" | ||
], | ||
"sources": [ | ||
{ | ||
"type": "archive", | ||
"url": "https://xorg.freedesktop.org/archive/individual/font/font-util-1.3.2.tar.bz2", | ||
"sha256": "3ad880444123ac06a7238546fa38a2a6ad7f7e0cc3614de7e103863616522282" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "xvfb-libXfont2", | ||
"buildsystem": "simple", | ||
"build-options": { | ||
"prepend-path": "/app/build_staging/xvfb/bin", | ||
"prepend-ld-library-path": "/app/build_staging/xvfb/lib", | ||
"prepend-pkg-config-path": "/app/build_staging/xvfb/lib/pkgconfig" | ||
}, | ||
"build-commands": [ | ||
"./configure --prefix=/app/build_staging/xvfb --exec_prefix=/app/build_staging/xvfb", | ||
"make", | ||
"make install" | ||
], | ||
"sources": [ | ||
{ | ||
"type": "archive", | ||
"url": "https://xorg.freedesktop.org/archive/individual/lib/libXfont2-2.0.4.tar.bz2", | ||
"sha256": "6d151b3368e5035efede4b6264c0fdc6662c1c99dbc2de425e3480cababc69e6" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "xvfb-xauth", | ||
"buildsystem": "simple", | ||
"build-options": { | ||
"prepend-path": "/app/build_staging/xvfb/bin", | ||
"prepend-ld-library-path": "/app/build_staging/xvfb/lib", | ||
"prepend-pkg-config-path": "/app/build_staging/xvfb/lib/pkgconfig" | ||
}, | ||
"build-commands": [ | ||
"./autogen.sh --prefix=/app/build_staging/xvfb --exec_prefix=/app/build_staging/xvfb", | ||
"make", | ||
"make install" | ||
], | ||
"sources": [ | ||
{ | ||
"type": "archive", | ||
"url": "https://gitlab.freedesktop.org/xorg/app/xauth/-/archive/xauth-1.1.1/xauth-xauth-1.1.1.tar.bz2", | ||
"sha256": "921231133efd77091788afaf177e437922c727976391434cfcbffb95b77be81a" | ||
} | ||
] | ||
} | ||
] | ||
} |