From 799a31ce8fab6cbd56fdd9a5a737dda979bfde6d Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@freedombone.net>
Date: Mon, 12 Feb 2018 13:16:15 +0000
Subject: [PATCH] Add users to i2p group when bdsmail is installed

---
 src/freedombone-app-bdsmail | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/freedombone-app-bdsmail b/src/freedombone-app-bdsmail
index 46c6b6c89..f02fc27ac 100755
--- a/src/freedombone-app-bdsmail
+++ b/src/freedombone-app-bdsmail
@@ -42,6 +42,10 @@ function bdsmail_configure_users {
     for d in /home/*/ ; do
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
+
+            # Add the user to the i2p group
+            usermod -a -G i2psvc $USERNAME
+
             if [ -f /home/$USERNAME/.muttrc ]; then
                 # Create a mutt i2p folder
                 if ! grep -q ' =i2p' /home/$USERNAME/.muttrc; then
@@ -199,18 +203,12 @@ function remove_bdsmail {
         rm /etc/systemd/system/bdsmail.service
     fi
 
-    remove_i2p
-    remove_app bdsmail
-    remove_completion_param install_bdsmail
-    sed -i '/bdsmail/d' $COMPLETION_FILE
-    rm -rf /etc/skel/.mutt
-    if [ -d /etc/bdsmail ]; then
-        rm -rf /etc/bdsmail
-    fi
-
     for d in /home/*/ ; do
         USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
+            # remove the user from the i2p group
+            deluser $USERNAME i2psvc
+
             # Remove mutt folder hook to the i2p config
             if [ -f /home/$USERNAME/.muttrc ]; then
                 if grep -q 'folder-hook !i2p' /home/$USERNAME/.muttrc; then
@@ -230,6 +228,15 @@ function remove_bdsmail {
             # or just be reinstalling the system without losing mail
         fi
     done
+
+    remove_i2p
+    remove_app bdsmail
+    remove_completion_param install_bdsmail
+    sed -i '/bdsmail/d' $COMPLETION_FILE
+    rm -rf /etc/skel/.mutt
+    if [ -d /etc/bdsmail ]; then
+        rm -rf /etc/bdsmail
+    fi
 }
 
 function install_bdsmail {
-- 
GitLab