add script to setup bridge tokens
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Simon 2025-01-17 15:43:47 +01:00
parent 943ed58db4
commit 2a18291f48
2 changed files with 79 additions and 24 deletions

View File

@ -54,8 +54,6 @@ For all Bridges:
### Telegram bridging ### 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: 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: ... api_hash: ...
telegram_bot_token: ... telegram_bot_token: ...
``` ```
Experimental script for a automated token replacement:
```
DOMAIN=<domain>
abra app secret insert $DOMAIN telegram_api_hash v1 <secret>
abra app secret insert $DOMAIN telegram_bot_token v1 <secret>
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 <domain> telegram_api_hash v1 <secret> DOMAIN=<domain>
abra app secret insert <domain> telegram_bot_token v1 <secret> abra app secret insert $DOMAIN telegram_api_hash v1 <secret>
abra app secret generate -a <domain> abra app secret insert $DOMAIN telegram_bot_token v1 <secret>
abra app secret generate -a $DOMAIN
abra app deploy <domain> abra app deploy $DOMAIN
abra app run matrix.fva.wtf telegram_bridge cat /data/registration.yaml abra app run $DOMAIN telegrambridge cat /data/registration.yaml
abra app undeploy <domain> abra app undeploy $DOMAIN
abra app secret rm <domain> telegram_as_token abra app secret rm $DOMAIN telegram_as_token
abra app secret insert <domain> telegram_as_token v1 <secret> abra app secret insert $DOMAIN telegram_as_token v1 <secret>
abra app secret rm <domain> telegram_as_token abra app secret rm $DOMAIN telegram_hs_token
abra app secret insert <domain> telegram_hs_token v1 <secret> abra app secret insert $DOMAIN telegram_hs_token v1 <secret>
abra app deploy <domain> abra app deploy $DOMAIN
``` ```
Some helpful documentation: Some helpful documentation:
@ -110,16 +119,29 @@ Some helpful documentation:
### Signal bridging ### Signal bridging
> WIP docs Experimental script for a more automated token replacement:
```
DOMAIN=<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=<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 <secret>
abra app secret rm $DOMAIN signal_hs_token
abra app secret insert $DOMAIN signal_hs_token v1 <secret>
- fake that you have the required tokens: abra app deploy $DOMAIN
- `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: - message `@signalbot:example.com` to test
- `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
- See the [docs](https://docs.mau.fi/bridges/go/signal/authentication.html) for authentication - See the [docs](https://docs.mau.fi/bridges/go/signal/authentication.html) for authentication

33
abra.sh
View File

@ -18,3 +18,36 @@ set_admin () {
fi fi
psql -U synapse -c "UPDATE users SET admin = 1 WHERE name = '@$admin:$DOMAIN'"; 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 <BRIDGETYPE>"
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
}