add_fwd_only.sh 789 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/bash
  2. # Define exim config
  3. if [ -e "/etc/exim/exim.conf" ]; then
  4. # RHEL or CentOS
  5. conf="/etc/exim/exim.conf"
  6. else
  7. # Debian or Ubuntu
  8. conf="/etc/exim4/exim4.conf.template"
  9. fi
  10. # Check existance
  11. if [ ! -e "$conf" ]; then
  12. exit
  13. fi
  14. # Check if fwd_only flag
  15. check_flag=$(grep localuser_fwd_only $conf)
  16. if [ ! -z "$check_flag" ]; then
  17. exit
  18. fi
  19. # Define new router
  20. fwd1='localuser_fwd_only:\n driver = accept\n transport = devnull\n'
  21. fwd2=' condition = \${if exists{/etc/exim/domains/\$domain/fwd_only}'
  22. fwd3='{\${lookup{\$local_part}lsearch{/etc/exim/domains/\$domain/fwd_only}'
  23. fwd4='{true}{false}}}}\n\n'
  24. # Insert router
  25. sed -i "s%localuser_spam:%$fwd1$fwd2$fwd3${fwd4}localuser_spam:%" $conf
  26. # Restart mail server
  27. /usr/local/vesta/bin/v-restart-mail
  28. exit