allow to set dynamic variables per mail template
directly used in the new fooled-friday template
This commit is contained in:
@@ -6,27 +6,26 @@
|
||||
FROM bitnami/minideb:bullseye
|
||||
|
||||
# Installing the services and dependencies
|
||||
RUN install_packages msmtp ca-certificates curl
|
||||
RUN install_packages msmtp ca-certificates curl gettext-base
|
||||
|
||||
# Manually install supercronic
|
||||
ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.1.12/supercronic-linux-amd64 \
|
||||
SUPERCRONIC=supercronic-linux-amd64 \
|
||||
SUPERCRONIC_SHA1SUM=048b95b48b708983effb2e5c935a1ef8483d9e3e
|
||||
|
||||
RUN curl -fsSLO "$SUPERCRONIC_URL" \
|
||||
&& echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - \
|
||||
&& chmod +x "$SUPERCRONIC" \
|
||||
&& mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
|
||||
&& ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic
|
||||
|
||||
# Set up unprivileged user
|
||||
RUN adduser --shell "/sbin/nologin" --gecos "Reminder" --disabled-password reminder
|
||||
|
||||
USER reminder
|
||||
|
||||
WORKDIR /home/reminder
|
||||
|
||||
RUN mkdir mails
|
||||
# Add script and mails
|
||||
COPY reminder-mails.sh cron.txt .msmtprc /home/reminder/
|
||||
RUN mkdir mails
|
||||
COPY mails/* /home/reminder/mails/
|
||||
|
||||
# CMD to run the cron on container start
|
||||
|
7
cron.txt
7
cron.txt
@@ -2,6 +2,7 @@
|
||||
#
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
0 22 15 2,5,8,11 * /home/reminder/reminder-mails.sh access-review
|
||||
0 22 15 1,4,7,10 * /home/reminder/reminder-mails.sh services-review
|
||||
0 22 15 3,6,9,12 * /home/reminder/reminder-mails.sh mailinglist-review
|
||||
0 22 15 2,5,8,11 * /home/reminder/reminder-mails.sh /home/reminder/mails/access-review
|
||||
0 22 15 1,4,7,10 * /home/reminder/reminder-mails.sh /home/reminder/mails/services-review
|
||||
0 22 15 3,6,9,12 * /home/reminder/reminder-mails.sh /home/reminder/mails/mailinglist-review
|
||||
* * * * * /home/reminder/reminder-mails.sh /home/reminder/mails/fooled-friday
|
||||
|
24
mails/fooled-friday
Normal file
24
mails/fooled-friday
Normal file
@@ -0,0 +1,24 @@
|
||||
# Set a random recipient based on the array $users
|
||||
# var: users=("alex.sander@fsfe.org" "bonnie@fsfe.org" "eal@fsfe.org" "fani@fsfe.org" "gabriel.ku@fsfe.org" "jackie@fsfe.org" "lina.ceballos@fsfe.org" "linda@fsfe.org" "linus@fsfe.org" "lucas.lasota@fsfe.org" "max.mehl@fsfe.org" "mk@fsfe.org" "niharika@fsfe.org")
|
||||
# var: to=${users[$RANDOM % ${#users[@]}]}
|
||||
To: $to
|
||||
From: no-reply@fsfe.org
|
||||
Subject: [Staff] You have been chosen for Fooled Friday!
|
||||
|
||||
Hello,
|
||||
|
||||
You have been selected the random person of the group to say one wrong task in
|
||||
the daily meeting that you have done or will do. Nobody except you knows that
|
||||
you are the one who is supposed to trick the others, so keep it secret!
|
||||
|
||||
Others than have to guess who of the group tries to trick them, and detect the
|
||||
wrong task.
|
||||
|
||||
Good luck and have fun :)
|
||||
|
||||
Best,
|
||||
Your friendly randomiser robot
|
||||
|
||||
--
|
||||
This mail has been automatically sent by:
|
||||
https://git.fsfe.org/fsfe-system-hackers/reminder-mails
|
@@ -10,26 +10,49 @@
|
||||
prepmail () {
|
||||
# read mail in variable
|
||||
mail=$(< "$1")
|
||||
# add date and message ID
|
||||
mail=$(echo "$mail" | sed "1s|^|Date: $(date -R)\n|" | sed "1s|^|Message-ID: <ReMiNdEr.$(date +%s)@fsfe.org>\n|")
|
||||
|
||||
echo "$mail"
|
||||
# get dynamic variables from file
|
||||
while read -r line; do
|
||||
if [[ -n "$line" ]]; then
|
||||
# remove prefix
|
||||
line=${line//# var: /}
|
||||
# export the line in the format of var=value
|
||||
eval "export $line"
|
||||
fi
|
||||
done <<< "$(grep '^# var: ' <<< "$mail")"
|
||||
|
||||
# add date and message ID in the first lines
|
||||
# and remove all local variable declaration from template
|
||||
mail=$(echo "$mail" | sed "1s|^|Date: $(date -R)\n|" \
|
||||
| sed "1s|^|Message-ID: <ReMiNdEr.$(date +%s)@fsfe.org>\n|" \
|
||||
| sed '/^#.*/d')
|
||||
|
||||
# replace variables in mail with exported variables
|
||||
envsubst <<< "$mail"
|
||||
}
|
||||
|
||||
send_mail() {
|
||||
if [[ "$DEBUG" != "debug" ]]; then
|
||||
msmtp -t --read-envelope-from -a fsfe
|
||||
else
|
||||
cat
|
||||
fi
|
||||
}
|
||||
|
||||
EMAIL=$1
|
||||
DEBUG=$2
|
||||
|
||||
# If argument is given, check for mail template and send it out
|
||||
if [[ ! -z "$EMAIL" ]]; then
|
||||
if [[ -e "${HOME}/mails/$EMAIL" ]]; then
|
||||
prepmail "$EMAIL" | msmtp -t --read-envelope-from -a fsfe
|
||||
if [[ "$?" == 0 ]]; then
|
||||
echo "[INFO] Mail \"$EMAIL\" has been sent successfully"
|
||||
if [[ -n "$EMAIL" ]]; then
|
||||
if [[ -e "$EMAIL" ]]; then
|
||||
if prepmail "$EMAIL" | send_mail; then
|
||||
echo "[INFO] $EMAIL has been sent successfully"
|
||||
else
|
||||
echo "[ERROR] There has been an error with sending \"$EMAIL\"".
|
||||
echo "[ERROR] There has been an error with sending $EMAIL".
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "[ERROR] Mail template \"$EMAIL\" does not exist."
|
||||
echo "[ERROR] Mail template $EMAIL does not exist."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
|
Reference in New Issue
Block a user