diff --git a/hosts/profiles/matrix/register-user.sh b/hosts/profiles/matrix/register-user.sh new file mode 100755 index 0000000..0530d3c --- /dev/null +++ b/hosts/profiles/matrix/register-user.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env nix-shell +#! nix-shell -i bash -p matrix-synapse + +set -euo pipefail + +SYNAPSE_CONFIG="/run/agenix/synapse-config" + +if [ $# -eq 0 ]; then + echo "Usage: register-user.sh -u USERNAME -p PASSWORD [--no-admin | -a]" + echo "Example: register-user.sh -u alice -p PLEASECHANGETHISPASSWORD --no-admin" + exit 1 +fi + +SHARED_SECRET=$(sudo sed -n 's/.*registration_shared_secret:[[:space:]]*"\?\([^"]*\)"\?.*/\1/p' "$SYNAPSE_CONFIG") + +if [ -z "$SHARED_SECRET" ]; then + echo "Error: Could not extract registration_shared_secret from $SYNAPSE_CONFIG" + exit 1 +fi + +register_new_matrix_user \ + -k "$SHARED_SECRET" \ + "$@" \ + http://localhost:8448