summaryrefslogtreecommitdiff
path: root/mail/relay-ctrl/files/ifrelayclient.sh
blob: 30242e47c7542d8c581d9c685a7a901a482d4550 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!@SH@
#
# Wrapper for qmail-smtpd command chain that runs the first command
#   only if RELAYCLIENT is set, running the remaining commands
#   regardless. End the first command with "--".
#
# Useful for e.g. setting RBLSMTPD="" to avoid RBL-blocking an
#   authenticated user.

relayclient_isset()
{
	@SETENV@ | @GREP@ -q '^RELAYCLIENT=' >/dev/null 2>&1
}

main()
{
	local cmd1 arg
	cmd1=""
	while [ $# -gt 0 ]; do
		arg="$1"; shift
		if [ "${arg}" = '--' ]; then
			break
		else
			cmd1="${cmd1} ${arg}"
		fi
	done
	if [ $# -eq 0 ]; then
		@ECHO@ >&2 "usage: $0 command args -- command args"
		exit 111
	fi
	if relayclient_isset; then
		exec ${cmd1} "$@"
	else
		exec "$@"
	fi
}

main "$@"
exit $?