1 # Hey Emacs, this is a -*- shell-script -*- !!! :-)
3 # Common variables and functions for all CTDB tests.
5 # Print a message and exit.
8 echo "$1" >&2 ; exit ${2:-1}
11 # This expands the most probable problem cases like "." and "..".
12 TEST_SUBDIR=$(dirname "$0")
13 if [ $(dirname "$TEST_SUBDIR") = "." ] ; then
14 TEST_SUBDIR=$(cd "$TEST_SUBDIR" ; pwd)
17 # If we are running from within the source tree then, depending on the
18 # tests that we're running, we may need to add the top level bin/ and
19 # tools/ subdirectories to $PATH. In this case, sanity check that
20 # run_tests.sh is in the expected place.
21 if ! $CTDB_TESTS_ARE_INSTALLED ; then
22 if [ ! -f "${CTDB_TEST_DIR}/run_tests.sh" ] ; then
23 die "Tests not installed but can't find run_tests.sh"
26 ctdb_dir=$(dirname "$CTDB_TEST_DIR")
28 top_dir=$(cd -P "$ctdb_dir" && echo "$PWD") # real path
29 if [ ! -d "${top_dir}/bin" ] ; then
30 top_dir=$(dirname "$top_dir")
34 . "${TEST_SCRIPTS_DIR}/script_install_paths.sh"
36 if [ -d "$CTDB_SCRIPTS_TOOLS_BIN_DIR" ] ; then
37 PATH="${CTDB_SCRIPTS_TOOLS_BIN_DIR}:${PATH}"
40 if [ -d "$CTDB_SCRIPTS_TESTS_BINDIR" ] ; then
41 PATH="${CTDB_SCRIPTS_TESTS_BINDIR}:${PATH}"
44 # Wait until either timeout expires or command succeeds. The command
45 # will be tried once per second, unless timeout has format T/I, where
46 # I is the recheck interval.
49 local timeout="$1" ; shift # "$@" is the command...
54 interval="${timeout#*/}"
55 timeout="${timeout%/*}"
59 if [ "$1" = "!" ] ; then
64 echo -n "<${timeout}|"
66 while [ $t -gt 0 ] ; do
69 if { ! $negate && [ $rc -eq 0 ] ; } || \
70 { $negate && [ $rc -ne 0 ] ; } ; then
71 echo "|$(($timeout - $t))|"
76 for i in $(seq 1 $interval) ; do
88 # setup_ctdb_base <parent> <subdir> [item-to-copy]...
91 [ $# -ge 2 ] || die "usage: setup_ctdb_base <parent> <subdir> [item]..."
92 # If empty arguments are passed then we attempt to remove /
93 # (i.e. the root directory) below
94 [ -n "$1" -a -n "$2" ] || \
95 die "usage: setup_ctdb_base <parent> <subdir> [item]..."
100 # Other arguments are files/directories to copy
103 export CTDB_BASE="${_parent}/${_subdir}"
104 if [ -d "$CTDB_BASE" ] ; then
107 mkdir -p "$CTDB_BASE" || die "Failed to create CTDB_BASE=$CTDB_BASE"
108 mkdir -p "${CTDB_BASE}/run" || die "Failed to create ${CTDB_BASE}/run"
109 mkdir -p "${CTDB_BASE}/var" || die "Failed to create ${CTDB_BASE}/var"
112 cp -pr "${CTDB_SCRIPTS_BASE}/${_i}" "${CTDB_BASE}/"
115 for _i in "${TEST_SUBDIR}/etc-ctdb/"* ; do
116 # No/empty etc-ctdb directory
117 [ -e "$_i" ] || break
119 cp -pr "$_i" "${CTDB_BASE}/"