OSX Server - Group EMail Enabler v0.2


/ Published in: Bash
Save to your folder(s)

If you have any contributions, please comment here.


Copy this code and paste it in your HTML
  1. #!/bin/bash
  2.  
  3. # Group EMail Enabler v0.2
  4. # Jeff Johnson <[email protected]>
  5.  
  6. # Tested with OS X Server 10.6 and 10.7
  7. # Should also work with 10.5
  8.  
  9. # This script allows you to manage email groups using Work Group Manager.
  10. # If you create an executive group in WGM, you then have a executive@ email address
  11. # This is automatically maintained as you adjust the members
  12.  
  13. # The script searches your LDAP groups for the word 'mail' in the comment field
  14. # You must add mail to the comment field for any group which should have an email address.
  15. # The email address for that group will be the shortname of that group.
  16. # If you miss this step (add 'mail' to the comment field), this script does nothing.
  17.  
  18. # Known issues
  19. # 1. Only supports groups in LDAP, users can be in LDAP or Local
  20. # 2. Does not support other groups within your email group (no nested groups)
  21. # 3. Almost no error checking, so best to run it manually a few times to check results.
  22.  
  23. # Installation Instructions
  24. # 1. Save this file as
  25. # /usr/sbin/group_email.sh
  26. # 2. Then adjust permissions
  27. # sudo chmod +x /usr/sbin/group_email.sh
  28. # 3. Modifiy alias_maps in /etc/postfix/main.cf
  29. # You need to add this line to what you already have
  30. # hash:/etc/postfix/group_aliases
  31. # Example, you have:
  32. # alias_maps = hash:/etc/aliases
  33. # Change to:
  34. # alias_maps = hash:/etc/aliases, hash:/etc/postfix/group_aliases
  35. # 4. To run automatically every 5 minutes, I prefer a simple addition to /etc/crontab
  36. # you may need to create /etc/crontab if it doesn't exist
  37. # Add the following to /etc/crontab
  38. # */5 * * * * root /usr/sbin/group_email.sh >> /dev/null 2>&1
  39. #
  40. # If you followed these instructions, within 5 minutes you will see an alias file at
  41. # /etc/postfix/groupaliases
  42. # you can inspect the file to confirm the results.
  43.  
  44.  
  45. cd /etc/postfix
  46.  
  47. # clear current aliases
  48. echo "" > group_aliases.tmp
  49.  
  50. # Get list of groups with 'mail' in the comment field
  51. gr=`dscl /LDAPv3/127.0.0.1 -list /Groups Comment | grep mail | awk '{print $1}'`
  52.  
  53. for group in $gr
  54. do
  55. echo $group: `dscl /LDAPv3/127.0.0.1 -read /Groups/$group dsAttrTypeNative:memberUid | cut -d : -f 3 | grep -v "No such key"` >> group_aliases.tmp
  56. done
  57.  
  58. cmp -s group_aliases.tmp group_aliases > /dev/null
  59. if [ $? -eq 1 ]; then
  60. echo different
  61. cp group_aliases.tmp group_aliases
  62. /usr/sbin/postalias /etc/postfix/group_aliases
  63. /usr/bin/newaliases
  64. else
  65. echo same
  66. fi
  67.  
  68. exit

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.