1#!/bin/bash
2set -o errexit
3set -o nounset
4set -o pipefail
5
6source "$(dirname "$0")/../pds.env"
7
8# curl a URL and fail if the request fails.
9function curl_cmd_get {
10 curl --fail --silent --show-error "$@"
11}
12
13# curl a URL and fail if the request fails.
14function curl_cmd_post {
15 curl --fail --silent --show-error --request POST --header "Content-Type: application/json" "$@"
16}
17
18# curl a URL but do not fail if the request fails.
19function curl_cmd_post_nofail {
20 curl --silent --show-error --request POST --header "Content-Type: application/json" "$@"
21}
22
23USERNAME="${1:-}"
24
25if [[ "${USERNAME}" == "" ]]; then
26 read -p "Enter a username: " USERNAME
27fi
28
29if [[ "${USERNAME}" == "" ]]; then
30 echo "ERROR: missing USERNAME parameter." >/dev/stderr
31 echo "Usage: $0 ${SUBCOMMAND} <USERNAME>" >/dev/stderr
32 exit 1
33fi
34
35PASSWORD="password"
36INVITE_CODE="$(curl_cmd_post \
37 --user "admin:${PDS_ADMIN_PASSWORD}" \
38 --data '{"useCount": 1}' \
39 "https://${PDS_HOSTNAME}/xrpc/com.atproto.server.createInviteCode" | jq --raw-output '.code'
40)"
41RESULT="$(curl_cmd_post_nofail \
42 --data "{\"email\":\"${USERNAME}@${PDS_HOSTNAME}\", \"handle\":\"${USERNAME}.${PDS_HOSTNAME}\", \"password\":\"${PASSWORD}\", \"inviteCode\":\"${INVITE_CODE}\"}" \
43 "https://${PDS_HOSTNAME}/xrpc/com.atproto.server.createAccount"
44)"
45
46DID="$(echo $RESULT | jq --raw-output '.did')"
47if [[ "${DID}" != did:* ]]; then
48 ERR="$(echo ${RESULT} | jq --raw-output '.message')"
49 echo "ERROR: ${ERR}" >/dev/stderr
50 echo "Usage: $0 <EMAIL> <HANDLE>" >/dev/stderr
51 exit 1
52fi
53
54echo
55echo "Account created successfully!"
56echo "-----------------------------"
57echo "Handle : ${USERNAME}.${PDS_HOSTNAME}"
58echo "DID : ${DID}"
59echo "Password : ${PASSWORD}"
60echo "-----------------------------"
61echo "This is a test account with an insecure password."
62echo "Make sure it's only used for development."
63echo