1
1
Fork 0
mirror of https://github.com/docker-mailserver/docker-mailserver synced 2024-05-26 02:06:17 +02:00
docker-mailserver/target/scripts/helpers/utils.sh
Brennan Kinney 1f3e672018
fix(listmailuser): Don't parse comments when reading config (#2617)
* fix(listmailuser): Don't parse comments

Avoids passing comments to `dovecot_quota_to_hr()` which fails to handle it and would throws errors.

* chore: Move config filter method to `helpers/utils.sh`
2022-06-06 11:02:52 +12:00

31 lines
772 B
Bash

#! /bin/bash
function _escape
{
echo "${1//./\\.}"
}
# Returns input after filtering out lines that are:
# empty, white-space, comments (`#` as the first non-whitespace character)
function _filter_to_valid_lines
{
grep --extended-regexp --invert-match "^\s*$|^\s*#" "${1}" || true
}
# TODO: Only used by `relay.sh`, will be removed in future.
# Similar to _filter_to_valid_lines, but only returns a status code
# to indicate invalid line(s):
function _is_comment
{
grep -q -E "^\s*$|^\s*#" <<< "${1}"
}
# Provide the name of an environment variable to this function
# and it will return its value stored in /etc/dms-settings
function _get_dms_env_value
{
local VALUE
VALUE=$(grep "^${1}=" /etc/dms-settings | cut -d '=' -f 2)
printf '%s' "${VALUE:1:-1}"
}