freedombone-rmlist 2.1KB

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