Skip to content
Snippets Groups Projects
Commit d0bd807e authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Add script example to sync nextcloud group to mailman list

parent 3e9e4d21
No related branches found
No related tags found
No related merge requests found
......@@ -87,3 +87,59 @@ Response:
## Example script to sync members of a Nextcloud group to a Mailman mailing list
```
#!/bin/bash
if [ "$#" -lt 2 ]; then
echo "Simple script to sync all members of a nextcloud group to a mailman list. Usage: "
echo "./sync-nextcloud-group-mailman.sh [NEXTCLOUD_GROUP] [MAILMAN_LIST] [nosync]"
fi
group=$1
list=$2
[ "$3" == "nosync" ] && sync=0 || sync=1
dir=$(dirname $0)
server=[YOUR_NEXTCLOUD_SERVER_WITH_PATH]
user=[ADMINUSER_READONLY]
pass=[ADMINPASSWORD_READONLY]
url="https://$user:$pass@$server/ocs/v1.php/"
echo "GROUP $group (Mailinglist $list)"
echo "====================="
# Spaces in NextCloud groups need to be escaped as %20
users=$(curl -s -X GET "${url}cloud/groups/${group/ /%20}" -H "OCS-APIRequest: true" | xpath -q -e '/ocs/data/users/element/text()')
mails=""
for u in $users; do
name=$(curl -s -X GET "${url}cloud/users/$u" -H "OCS-APIRequest: true" | xpath -q -e "/ocs/data/displayname/text()")
response=$(curl -s -X GET "${url}apps/secondarymail/getAddress/$u" -H "OCS-APIRequest: true")
failure=$(echo $response | xpath -q -e "/ocs/meta/status/text()")
if [ "$failure" != "ok" ]; then
echo "Unable to query NextCloud for user preferences on email and for secondary mail. Is the secondarymail app enabled?"
echo "Server response:"
echo -e $response
exit 1
fi
mailaddresses=$(echo $response | xpath -q -e "/ocs/data/email/element/text()")
for e in $mailaddresses; do
if [ ! -z "$e" ]; then
mails="$mails$name <$e>\n"
fi
done
done
sync_flags="-a=no -g=no -w=no -d=no"
if [ $sync = 0 ]; then
sync_flags="$sync_flags -n "
fi
printf "$mails" | sync_members $sync_flags -n -f - $list | grep -v -e 'Was-Wäre-Wenn-Modus' -e 'Ignoriere:' -e 'Nichts zu tun.'
echo
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment