From 2a244ee167bbbd70e8bde4eed25e0fa581121e27 Mon Sep 17 00:00:00 2001 From: Felix Date: Sun, 17 May 2020 15:57:22 +0200 Subject: [PATCH] Add script for email announcements --- files/email-template.txt | 4 ++++ files/send-email-to-users.bash | 27 +++++++++++++++++++++++++++ peertube.yml | 10 ++++++---- 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 files/email-template.txt create mode 100644 files/send-email-to-users.bash diff --git a/files/email-template.txt b/files/email-template.txt new file mode 100644 index 0000000..9646d05 --- /dev/null +++ b/files/email-template.txt @@ -0,0 +1,4 @@ +subject:email to all users +from:info@your-instance.com + +this is a test email. diff --git a/files/send-email-to-users.bash b/files/send-email-to-users.bash new file mode 100644 index 0000000..50718f4 --- /dev/null +++ b/files/send-email-to-users.bash @@ -0,0 +1,27 @@ +#!/bin/bash +set -e + +echo -e "This will send an email to all users, based on the template in $(pwd)/email-template.txt. Content:\n\n" +cat email-template.txt +echo -e "\n\n" + +read -p "Send test email (y/N)? " SEND_EMAIL +case "$SEND_EMAIL" in + [yY]* ) ;; + [nN]* ) exit;; + * ) exit;; +esac + +EMAIL_LIST=$(mktemp) +echo $EMAIL_LIST +docker-compose exec -T -u postgres postgres psql -U peertube -d peertube -c "SELECT email FROM public.user WHERE NOT blocked" -t > $EMAIL_LIST +echo "Sending email to $(wc -l $EMAIL_LIST | cut -d' ' -f1) users" + +cat $EMAIL_LIST | while read EMAIL +do + echo "sending to $EMAIL" + cat email-template.txt | \ + docker exec -i "$(docker-compose ps -q postfix)" sendmail -t "$EMAIL" +done + +rm $EMAIL_LIST diff --git a/peertube.yml b/peertube.yml index 58807f3..42f46e3 100644 --- a/peertube.yml +++ b/peertube.yml @@ -25,11 +25,13 @@ - { path: '/peertube/volumes/certbot/' } - { path: '/peertube/volumes/config/' } - - name: copy docker config - copy: src={{item.src}} dest={{item.dest}} mode='0644' + - name: copy files + copy: src={{item.src}} dest={{item.dest}} mode={{item.mode}} force={{item.force}} with_items: - - { src: 'files/docker-daemon.json', dest: '/etc/docker/daemon.json' } - - { src: 'files/local-production.json', dest: '/peertube/volumes/config/local-production.json' } + - { src: 'files/docker-daemon.json', dest: '/etc/docker/daemon.json', mode: '0644', force: 'yes' } + - { src: 'files/local-production.json', dest: '/peertube/volumes/config/local-production.json', mode: '0644', force: 'yes' } + - { src: 'files/send-email-to-users.bash', dest: '/peertube/send-email-to-users.bash', mode: '755', force: 'yes' } + - { src: 'files/email-template.txt', dest: '/peertube/email-template.txt', mode: '0644', force: 'no' } - name: get latest peertube version from github uri: