fix: added gen domains config

This commit is contained in:
GoliathLabs 2023-07-12 17:02:21 +02:00 committed by Felix
parent 6697f45949
commit 049bf7109a
2 changed files with 49 additions and 26 deletions

49
target/bin/share-inbox Normal file
View File

@ -0,0 +1,49 @@
#!/bin/bash
# shellcheck source=../scripts/helpers/index.sh
source /usr/local/bin/helpers/index.sh
# $1: The source account name
# $2: The account name of who receives access
# $3, $4 and so on: list of permissions - one of: lookup read write write-seen write-deleted insert post expunge
# Call me like this: share_inbox.sh office bob lookup read
# NOTE: HOSTNAME is set via `helpers/dns.sh`, it is not the original system HOSTNAME ENV anymore.
if [[ "${DOVECOT_ENABLE_INBOX_SHARING}" = 0 ]]
then
echo "You have to enable inbox sharing by means of 'DOVECOT_ENABLE_INBOX_SHARING' before actually sharing anything." >&2
exit 1
fi
DATABASE_VHOST='/tmp/vhost.sharedinbox'
# Prepare a file with one domain per line:
function _generate_domains_config() {
local TMP_VHOST='/tmp/vhost.sharedinbox.tmp'
# Generate the default vhost (equivalent to /etc/postfix/vhost),
# unless CLI arg DOMAINS provided an alternative list to use instead:
if [[ -z ${DOMAINS} ]]; then
_obtain_hostname_and_domainname
# uses TMP_VHOST:
_vhost_collect_postfix_domains
else
tr ',' '\n' <<< "${DOMAINS}" >"${TMP_VHOST}"
fi
# uses DATABASE_VHOST + TMP_VHOST:
_create_vhost
}
_generate_domains_config
if [[ ! -s ${DATABASE_VHOST} ]]; then
_log 'warn' 'No entries found'
exit 0
fi
SHARING=$1
shift
SHARED_TO=$1
shift
doveadm acl add -u "${SHARING}@${DOMAINNAME}" 'Inbox' "user=${SHARED_TO}@${DOMAINNAME}" "$@"

View File

@ -1,26 +0,0 @@
#!/bin/bash
# $1: The source account name
# $2: The account name of who receives access
# $3, $4 and so on: list of permissions - one of: lookup read write write-seen write-deleted insert post expunge
# Call me like this: share_inbox.sh office bob lookup read
DOMAIN=$(hostname -d)
if [[ "${DOVECOT_ENABLE_INBOX_SHARING}" = 0 ]]
then
echo "You have to enable inbox sharing by means of 'DOVECOT_ENABLE_INBOX_SHARING' before actually sharing anything." >&2
exit 1
fi
if ! grep -q '\.' <<< "${DOMAIN}"
then
echo "Couldn't detect the target domain - 'hostname -d' returned '${DOMAIN}', which seems to be garbage. Configure the container, so it is aware of its domain" >&2
exit 1
fi
SHARING=$1
shift
SHARED_TO=$1
shift
doveadm acl add -u "${SHARING}@${DOMAIN}" 'Inbox' "user=${SHARED_TO}@${DOMAIN}" "$@"