freedombone-addxmpp 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 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. EMAIL_ADDRESS=
  30. NEW_USER_PASSWORD=
  31. function show_help {
  32. echo ''
  33. echo 'freedombone-addxmpp -e [email address] -p [password]'
  34. echo ''
  35. exit 0
  36. }
  37. while [[ $# > 1 ]]
  38. do
  39. key="$1"
  40. case $key in
  41. -h|--help)
  42. show_help
  43. ;;
  44. -e|--email)
  45. shift
  46. EMAIL_ADDRESS="$1"
  47. ;;
  48. -p|--password|--passphrase)
  49. shift
  50. NEW_USER_PASSWORD="$1"
  51. ;;
  52. *)
  53. # unknown option
  54. ;;
  55. esac
  56. shift
  57. done
  58. if [ ! -d /etc/prosody ]; then
  59. echo 'xmpp server is not installed'
  60. exit 0
  61. fi
  62. if [ ! $EMAIL_ADDRESS ]; then
  63. show_help
  64. exit 1
  65. fi
  66. if [ ! $NEW_USER_PASSWORD ]; then
  67. prosodyctl adduser $EMAIL_ADDRESS
  68. else
  69. USERNAME=$(echo $EMAIL_ADDRESS | awk -F '@' '{print $1}')
  70. DOMAIN_NAME=$(echo $EMAIL_ADDRESS | awk -F '@' '{print $2}')
  71. prosodyctl register $USERNAME $DOMAIN_NAME "$NEW_USER_PASSWORD"
  72. if [ ! "$?" = "0" ]; then
  73. exit 2
  74. fi
  75. fi
  76. exit 0