Add a script to distribute bdsmail to user maildirs

This commit is contained in:
Bob Mottram 2018-02-13 18:54:26 +00:00
parent a3c92759b7
commit 78bcc77896
1 changed files with 23 additions and 0 deletions

View File

@ -245,6 +245,9 @@ function remove_bdsmail {
if [ -d $BDSMAIL_DIR ]; then if [ -d $BDSMAIL_DIR ]; then
rm -rf $BDSMAIL_DIR rm -rf $BDSMAIL_DIR
fi fi
rm /usr/bin/bdsmail_domain
sed -i '/bdsmail_distribute/d' /etc/crontab
rm /usr/bin/bdsmail_distribute
} }
function install_bdsmail { function install_bdsmail {
@ -342,6 +345,26 @@ function install_bdsmail {
systemctl enable bdsmail systemctl enable bdsmail
systemctl start bdsmail systemctl start bdsmail
echo '#!/bin/bash' > /usr/bin/bdsmail_distribute
echo 'BDSMAIL_DIR=/etc/bdsmail' >> /usr/bin/bdsmail_distribute
echo "MAIL_DIR=\$BDSMAIL_DIR/$(cat \$BDSMAIL_DIR/config.ini | grep 'maildir =' | awk -F ' ' '{print \$3}')" >> /usr/bin/bdsmail_distribute
echo 'if [ ! -d $MAIL_DIR/postmaster/new ]; then' >> /usr/bin/bdsmail_distribute
echo ' exit 0' >> /usr/bin/bdsmail_distribute
echo 'fi' >> /usr/bin/bdsmail_distribute
echo 'for filename in $MAIL_DIR/postmaster/new/*; do' >> /usr/bin/bdsmail_distribute
echo ' to_line=$(cat $filename | grep "To: " | head -n 1)' >> /usr/bin/bdsmail_distribute
echo " to_username=\$(echo \"\$to_line\" | awk -F ' ' '{print \$2}' | awk -F '@' '{print \$1}')" >> /usr/bin/bdsmail_distribute
echo ' if [ -d /home/$to_username/Maildir/i2p/new ]; then' >> /usr/bin/bdsmail_distribute
echo ' chown $to_username:$to_username $filename' >> /usr/bin/bdsmail_distribute
echo ' mv $filename /home/$to_username/Maildir/i2p/new' >> /usr/bin/bdsmail_distribute
echo ' fi' >> /usr/bin/bdsmail_distribute
echo 'done' >> /usr/bin/bdsmail_distribute
chmod +x /usr/bin/bdsmail_distribute
if ! grep -q 'bdsmail_distribute' /etc/crontab; then
echo '*/1 * * * * root /usr/bin/bdsmail_distribute 2> /dev/null' >> /etc/crontab
fi
echo '#!/bin/bash' > /usr/bin/bdsmail_domain echo '#!/bin/bash' > /usr/bin/bdsmail_domain
echo "cd $BDSMAIL_DIR" >> /usr/bin/bdsmail_domain echo "cd $BDSMAIL_DIR" >> /usr/bin/bdsmail_domain
echo 'if [ ! -f bdsmail-privkey.dat ]; then' >> /usr/bin/bdsmail_domain echo 'if [ ! -f bdsmail-privkey.dat ]; then' >> /usr/bin/bdsmail_domain