49 lines
1.7 KiB
Bash
Executable File
49 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
command_name=${0##*/}
|
|
: "${TEST_MOCK_LOG:?TEST_MOCK_LOG must identify the isolated test log}"
|
|
printf '%q' "$command_name" >>"$TEST_MOCK_LOG"
|
|
for argument in "$@"; do printf ' %q' "$argument" >>"$TEST_MOCK_LOG"; done
|
|
printf '\n' >>"$TEST_MOCK_LOG"
|
|
if [[ -n ${MOCK_FLOCK_CHANGE_TO:-} && -z ${MOCK_FLOCK_CHANGED_MARKER:-} && -f $MOCK_FLOCK_CHANGE_TO && -n ${WG_MANAGER_CONFIG:-} ]]; then
|
|
cp -- "$MOCK_FLOCK_CHANGE_TO" "$WG_MANAGER_CONFIG"
|
|
export MOCK_FLOCK_CHANGED_MARKER=1
|
|
fi
|
|
if [[ $# == 2 && $1 == -n && $2 =~ ^[0-9]+$ ]]; then
|
|
[[ ${MOCK_FLOCK_BUSY:-0} == 1 ]] && exit 1
|
|
[[ ${MOCK_FLOCK_FAIL:-0} == 1 ]] && exit 97
|
|
exit 0
|
|
fi
|
|
if [[ $# -ge 3 && $1 == -n && $2 =~ ^[0-9]+$ && ( $3 == printf || $3 == cat ) ]]; then
|
|
[[ ${MOCK_FLOCK_BUSY:-0} == 1 ]] && exit 1
|
|
[[ ${MOCK_FLOCK_FAIL:-0} == 1 ]] && exit 97
|
|
shift 2
|
|
command "$@"
|
|
exit $?
|
|
fi
|
|
if [[ $# == 1 && $1 =~ ^[0-9]+$ || $# == 2 && $1 == -s && $2 =~ ^[0-9]+$ ]]; then
|
|
[[ ${MOCK_FLOCK_BUSY:-0} == 1 ]] && exit 1
|
|
[[ ${MOCK_FLOCK_FAIL:-0} == 1 ]] && exit 97
|
|
real_flock=${REAL_FLOCK:-}
|
|
if [[ -z $real_flock ]]; then
|
|
for candidate in /usr/bin/flock /bin/flock; do
|
|
if [[ -x $candidate ]]; then real_flock=$candidate; break; fi
|
|
done
|
|
fi
|
|
[[ -n $real_flock ]] || exit 98
|
|
exec "$real_flock" "$@"
|
|
fi
|
|
if [[ $# -ge 2 && ( $1 == -s || $1 != -* ) && ${1#-} =~ ^[0-9]+$ || $1 == -s && ${2:-} =~ ^[0-9]+$ ]]; then
|
|
[[ ${MOCK_FLOCK_BUSY:-0} == 1 ]] && exit 1
|
|
[[ ${MOCK_FLOCK_FAIL:-0} == 1 ]] && exit 97
|
|
real_flock=${REAL_FLOCK:-}
|
|
if [[ -z $real_flock ]]; then
|
|
for candidate in /usr/bin/flock /bin/flock; do
|
|
if [[ -x $candidate ]]; then real_flock=$candidate; break; fi
|
|
done
|
|
fi
|
|
[[ -n $real_flock ]] || exit 98
|
|
exec "$real_flock" "$@"
|
|
fi
|
|
exit 99
|