Quellcode durchsuchen

Add a script to distribute bdsmail to user maildirs

Bob Mottram vor 7 Jahren
Ursprung
Commit
78bcc77896
1 geänderte Dateien mit 23 neuen und 0 gelöschten Zeilen
  1. 23
    0
      src/freedombone-app-bdsmail

+ 23
- 0
src/freedombone-app-bdsmail Datei anzeigen

@@ -245,6 +245,9 @@ function remove_bdsmail {
245 245
     if [ -d $BDSMAIL_DIR ]; then
246 246
         rm -rf $BDSMAIL_DIR
247 247
     fi
248
+    rm /usr/bin/bdsmail_domain
249
+    sed -i '/bdsmail_distribute/d' /etc/crontab
250
+    rm /usr/bin/bdsmail_distribute
248 251
 }
249 252
 
250 253
 function install_bdsmail {
@@ -342,6 +345,26 @@ function install_bdsmail {
342 345
     systemctl enable bdsmail
343 346
     systemctl start bdsmail
344 347
 
348
+    echo '#!/bin/bash' > /usr/bin/bdsmail_distribute
349
+    echo 'BDSMAIL_DIR=/etc/bdsmail' >> /usr/bin/bdsmail_distribute
350
+    echo "MAIL_DIR=\$BDSMAIL_DIR/$(cat \$BDSMAIL_DIR/config.ini | grep 'maildir =' | awk -F ' ' '{print \$3}')" >> /usr/bin/bdsmail_distribute
351
+    echo 'if [ ! -d $MAIL_DIR/postmaster/new ]; then' >> /usr/bin/bdsmail_distribute
352
+    echo '    exit 0' >> /usr/bin/bdsmail_distribute
353
+    echo 'fi' >> /usr/bin/bdsmail_distribute
354
+    echo 'for filename in $MAIL_DIR/postmaster/new/*; do' >> /usr/bin/bdsmail_distribute
355
+    echo '    to_line=$(cat $filename | grep "To: " | head -n 1)' >> /usr/bin/bdsmail_distribute
356
+    echo "    to_username=\$(echo \"\$to_line\" | awk -F ' ' '{print \$2}' | awk -F '@' '{print \$1}')" >> /usr/bin/bdsmail_distribute
357
+    echo '    if [ -d /home/$to_username/Maildir/i2p/new ]; then' >> /usr/bin/bdsmail_distribute
358
+    echo '        chown $to_username:$to_username $filename' >> /usr/bin/bdsmail_distribute
359
+    echo '        mv $filename /home/$to_username/Maildir/i2p/new' >> /usr/bin/bdsmail_distribute
360
+    echo '    fi' >> /usr/bin/bdsmail_distribute
361
+    echo 'done' >> /usr/bin/bdsmail_distribute
362
+    chmod +x /usr/bin/bdsmail_distribute
363
+
364
+    if ! grep -q 'bdsmail_distribute' /etc/crontab; then
365
+        echo '*/1            * *   *   *   root /usr/bin/bdsmail_distribute 2> /dev/null' >> /etc/crontab
366
+    fi
367
+
345 368
     echo '#!/bin/bash' > /usr/bin/bdsmail_domain
346 369
     echo "cd $BDSMAIL_DIR" >> /usr/bin/bdsmail_domain
347 370
     echo 'if [ ! -f bdsmail-privkey.dat ]; then' >> /usr/bin/bdsmail_domain