freedombone-rmlist 2.0KB

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