freedombone-addxmpp 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Adds an xmpp user
  12. # License
  13. # =======
  14. #
  15. # Copyright (C) 2015-2016 Bob Mottram <bob@freedombone.net>
  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}-addxmpp
  31. export TEXTDOMAINDIR="/usr/share/locale"
  32. EMAIL_ADDRESS=
  33. NEW_USER_PASSWORD=
  34. function show_help {
  35. echo ''
  36. echo $"${PROJECT_NAME}-addxmpp -e [email address] -p [password]"
  37. echo ''
  38. exit 0
  39. }
  40. while [[ $# > 1 ]]
  41. do
  42. key="$1"
  43. case $key in
  44. -h|--help)
  45. show_help
  46. ;;
  47. -e|--email)
  48. shift
  49. EMAIL_ADDRESS="$1"
  50. ;;
  51. -p|--password|--passphrase)
  52. shift
  53. NEW_USER_PASSWORD="$1"
  54. ;;
  55. *)
  56. # unknown option
  57. ;;
  58. esac
  59. shift
  60. done
  61. if [ ! -d /etc/prosody ]; then
  62. echo $'xmpp server is not installed'
  63. exit 0
  64. fi
  65. if [ ! $EMAIL_ADDRESS ]; then
  66. show_help
  67. exit 1
  68. fi
  69. USERNAME=$(echo $EMAIL_ADDRESS | awk -F '@' '{print $1}')
  70. if [ ! $NEW_USER_PASSWORD ]; then
  71. prosodyctl adduser $EMAIL_ADDRESS
  72. else
  73. DOMAIN_NAME=$(echo $EMAIL_ADDRESS | awk -F '@' '{print $2}')
  74. prosodyctl register $USERNAME $DOMAIN_NAME "$NEW_USER_PASSWORD"
  75. if [ ! "$?" = "0" ]; then
  76. exit 2
  77. fi
  78. fi
  79. # add the xmpp address to email headers
  80. if [ -f /home/$USERNAME/.muttrc ]; then
  81. if ! grep -q "Jabber-ID" /home/$USERNAME/.muttrc; then
  82. echo "my_hdr Jabber-ID: $EMAIL_ADDRESS" >> /home/$USERNAME/.muttrc
  83. else
  84. sed -i "s|my_hdr Jabber-ID.*|my_hdr Jabber-ID: $EMAIL_ADDRESS|g" /home/$USERNAME/.muttrc
  85. fi
  86. fi
  87. exit 0