fork 0k-charms
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.

98 lines
1.9 KiB

  1. #!/bin/bash
  2. ## compose: no-hooks
  3. if [ -z "$SERVICE_DATASTORE" ]; then
  4. echo "This script is meant to be run through 'compose' to work properly." >&2
  5. exit 1
  6. fi
  7. . $CHARM_PATH/lib/common
  8. version=0.1
  9. usage="$exname [-h|--help]"
  10. help="
  11. USAGE:
  12. $usage
  13. DESCRIPTION:
  14. Request an invite code.
  15. EXAMPLES:
  16. $exname
  17. "
  18. dbname=
  19. neutralize=
  20. while [ "$1" ]; do
  21. case "$1" in
  22. "--help"|"-h")
  23. print_help >&2
  24. exit 0
  25. ;;
  26. --*|-*)
  27. err "Unexpected optional argument '$1'"
  28. print_usage >&2
  29. exit 1
  30. ;;
  31. *)
  32. err "Unexpected positional argument '$1'"
  33. print_usage >&2
  34. exit 1
  35. ;;
  36. esac
  37. shift
  38. done
  39. set -e
  40. . "$PDS_ENV_FILE"
  41. curl_opts=()
  42. container_network_ip=$(get_healthy_container_ip_for_service "$SERVICE_NAME" 3000 4) || {
  43. err "Please ensure that $DARKYELLOW$service$NORMAL is running before using '$exname'."
  44. exit 1
  45. }
  46. container_ip=${container_network_ip##*:}
  47. container_network=${container_network_ip%%:*}
  48. DEFAULT_CURL_IMAGE=${DEFAULT_CURL_IMAGE:-docker.0k.io/curl}
  49. cmd=(
  50. docker run -i --rm --network "$container_network"
  51. "$DEFAULT_CURL_IMAGE"
  52. --fail \
  53. --silent \
  54. --show-error \
  55. --request POST \
  56. --user "admin:${PDS_ADMIN_PASSWORD}" \
  57. --header "Content-Type: application/json" \
  58. --data '{"useCount": 1}' \
  59. "http://${container_ip}:3000/xrpc/com.atproto.server.createInviteCode"
  60. )
  61. ## XXXvlab: contains password, left only for advanced debug
  62. #echo "COMMAND: ${cmd[@]}" >&2
  63. if ! out=$("${cmd[@]}"); then
  64. err "Failed to request an invite code."
  65. echo " $out" | prefix " $GRAY|$NORMAL " >&2
  66. exit 1
  67. fi
  68. e "$out" | jq -r '.code' || {
  69. err "Failed to parse invite code from response."
  70. echo " $out" | prefix " $GRAY|$NORMAL " >&2
  71. exit 1
  72. }