freedombone-rmlist 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. # Removes a mailing list to the email configuration
  3. # License
  4. # =======
  5. #
  6. # Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. MYUSERNAME=$USER
  21. MAILINGLIST=
  22. function show_help {
  23. echo ''
  24. echo 'freedombone-rmlist -u [username] -l [mailing list name]'
  25. echo ''
  26. exit 0
  27. }
  28. while [[ $# > 1 ]]
  29. do
  30. key="$1"
  31. case $key in
  32. -h|--help)
  33. show_help
  34. ;;
  35. -u|--user)
  36. shift
  37. MYUSERNAME="$1"
  38. ;;
  39. -l|--list)
  40. shift
  41. MAILINGLIST="$1"
  42. ;;
  43. *)
  44. # unknown option
  45. ;;
  46. esac
  47. shift
  48. done
  49. if ! [[ $MYUSERNAME && $MAILINGLIST ]]; then
  50. show_help
  51. fi
  52. MUTTRC=/home/$MYUSERNAME/.muttrc
  53. MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)
  54. if [[ $MUTT_MAILBOXES == *$MAILINGLIST* ]]; then
  55. sed -i "s| =$MAILINGLIST||g" $MUTTRC
  56. chown $MYUSERNAME:$MYUSERNAME $MUTTRC
  57. fi
  58. exit 0