From 2a18291f485fa77201f500b0d3477dc7940f7b3b Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 17 Jan 2025 15:43:47 +0100 Subject: [PATCH] add script to setup bridge tokens --- README.md | 70 ++++++++++++++++++++++++++++++++++++------------------- abra.sh | 33 ++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index a423af4..b737ee3 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,6 @@ For all Bridges: ### Telegram bridging -> WIP docs - You need to get your bot setup on the telegram side first by creating a [telegram app](https://my.telegram.org/apps) and a [telegram bot](https://docs.mau.fi/bridges/python/telegram/relay-bot.html#setup) and have these values: ``` @@ -63,25 +61,36 @@ api_id: ... api_hash: ... telegram_bot_token: ... ``` +Experimental script for a automated token replacement: +``` +DOMAIN= +abra app secret insert $DOMAIN telegram_api_hash v1 +abra app secret insert $DOMAIN telegram_bot_token v1 +abra app secret generate -a $DOMAIN -A rough guide for the following steps: +abra app deploy $DOMAIN +abra app cmd -l $DOMAIN set_bridge_tokens telegram +``` + +Alternatively a manual guide for the necessary steps: ``` -abra app secret insert telegram_api_hash v1 -abra app secret insert telegram_bot_token v1 -abra app secret generate -a +DOMAIN= +abra app secret insert $DOMAIN telegram_api_hash v1 +abra app secret insert $DOMAIN telegram_bot_token v1 +abra app secret generate -a $DOMAIN -abra app deploy -abra app run matrix.fva.wtf telegram_bridge cat /data/registration.yaml -abra app undeploy +abra app deploy $DOMAIN +abra app run $DOMAIN telegrambridge cat /data/registration.yaml +abra app undeploy $DOMAIN -abra app secret rm telegram_as_token -abra app secret insert telegram_as_token v1 +abra app secret rm $DOMAIN telegram_as_token +abra app secret insert $DOMAIN telegram_as_token v1 -abra app secret rm telegram_as_token -abra app secret insert telegram_hs_token v1 +abra app secret rm $DOMAIN telegram_hs_token +abra app secret insert $DOMAIN telegram_hs_token v1 -abra app deploy +abra app deploy $DOMAIN ``` Some helpful documentation: @@ -110,16 +119,29 @@ Some helpful documentation: ### Signal bridging -> WIP docs +Experimental script for a more automated token replacement: +``` +DOMAIN= +abra app secret generate -a $DOMAIN +abra app deploy $DOMAIN +abra app cmd -l $DOMAIN set_bridge_tokens signal +``` +Alternatively a manual guide for the necessary steps: +``` +DOMAIN= +abra app secret insert $DOMAIN signal_hs_token v1 foo +abra app secret insert $DOMAIN signal_as_token v1 foo +abra app secret generate $DOMAIN -a +abra app deploy $DOMAIN +abra app run $DOMAIN signalbridge cat /data/registration.yaml -OK, it's also awful to set this up. Do you see a pattern emerging :) +abra app secret rm $DOMAIN signal_as_token +abra app secret insert $DOMAIN signal_as_token v1 +abra app secret rm $DOMAIN signal_hs_token +abra app secret insert $DOMAIN signal_hs_token v1 -- fake that you have the required tokens: - - `abra app secret insert example.com signal_hs_token v1 foo` - - `abra app secret insert example.com signal_as_token v1 foo` -- generate the database password: - - `abra app secret generate example.com -a` -- deploy the thing and then check the `/data/registration.yaml` -- rm the fake `signal_hs/as_token` values and re-insert the new ones from `registration.yaml` -- re-deploy the whole thing and then it should come up, message `@signalbot:example.com` to test +abra app deploy $DOMAIN +``` + +- message `@signalbot:example.com` to test - See the [docs](https://docs.mau.fi/bridges/go/signal/authentication.html) for authentication diff --git a/abra.sh b/abra.sh index 726219b..0191b4a 100644 --- a/abra.sh +++ b/abra.sh @@ -18,3 +18,36 @@ set_admin () { fi psql -U synapse -c "UPDATE users SET admin = 1 WHERE name = '@$admin:$DOMAIN'"; } + +set_bridge_tokens() { + if [ -z "$1" ]; then + echo "Error: Missing parameter. Usage: set_bridge_tokens " + return 1 + fi + + BRIDGETYPE=$1 + echo "retrieve tokens from registration.yaml..." + output=$(abra app run $DOMAIN ${BRIDGETYPE}bridge cat /data/registration.yaml) + if [ $? -ne 0 ]; then + echo "Error: Failed to retrieve registration.yaml for ${BRIDGETYPE} bridge:" + echo "$output" + return 1 + fi + + hs_token=$(echo "$output" | grep 'hs_token:' | awk '{print $2}') + as_token=$(echo "$output" | grep 'as_token:' | awk '{print $2}') + + echo "HS Token: $hs_token" + echo "AS Token: $as_token" + echo "UNDEPLOY $DOMAIN?" + abra app undeploy $DOMAIN + + echo "Replacing tokens:" + abra app secret rm $DOMAIN ${BRIDGETYPE}_as_token + abra app secret insert $DOMAIN ${BRIDGETYPE}_as_token v1 $as_token + abra app secret rm $DOMAIN ${BRIDGETYPE}_hs_token + abra app secret insert $DOMAIN ${BRIDGETYPE}_hs_token v1 $hs_token + + echo "Redeploying $DOMAIN..." + abra app deploy -n $DOMAIN +}