freedombone-rmlist 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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-2016 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 Affero 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 Affero General Public License for more details.
  26. #
  27. # You should have received a copy of the GNU Affero General Public License
  28. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. PROJECT_NAME='freedombone'
  30. export TEXTDOMAIN=${PROJECT_NAME}-rmlist
  31. export TEXTDOMAINDIR="/usr/share/locale"
  32. MYUSERNAME=$USER
  33. MAILINGLIST=
  34. LIST_ADDRESS=
  35. function show_help {
  36. echo ''
  37. echo $"${PROJECT_NAME}-rmlist -u [username] -l [mailing list name] -e [list email address]"
  38. echo ''
  39. exit 0
  40. }
  41. while [[ $# > 1 ]]
  42. do
  43. key="$1"
  44. case $key in
  45. -h|--help)
  46. show_help
  47. ;;
  48. -u|--user)
  49. shift
  50. MYUSERNAME="$1"
  51. ;;
  52. -l|--list)
  53. shift
  54. MAILINGLIST="$1"
  55. ;;
  56. -e|--email)
  57. shift
  58. LIST_ADDRESS="$1"
  59. ;;
  60. *)
  61. # unknown option
  62. ;;
  63. esac
  64. shift
  65. done
  66. if ! [[ $MYUSERNAME && $MAILINGLIST ]]; then
  67. show_help
  68. fi
  69. MUTTRC=/home/$MYUSERNAME/.muttrc
  70. MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)
  71. if [[ $MUTT_MAILBOXES == *$MAILINGLIST* ]]; then
  72. sed -i "s| =$MAILINGLIST||g" $MUTTRC
  73. chown $MYUSERNAME:$MYUSERNAME $MUTTRC
  74. fi
  75. if [ $LIST_ADDRESS ]; then
  76. if ! grep -q "unsubscribe $LIST_ADDRESS" $MUTTRC; then
  77. sed -i "s|subscribe $LIST_ADDRESS|unsubscribe $LIST_ADDRESS|g" $MUTTRC
  78. fi
  79. fi
  80. exit 0