Error if expected environment variables are unset
This commit is contained in:
parent
2270c32ddb
commit
231f96de18
6 changed files with 52 additions and 50 deletions
|
@ -23,18 +23,18 @@ drop_awk_comments() { sed '/^[[:blank:]]*#.*$/d;/^$/d' "$@"; }
|
||||||
CONF_PATH=/etc/dma # set in Makefile
|
CONF_PATH=/etc/dma # set in Makefile
|
||||||
|
|
||||||
# Determine mailname
|
# Determine mailname
|
||||||
if test -f "${__object}/parameter/mailname"
|
if test -f "${__object:?}/parameter/mailname"
|
||||||
then
|
then
|
||||||
mailname=$(cat "${__object}/parameter/mailname")
|
mailname=$(cat "${__object:?}/parameter/mailname")
|
||||||
else
|
else
|
||||||
case $(cat "${__global}/explorer/os")
|
case $(cat "${__global:?}/explorer/os")
|
||||||
in
|
in
|
||||||
(debian|devuan|ubuntu)
|
(debian|devuan|ubuntu)
|
||||||
# On Debian-like systems use /etc/mailname unless --mailname is used
|
# On Debian-like systems use /etc/mailname unless --mailname is used
|
||||||
mailname='/etc/mailname'
|
mailname='/etc/mailname'
|
||||||
;;
|
;;
|
||||||
(*)
|
(*)
|
||||||
mailname=$__target_fqdn
|
mailname=${__target_fqdn:?}
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
@ -42,19 +42,19 @@ fi
|
||||||
|
|
||||||
# Generate "should" values for config
|
# Generate "should" values for config
|
||||||
conf_should=$(
|
conf_should=$(
|
||||||
if test -s "${__object}/parameter/smarthost"
|
if test -s "${__object:?}/parameter/smarthost"
|
||||||
then
|
then
|
||||||
printf 'SMARTHOST %s\n' "$(cat "${__object}/parameter/smarthost")"
|
printf 'SMARTHOST %s\n' "$(cat "${__object:?}/parameter/smarthost")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf 'MAILNAME %s\n' "${mailname}"
|
printf 'MAILNAME %s\n' "${mailname}"
|
||||||
|
|
||||||
if test -s "${__object}/explorer/auth_conf"
|
if test -s "${__object:?}/explorer/auth_conf"
|
||||||
then
|
then
|
||||||
printf "AUTHPATH %s\n" "$(cat "${__object}/explorer/auth_conf")"
|
printf "AUTHPATH %s\n" "$(cat "${__object:?}/explorer/auth_conf")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case $(cat "${__object}/parameter/security")
|
case $(cat "${__object:?}/parameter/security")
|
||||||
in
|
in
|
||||||
(ssl|tls)
|
(ssl|tls)
|
||||||
default_smtp_port=465
|
default_smtp_port=465
|
||||||
|
@ -77,35 +77,35 @@ conf_should=$(
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if test -s "${__object}/parameter/port"
|
if test -s "${__object:?}/parameter/port"
|
||||||
then
|
then
|
||||||
printf 'PORT %u\n' "$(cat "${__object}/parameter/port")"
|
printf 'PORT %u\n' "$(cat "${__object:?}/parameter/port")"
|
||||||
elif test "${default_smtp_port}" -ne 25 # DMA uses port 25 by default
|
elif test "${default_smtp_port}" -ne 25 # DMA uses port 25 by default
|
||||||
then
|
then
|
||||||
printf 'PORT %u\n' "${default_smtp_port}"
|
printf 'PORT %u\n' "${default_smtp_port}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -f "${__object}/parameter/masquerade"
|
if test -f "${__object:?}/parameter/masquerade"
|
||||||
then
|
then
|
||||||
while read -r line
|
while read -r line
|
||||||
do
|
do
|
||||||
printf 'MASQUERADE %s\n' "${line}"
|
printf 'MASQUERADE %s\n' "${line}"
|
||||||
done <"${__object}/parameter/masquerade"
|
done <"${__object:?}/parameter/masquerade"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -f "${__object}/parameter/defer"
|
if test -f "${__object:?}/parameter/defer"
|
||||||
then
|
then
|
||||||
echo 'DEFER'
|
echo 'DEFER'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -f "${__object}/parameter/fullbounce"
|
if test -f "${__object:?}/parameter/fullbounce"
|
||||||
then
|
then
|
||||||
echo 'FULLBOUNCE'
|
echo 'FULLBOUNCE'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -f "${__object}/parameter/nullclient"
|
if test -f "${__object:?}/parameter/nullclient"
|
||||||
then
|
then
|
||||||
test -s "${__object}/parameter/smarthost" || {
|
test -s "${__object:?}/parameter/smarthost" || {
|
||||||
echo '--nullclient requires a --smarthost to be defined' >&2
|
echo '--nullclient requires a --smarthost to be defined' >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
@ -114,10 +114,10 @@ conf_should=$(
|
||||||
fi
|
fi
|
||||||
)
|
)
|
||||||
# Sort conf_should to compare against "conf_is"
|
# Sort conf_should to compare against "conf_is"
|
||||||
conf_should=$(echo "$conf_should" | sort -s -k 1,1)
|
conf_should=$(echo "${conf_should}" | sort -s -k 1,1)
|
||||||
|
|
||||||
config_updated=false
|
config_updated=false
|
||||||
if ! echo "$conf_should" | cmp -s "${__object}/explorer/conf" -
|
if ! echo "${conf_should}" | cmp -s "${__object:?}/explorer/conf" -
|
||||||
then
|
then
|
||||||
# config needs to be updated
|
# config needs to be updated
|
||||||
dma_conf="${CONF_PATH:?}/dma.conf"
|
dma_conf="${CONF_PATH:?}/dma.conf"
|
||||||
|
@ -140,7 +140,7 @@ then
|
||||||
# at the end of the file.
|
# at the end of the file.
|
||||||
|
|
||||||
cat <<CODE
|
cat <<CODE
|
||||||
awk '$(drop_awk_comments "${__type}/files/update_dma_conf.awk")' '${dma_conf}' '${dma_conf}' <<'EOF' >'${dma_conf}.tmp' \
|
awk '$(drop_awk_comments "${__type:?}/files/update_dma_conf.awk")' '${dma_conf}' '${dma_conf}' <<'EOF' >'${dma_conf}.tmp' \
|
||||||
&& cat '${dma_conf}.tmp' >'${dma_conf}'
|
&& cat '${dma_conf}.tmp' >'${dma_conf}'
|
||||||
${conf_should}
|
${conf_should}
|
||||||
EOF
|
EOF
|
||||||
|
@ -148,28 +148,28 @@ rm '${dma_conf}.tmp'
|
||||||
CODE
|
CODE
|
||||||
|
|
||||||
config_updated=true
|
config_updated=true
|
||||||
echo 'config updated' >>"${__messages_out}"
|
echo 'config updated' >>"${__messages_out:?}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if test -f "${__object}/parameter/send-test-email"
|
if test -f "${__object:?}/parameter/send-test-email"
|
||||||
then
|
then
|
||||||
if grep -q '^__mail_alias/root:' "${__messages_in}" \
|
if grep -q '^__mail_alias/root:' "${__messages_in:?}" \
|
||||||
|| grep -q '^__dma_auth/' "${__messages_in}" \
|
|| grep -q '^__dma_auth/' "${__messages_in:?}" \
|
||||||
|| $config_updated
|
|| $config_updated
|
||||||
then
|
then
|
||||||
cat <<-EOF
|
cat <<-CODE
|
||||||
sendmail root <<EOM
|
sendmail root <<'EOF'
|
||||||
Subject: [cdist] Test mail from '${__target_fqdn}'
|
Subject: [cdist] Test mail from '${__target_fqdn:?}'
|
||||||
|
|
||||||
Hi,
|
Hi,
|
||||||
|
|
||||||
you can ignore this message.
|
you can ignore this message.
|
||||||
Its sole purpose is to notify you that root mail on ${__target_fqdn}
|
Its sole purpose is to notify you that root mail on ${__target_fqdn:?}
|
||||||
will be redirected to you.
|
will be redirected to you.
|
||||||
|
|
||||||
Enjoy!
|
Enjoy!
|
||||||
EOM
|
|
||||||
EOF
|
EOF
|
||||||
|
CODE
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
os=$(cat "${__global}/explorer/os")
|
os=$(cat "${__global:?}/explorer/os")
|
||||||
|
|
||||||
# Install DMA
|
# Install DMA
|
||||||
case $os
|
case $os
|
||||||
|
|
|
@ -20,14 +20,14 @@
|
||||||
|
|
||||||
drop_awk_comments() { sed '/^[[:blank:]]*#.*$/d;/^$/d' "$@"; }
|
drop_awk_comments() { sed '/^[[:blank:]]*#.*$/d;/^$/d' "$@"; }
|
||||||
|
|
||||||
state_is=$(cat "${__object}/explorer/state")
|
state_is=$(cat "${__object:?}/explorer/state")
|
||||||
state_should=$(cat "${__object}/parameter/state")
|
state_should=$(cat "${__object:?}/parameter/state")
|
||||||
|
|
||||||
server=$__object_id
|
server=${__object_id:?}
|
||||||
login=$(cat "${__object}/parameter/login")
|
login=$(cat "${__object:?}/parameter/login")
|
||||||
|
|
||||||
|
|
||||||
auth_conf=$(cat "${__object}/explorer/auth_conf")
|
auth_conf=$(cat "${__object:?}/explorer/auth_conf")
|
||||||
test -n "${auth_conf}" || {
|
test -n "${auth_conf}" || {
|
||||||
echo 'Cannot determine path of dma auth.conf' >&2
|
echo 'Cannot determine path of dma auth.conf' >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -46,13 +46,13 @@ in
|
||||||
|
|
||||||
if test "${state_is}" = 'absent'
|
if test "${state_is}" = 'absent'
|
||||||
then
|
then
|
||||||
printf 'add authuser %s on %s\n' "${login}" "${server}" >>"${__messages_out}"
|
printf 'add authuser %s on %s\n' "${login}" "${server}" >>"${__messages_out:?}"
|
||||||
else
|
else
|
||||||
printf 'set authuser %s on %s\n' "${login}" "${server}" >>"${__messages_out}"
|
printf 'set authuser %s on %s\n' "${login}" "${server}" >>"${__messages_out:?}"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
(absent)
|
(absent)
|
||||||
printf 'delete authuser %s on %s\n' "${login}" "${server}" >>"${__messages_out}"
|
printf 'delete authuser %s on %s\n' "${login}" "${server}" >>"${__messages_out:?}"
|
||||||
;;
|
;;
|
||||||
(*)
|
(*)
|
||||||
printf 'Invalid --state: %s.\n' "${state_should}" >&2
|
printf 'Invalid --state: %s.\n' "${state_should}" >&2
|
||||||
|
@ -65,7 +65,7 @@ esac
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
test -f "${auth_conf}" || touch "${auth_conf}"
|
test -f "${auth_conf}" || touch "${auth_conf}"
|
||||||
|
|
||||||
awk '$(drop_awk_comments "${__type}/files/update_dma_auth.awk")' <'${auth_conf}' >'${auth_conf}.tmp' \
|
awk '$(drop_awk_comments "${__type:?}/files/update_dma_auth.awk")' <'${auth_conf}' >'${auth_conf}.tmp' \
|
||||||
&& cat '${auth_conf}.tmp' >'${auth_conf}'
|
&& cat '${auth_conf}.tmp' >'${auth_conf}'
|
||||||
rm -f '${auth_conf}.tmp'
|
rm -f '${auth_conf}.tmp'
|
||||||
EOF
|
EOF
|
||||||
|
|
|
@ -20,9 +20,11 @@
|
||||||
# Find aliases for a given user name and print the aliases (each one on a
|
# Find aliases for a given user name and print the aliases (each one on a
|
||||||
# separate line)
|
# separate line)
|
||||||
|
|
||||||
aliases_file=$("${__type_explorer}/aliases_file")
|
aliases_file=$("${__type_explorer:?}/aliases_file")
|
||||||
test -r "${aliases_file}" || exit 0
|
test -r "${aliases_file}" || exit 0
|
||||||
|
|
||||||
|
: "${__object_id:?}" # assert __object_id is set, because it is used in AWK
|
||||||
|
|
||||||
awk -F ':[ \t]*' '
|
awk -F ':[ \t]*' '
|
||||||
function print_aliases(aliases, matches) {
|
function print_aliases(aliases, matches) {
|
||||||
# prints comma-separated aliases (one per line)
|
# prints comma-separated aliases (one per line)
|
||||||
|
|
|
@ -28,7 +28,7 @@ check_file() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
case $("${__explorer}/os")
|
case $("${__explorer:?}/os")
|
||||||
in
|
in
|
||||||
(freebsd|openbsd|solaris)
|
(freebsd|openbsd|solaris)
|
||||||
check_file /etc/mail/aliases
|
check_file /etc/mail/aliases
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
drop_awk_comments() { sed '/^[[:blank:]]*#.*$/d;/^$/d' "$@"; }
|
drop_awk_comments() { sed '/^[[:blank:]]*#.*$/d;/^$/d' "$@"; }
|
||||||
|
|
||||||
aliases_file=$(cat "${__object}/explorer/aliases_file")
|
aliases_file=$(cat "${__object:?}/explorer/aliases_file")
|
||||||
|
|
||||||
test -n "${aliases_file}" || {
|
test -n "${aliases_file}" || {
|
||||||
echo 'Could not determine aliases file path.' >&2
|
echo 'Could not determine aliases file path.' >&2
|
||||||
|
@ -28,29 +28,29 @@ test -n "${aliases_file}" || {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
state_should=$(cat "${__object}/parameter/state")
|
state_should=$(cat "${__object:?}/parameter/state")
|
||||||
|
|
||||||
case $state_should
|
case $state_should
|
||||||
in
|
in
|
||||||
(present)
|
(present)
|
||||||
if cmp -s "${__object}/explorer/aliases" "${__object}/parameter/alias"
|
if cmp -s "${__object:?}/explorer/aliases" "${__object:?}/parameter/alias"
|
||||||
then
|
then
|
||||||
# all good!
|
# all good!
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -s "${__object}/explorer/aliases"
|
if test -s "${__object:?}/explorer/aliases"
|
||||||
then
|
then
|
||||||
echo "update aliases" >>"$__messages_out"
|
echo "update aliases" >>"${__messages_out:?}"
|
||||||
else
|
else
|
||||||
echo "add aliases" >>"$__messages_out"
|
echo "add aliases" >>"${__messages_out:?}"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
(absent)
|
(absent)
|
||||||
# nothing to do if no aliases found.
|
# nothing to do if no aliases found.
|
||||||
test -s "${__object}/explorer/aliases" || exit 0
|
test -s "${__object:?}/explorer/aliases" || exit 0
|
||||||
|
|
||||||
echo "delete aliases" >>"$__messages_out"
|
echo "delete aliases" >>"${__messages_out:?}"
|
||||||
;;
|
;;
|
||||||
(*)
|
(*)
|
||||||
printf 'Invalid --state: %s.\n' "${state_should}" >&2
|
printf 'Invalid --state: %s.\n' "${state_should}" >&2
|
||||||
|
@ -61,7 +61,7 @@ esac
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
test -f '${aliases_file}' || touch '${aliases_file}'
|
test -f '${aliases_file}' || touch '${aliases_file}'
|
||||||
|
|
||||||
awk '$(drop_awk_comments "${__type}/files/update_aliases.awk")' <'${aliases_file}' >'${aliases_file}.tmp' \
|
awk '$(drop_awk_comments "${__type:?}/files/update_aliases.awk")' <'${aliases_file}' >'${aliases_file}.tmp' \
|
||||||
|| {
|
|| {
|
||||||
rm -f '${aliases_file}.tmp'
|
rm -f '${aliases_file}.tmp'
|
||||||
echo 'Generating new aliases file failed!' >&2
|
echo 'Generating new aliases file failed!' >&2
|
||||||
|
|
Loading…
Reference in a new issue