From 29c7f4cd62efbff5828359816345f15f6968b3d4 Mon Sep 17 00:00:00 2001 From: Peter Balcirak Date: Tue, 15 Jun 2021 13:31:49 +0200 Subject: [PATCH] mailaliases_generic dest_file configurable - Add possibility to change destination file (default is /etc/aliases.d/perun_generic) --- .../bin/process-mailaliases_generic.sh | 36 ++++++++++++++----- slave/process-mailaliases-generic/changelog | 8 +++++ ...lternative_mailaliases_generic_destination | 3 ++ 3 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 slave/process-mailaliases-generic/conf/example-pre_01_alternative_mailaliases_generic_destination diff --git a/slave/process-mailaliases-generic/bin/process-mailaliases_generic.sh b/slave/process-mailaliases-generic/bin/process-mailaliases_generic.sh index f7e1a373..58aa4ec4 100755 --- a/slave/process-mailaliases-generic/bin/process-mailaliases_generic.sh +++ b/slave/process-mailaliases-generic/bin/process-mailaliases_generic.sh @@ -6,7 +6,7 @@ PROTOCOL_VERSION='3.0.0' I_CHANGED=(0 'Aliases updated') I_NOT_CHANGED=(0 'Aliases has not changed') E_DUPLICITS=(50 'Duplicits: "\"${DUPLICITS}\"" have been found in "\"${FILES}\"".') -E_NOTEXISTING_ALIASESD_DIR=(51 'Directory "\"${ETC_ALIASESD_DIR}\"" not exists.') +E_NOTEXISTING_DST_FILE_DIR=(51 'Directory "\"${DST_FILE_DIR}\"" not exists.') E_PERMISSIONS=(52 'Cannot set permissions "\"${PERMISSIONS}\"" to file "\"${FROM_PERUN}\"".') E_NOTEXISTING_ALIASES_FILE=(53 'File "\"${ETC_ALIASES}\"" not exists.') E_NEWALIASES=(54 'Command newaliases failed.') @@ -15,19 +15,27 @@ GENERIC_FILE="perun_generic" FROM_PERUN="${WORK_DIR}/${GENERIC_FILE}" ETC_ALIASES="/etc/aliases" -ETC_ALIASESD_DIR="/etc/aliases.d/" +ETC_ALIASESD_DIR="/etc/aliases.d" PERMISSIONS="644" function process { + + ### prepare destination file variables + if [ -z "$DST_FILE" ]; then + DST_FILE="${ETC_ALIASESD_DIR}/${GENERIC_FILE}" + fi + DST_FILE_DIR=$(dirname "$DST_FILE") + DST_FILE_NAME=$(basename "$DST_FILE") + ### Create lock create_lock ### Set permisson for special case if destination file not exists catch_error E_PERMISSIONS chmod "${PERMISSIONS}" "${FROM_PERUN}" - ### try if /etc/aliases.d/ exists, if not, end with error - if [ ! -d "${ETC_ALIASESD_DIR}" ]; then - log_msg E_NOTEXISTING_ALIASESD_DIR + ### try if destination directory exists, if not, end with error + if [ ! -d "${DST_FILE_DIR}" ]; then + log_msg E_NOTEXISTING_DST_FILE_DIR fi ### try if file /etc/aliases exists, if not, end with error @@ -35,12 +43,22 @@ function process { log_msg E_NOTEXISTING_ALIASES_FILE fi - ### Looking for duplicits in possible places (except perun_generic_file) - ### take all files from /etc/aliases.d/ except old generic_file and all files with extension .db - fail_if_duplicits_found "${ETC_ALIASES}" "${FROM_PERUN}" `find "${ETC_ALIASESD_DIR}" -type f -not -name ${GENERIC_FILE} -not -name "*.db" -print` + ### Looking for duplicits in possible places + ### Checks /etc/aliases.d/ except old generic_file, all files with extension .db and destination file (if it is set) + ### If there is a destination file set inside different directory than /etc/aliases.d/, check that directory as well + DST_DIR_FILES=`find "${DST_FILE_DIR}" -type f -not -name "${DST_FILE_NAME}" -not -name "*.db" -print` + ETC_DIR_FILES=`find "${ETC_ALIASESD_DIR}" -type f -not -name "${DST_FILE_NAME}" -not -name "${GENERIC_FILE}" -not -name "*.db" -print` + ETC_DIR_FILES_SIMPLE=`find "${ETC_ALIASESD_DIR}" -type f -not -name "${GENERIC_FILE}" -not -name "*.db" -print` + if [ "${DST_FILE}" = "${ETC_ALIASESD_DIR}/${GENERIC_FILE}" ]; then + fail_if_duplicits_found "${ETC_ALIASES}" "${FROM_PERUN}" "${ETC_DIR_FILES_SIMPLE}" + elif [ "${DST_FILE_DIR}" = "${ETC_ALIASESD_DIR}" ]; then + fail_if_duplicits_found "${ETC_ALIASES}" "${FROM_PERUN}" "${ETC_DIR_FILES}" + else + fail_if_duplicits_found "${ETC_ALIASES}" "${FROM_PERUN}" "${DST_DIR_FILES}" "${ETC_DIR_FILES}" + fi ### If no duplicits found, move new generic_file to /etc/aliases.d/ - diff_mv_sync "${FROM_PERUN}" "${ETC_ALIASESD_DIR}/${GENERIC_FILE}" && log_msg I_CHANGED || log_msg I_NOT_CHANGED + diff_mv_sync "${FROM_PERUN}" "${DST_FILE}" && log_msg I_CHANGED || log_msg I_NOT_CHANGED ### call new aliases newaliases diff --git a/slave/process-mailaliases-generic/changelog b/slave/process-mailaliases-generic/changelog index a9402f54..02f4b2a0 100644 --- a/slave/process-mailaliases-generic/changelog +++ b/slave/process-mailaliases-generic/changelog @@ -1,3 +1,11 @@ +perun-slave-process-mailaliases-generic (3.1.5) stable; urgency=low + + * Add possibility to change destination file (default is + /etc/aliases.d/perun_generic). It may be set in a pre-script as a variable + DST_FILE + + -- Peter Balcirak Tue, 15 Jun 2021 13:28:00 +0200 + perun-slave-process-mailaliases-generic (3.1.4) stable; urgency=medium * Changed architecture to all diff --git a/slave/process-mailaliases-generic/conf/example-pre_01_alternative_mailaliases_generic_destination b/slave/process-mailaliases-generic/conf/example-pre_01_alternative_mailaliases_generic_destination new file mode 100644 index 00000000..072dd2a7 --- /dev/null +++ b/slave/process-mailaliases-generic/conf/example-pre_01_alternative_mailaliases_generic_destination @@ -0,0 +1,3 @@ +#!/bin/bash + +#export DST_FILE="/etc/aliases.d/perun_generic"