13901.1.1
by Gavin Panella
New command, with-xvfb, to run a given command in a standard Xvfb configuration. |
1 |
#!/bin/bash
|
2 |
#
|
|
3 |
# Copyright 2011 Canonical Ltd. This software is licensed under the
|
|
4 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
5 |
#
|
|
6 |
# Wrapper that provides a default Xvfb environment for the given
|
|
7 |
# command.
|
|
8 |
#
|
|
9 |
# If the command is not found it is searched for in the same directory
|
|
10 |
# as this script. This lets you do `bin/with-xvfb iharness` for
|
|
11 |
# example.
|
|
12 |
#
|
|
13901.1.2
by Gavin Panella
Fix/update some comments. |
13 |
# Follows sinzui's advice to the launchpad-dev list:
|
14 |
# https://lists.launchpad.net/launchpad-dev/msg07879.html
|
|
15 |
#
|
|
13901.1.1
by Gavin Panella
New command, with-xvfb, to run a given command in a standard Xvfb configuration. |
16 |
|
17 |
set -eu
|
|
18 |
||
13901.1.2
by Gavin Panella
Fix/update some comments. |
19 |
# Look for $1 - i.e. the command to run - in this script's directory
|
20 |
# if it's not found along the default PATH.
|
|
13901.1.1
by Gavin Panella
New command, with-xvfb, to run a given command in a standard Xvfb configuration. |
21 |
if [ $# -ge 1 ] && ! type -P "$1" > /dev/null |
22 |
then
|
|
23 |
if command="$(PATH="$(dirname "$0")" type -P "$1")" |
|
24 |
then
|
|
25 |
# Shift $1 off and set new positional arguments.
|
|
26 |
shift && set -- "$${command}" "$@" |
|
27 |
fi
|
|
28 |
# If no command has been given and SHELL is set, spawn a shell.
|
|
29 |
elif [ $# -eq 0 -a -n "$${SHELL:-}" ] |
|
30 |
then
|
|
31 |
set -- "$${SHELL}" |
|
32 |
fi
|
|
33 |
||
34 |
#
|
|
35 |
# --auto-servernum
|
|
36 |
# Try to get a free server number, starting at 99. See xvfb-run(1).
|
|
37 |
#
|
|
38 |
# --server-args=
|
|
39 |
# -ac disables host-based access control mechanisms. See Xserver(1).
|
|
40 |
# -screen forces a screen configuration. At the time of writing
|
|
41 |
# there is some disagreement between xvfb-run(1) and Xvfb(1)
|
|
42 |
# about what the default is.
|
|
43 |
#
|
|
44 |
exec xvfb-run \ |
|
45 |
--server-args="-ac -screen 0 1024x768x24" \ |
|
46 |
--auto-servernum -- "$@" |