Skip to content

Commit

Permalink
Merge pull request #605 from balcirakpeter/mailaliases_generic_dest
Browse files Browse the repository at this point in the history
mailaliases_generic dest_file configurable
  • Loading branch information
balcirakpeter authored Jul 22, 2021
2 parents 2278de0 + 29c7f4c commit c4fa8f4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand All @@ -15,32 +15,50 @@ 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
if [ ! -f "${ETC_ALIASES}" ]; then
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
Expand Down
8 changes: 8 additions & 0 deletions slave/process-mailaliases-generic/changelog
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> Tue, 15 Jun 2021 13:28:00 +0200

perun-slave-process-mailaliases-generic (3.1.4) stable; urgency=medium

* Changed architecture to all
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

#export DST_FILE="/etc/aliases.d/perun_generic"

0 comments on commit c4fa8f4

Please sign in to comment.