You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

register-jaas-account.sh 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. set -e
  3. EMAIL=$1
  4. DOMAIN=$2
  5. if [ -z "${DOMAIN}" ] || [ -z "${EMAIL}" ]; then
  6. echo "You need to provide email and domain as parameters."
  7. exit 1
  8. fi
  9. JITSI_INSTALLATION="DEBIAN"
  10. JAAS_ENDPOINT="https://account-provisioning.cloudflare.jitsi.net/operations"
  11. CHALLENGE_FILE="/usr/share/jitsi-meet/.well-known/jitsi-challenge.txt"
  12. SUPPORT_MSG="Reach out to JaaS support or retry with /usr/share/jitsi-meet/scripts/register-jaas-account.sh"
  13. create_error=0
  14. create_data=$(curl -s -f -X 'POST' "${JAAS_ENDPOINT}" -H 'Content-Type: application/json' -H 'accept: */*' \
  15. -d "{ \"domain\": \"${DOMAIN}\", \"email\": \"${EMAIL}\", \"jitsiInstallation\": \"${JITSI_INSTALLATION}\" }") || create_error=$?
  16. if [ ${create_error} -ne 0 ]; then
  17. echo "Account creation failed. Status: ${create_error}, response: ${create_data}"
  18. exit 2
  19. fi
  20. # make sure .well-known exists
  21. mkdir -p "$(dirname "$CHALLENGE_FILE")"
  22. # Creating the challenge file
  23. echo "${create_data}" | jq -r .challenge > ${CHALLENGE_FILE}
  24. op_id=$(echo "${create_data}" | jq -r .operationId)
  25. ready_error=0
  26. ready_data=$(curl -s -f -X 'PUT' "${JAAS_ENDPOINT}/${op_id}/ready") || ready_error=$?
  27. if [ ${ready_error} -ne 0 ]; then
  28. echo "Validating domain failed. Status: ${ready_error}"
  29. echo "Response: "
  30. echo "${ready_data}" | jq -r
  31. echo "${SUPPORT_MSG}"
  32. echo
  33. exit 3
  34. fi
  35. SLEEP_TIME=0
  36. WAIT_BEFORE_CHECK=10
  37. TIMEOUT=60
  38. echo -n "Creating..."
  39. (while true; do
  40. provisioned_data=$(curl -s -f "${JAAS_ENDPOINT}/${op_id}")
  41. status=$(echo "${provisioned_data}" | jq -r .status)
  42. if [ "${status}" == "PROVISIONED" ]; then
  43. echo ""
  44. echo "=================="
  45. echo ""
  46. echo "JaaS account was created. To finish setup follow the email that was sent."
  47. echo ""
  48. echo "=================="
  49. exit 0;
  50. elif [ "${status}" == "FAILED" ]; then
  51. echo ""
  52. echo "=================="
  53. echo ""
  54. echo "JaaS account creation failed:${provisioned_data}"
  55. echo ""
  56. echo "=================="
  57. exit 4
  58. elif [ "${status}" == "VERIFIED" ] && [ "${verified}" != "true" ]; then
  59. echo -n "Account was successfully verified..."
  60. verified="true"
  61. fi
  62. if [ ${SLEEP_TIME} -ge ${TIMEOUT} ]; then
  63. echo ""
  64. echo "=================="
  65. echo ""
  66. echo "Timeout creating account. ${SUPPORT_MSG}"
  67. echo ""
  68. echo "=================="
  69. exit 5
  70. fi
  71. echo -n "waiting..."
  72. sleep ${WAIT_BEFORE_CHECK}
  73. SLEEP_TIME=$((SLEEP_TIME+WAIT_BEFORE_CHECK))
  74. done)
  75. rm ${CHALLENGE_FILE} || true