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