-
Notifications
You must be signed in to change notification settings - Fork 5
Add script to extract Synapse configuration values #352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hanthor
wants to merge
1
commit into
element-hq:main
Choose a base branch
from
hanthor:generic-migration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright 2025 New Vector Ltd | ||
# | ||
# SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
set -xe | ||
|
||
|
||
targetDirectory="$1" | ||
homeserverconfig="$2" | ||
|
||
|
||
if [ -z "$targetDirectory" ]; then | ||
echo "Please provide a valid path for the ESS-Helm values directory" | ||
echo "Usage: $0 <target_directory> <homeserver.yaml>" | ||
echo "Example: $0 ~/ess-helm-values /matrx/synapse/config/homeserver.yaml" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$homeserverconfig" ]; then | ||
if [ -f "homeserver.yaml" ]; then | ||
homeserverconfig="homeserver.yaml" | ||
else | ||
echo "Please provide a valid path for the homeserver.yaml file" | ||
echo "try find / -name homeserver.yaml or copy the yaml file to the current directory" | ||
echo "and run the script again" | ||
echo "Usage: $0 <target_directory> <homeserver.yaml>" | ||
echo "Example: $0 ~/ess-helm-values /matrx/synapse/config/homeserver.yaml" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
read -p "Is your synapse running in a docker container? (y/n): " isDocker | ||
if [[ "$isDocker" == "y" ]]; then | ||
# Get the list of running containers | ||
containers=$(docker ps --format '{{.Names}}') | ||
echo "Select the Synapse container from the list:" | ||
select synapseContainer in $containers; do | ||
if [[ -n "$synapseContainer" ]]; then | ||
echo "You selected: $synapseContainer" | ||
break | ||
else | ||
echo "Invalid selection. Please try again." | ||
fi | ||
done | ||
fi | ||
|
||
|
||
if [ ! -d "$targetDirectory" ]; then | ||
mkdir -p "$targetDirectory" | ||
fi | ||
|
||
touch "$targetDirectory/hostnames.yaml" | ||
touch "$targetDirectory/secrets.yaml" | ||
|
||
servername=$(yq '.servername' "$homeserverconfig") | ||
synapseHost=$(yq '(.public_baseurl | match "https://(.+)/").captures[0].string' "$homeserverconfig") | ||
macaroon=$(yq '.macaroon_secret_key' "$homeserverconfig") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Synapse supports |
||
registrationSharedSecret=$(yq '.registration_shared_secret' "$homeserverconfig") | ||
|
||
# Check if the Synapse container is running | ||
if [[ "$isDocker" == "y" ]]; then | ||
if ! docker ps --format '{{.Names}}' | grep -q "$synapseContainer"; then | ||
echo "Error: Synapse container '$synapseContainer' is not running." | ||
exit 1 | ||
fi | ||
fi | ||
|
||
if [ "$isDocker" == "y" ]; then | ||
# Get the path to the signing key from the Docker container | ||
# Ensure $homeserverconfig contains the correct path accessible from *outside* the container | ||
signingKey=$(docker exec "$synapseContainer" cat "$(yq '.signing_key_path' "$homeserverconfig")") | ||
else | ||
# Get the path to the signing key from the local file system | ||
signingKey=$(cat "$(yq '.signing_key_path' "$homeserverconfig")") | ||
fi | ||
|
||
if [ -z "$signingKey" ]; then | ||
echo "Error: signing key not found." | ||
exit 1 | ||
fi | ||
if [ -z "$macaroon" ]; then | ||
echo "Error: macaroon not found." | ||
exit 1 | ||
fi | ||
if [ -z "$servername" ]; then | ||
echo "Error: servername not found." | ||
exit 1 | ||
fi | ||
|
||
yq -i ".serverName |= \"$servername\"" "$targetDirectory/hostnames.yaml" | ||
yq -i ".synapse.ingress.host |= \"$synapseHost\"" "$targetDirectory/hostnames.yaml" | ||
yq -i ".synapse.macaroon.value |= \"$macaroon\"" "$targetDirectory/secrets.yaml" | ||
yq -i ".synapse.signingKey.value |= \"$signingKey\"" "$targetDirectory/secrets.yaml" | ||
yq -i ".synapse.registrationSharedSecret.value |= \"$registrationSharedSecret\"" "$targetDirectory/secrets.yaml" | ||
|
||
echo "Verify that the values are correct:" | ||
echo "Servername (should be the ending of your mxids @user:servername)" | ||
echo "for example for the mxid @alice:matrix.org the servername is matrix.org)" | ||
echo "Servername: $servername" | ||
echo "Synapse Host: $synapseHost" | ||
echo "Signing Key: $signingKey" | ||
echo "Macaroon: $macaroon" | ||
echo "Registration Shared Secret: $registrationSharedSecret" | ||
echo "Synapse container: $synapseContainer" | ||
echo "Synapse container is running: $isDocker" | ||
echo "Synapse container name: $synapseContainer" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the migration docs with your script usage please?