freedombone-addxmpp 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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@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}-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. if [ ! $NEW_USER_PASSWORD ]; then
  70. prosodyctl adduser $EMAIL_ADDRESS
  71. else
  72. USERNAME=$(echo $EMAIL_ADDRESS | awk -F '@' '{print $1}')
  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. exit 0