86 lines
2.2 KiB
Bash
Executable File
86 lines
2.2 KiB
Bash
Executable File
#!/bin/sh -e
|
|
#
|
|
# 2021 Joachim Desroches (joachim.desroches@epfl.ch)
|
|
#
|
|
# This file is part of cdist.
|
|
#
|
|
# cdist is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# cdist is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
|
|
|
|
os=$(cat "${__global:?}/explorer/os")
|
|
|
|
CFG_DIR="/etc/opendkim"
|
|
user="opendkim"
|
|
group="opendkim"
|
|
case "$os" in
|
|
'alpine')
|
|
:
|
|
;;
|
|
'freebsd')
|
|
CFG_DIR="/usr/local/etc/mail"
|
|
user="mailnull"
|
|
group="mailnull"
|
|
;;
|
|
*)
|
|
cat <<- EOF >&2
|
|
__opendkim_genkey currently only supports Alpine Linux. Please
|
|
contribute an implementation for $os if you can.
|
|
EOF
|
|
;;
|
|
esac
|
|
# Persist user and group for gencode-remote
|
|
printf '%s' "${user}" > "${__object:?}/user"
|
|
printf '%s' "${group}" > "${__object:?}/group"
|
|
|
|
SELECTOR="$(cat "${__object:?}/parameter/selector")"
|
|
DOMAIN="$(cat "${__object:?}/parameter/domain")"
|
|
|
|
DIRECTORY="/var/db/dkim/"
|
|
if [ -f "${__object:?}/parameter/directory" ];
|
|
then
|
|
# Be forgiving about a lack of trailing slash
|
|
DIRECTORY="$(sed -E 's!([^/])$!\1/!' < "${__object:?}/parameter/directory")"
|
|
fi
|
|
|
|
SIGKEY="${DOMAIN:?}"
|
|
if [ -f "${__object:?}/parameter/sigkey" ];
|
|
then
|
|
SIGKEY="$(cat "${__object:?}/parameter/sigkey")"
|
|
fi
|
|
|
|
# Ensure the key-container directory exists with the proper permissions
|
|
__directory "${DIRECTORY}" \
|
|
--mode 0750 \
|
|
--owner "${user}" --group "${group}"
|
|
|
|
# OS-specific code
|
|
case "$os" in
|
|
'alpine')
|
|
# This is needed for opendkim-genkey
|
|
__package opendkim-utils
|
|
;;
|
|
esac
|
|
|
|
key_table="${CFG_DIR}/KeyTable"
|
|
signing_table="${CFG_DIR}/SigningTable"
|
|
|
|
__line "line-key-${__object_id:?}" \
|
|
--file "${key_table}" \
|
|
--line "${SELECTOR:?}._domainkey.${DOMAIN:?} ${DOMAIN:?}:${SELECTOR:?}:${DIRECTORY:?}${SELECTOR:?}.private"
|
|
|
|
__line "line-sig-${__object_id:?}" \
|
|
--file "${signing_table}" \
|
|
--line "${SIGKEY:?} ${SELECTOR:?}._domainkey.${DOMAIN:?}"
|