43 lines
2.0 KiB
Cheetah
43 lines
2.0 KiB
Cheetah
#!/bin/bash
|
|
# Co-op Cloud launcher for mautrix-signal (replaces the image's docker-run.sh).
|
|
#
|
|
# The image's docker-run.sh generates the appservice registration with RANDOM
|
|
# tokens and then writes those tokens back into /data/config.yaml. In this
|
|
# recipe the config is a read-only docker config mount sourced from secrets,
|
|
# so that write can never succeed and the generated tokens would never match
|
|
# the config (synapse reads the registration, the bridge reads the config ->
|
|
# permanent 401). The config is therefore the source of truth: after
|
|
# generation the registration is rewritten to match it, so both sides agree.
|
|
BINARY_NAME=/usr/bin/mautrix-signal
|
|
|
|
if [[ ! -s /data/config.yaml ]]; then
|
|
$BINARY_NAME -c /data/config.yaml -e
|
|
fi
|
|
|
|
if [[ ! -f /data/registration.yaml ]]; then
|
|
# -g generates a registration with random tokens and tries to save them
|
|
# into the (read-only) config; both are corrected below.
|
|
$BINARY_NAME -g -c /data/config.yaml -r /data/registration.yaml || true
|
|
fi
|
|
|
|
if [[ -f /data/registration.yaml ]]; then
|
|
AS_TOKEN=$(cat /run/secrets/signal_as_token)
|
|
HS_TOKEN=$(cat /run/secrets/signal_hs_token)
|
|
if ! grep -q "^as_token: ${AS_TOKEN}$" /data/registration.yaml; then
|
|
sed -i "s/^as_token:.*/as_token: ${AS_TOKEN}/" /data/registration.yaml || true
|
|
fi
|
|
if ! grep -q "^hs_token: ${HS_TOKEN}$" /data/registration.yaml; then
|
|
sed -i "s/^hs_token:.*/hs_token: ${HS_TOKEN}/" /data/registration.yaml || true
|
|
fi
|
|
if ! grep -q "^sender_localpart: signalbot$" /data/registration.yaml; then
|
|
sed -i "s/^sender_localpart:.*/sender_localpart: signalbot/" /data/registration.yaml || true
|
|
fi
|
|
# synapse (uid 991) must be able to read the registration even though the
|
|
# bridge (uid 1337) owns it; the synapse entrypoint chowns the volume at
|
|
# its own start, but make the file readable regardless of ownership.
|
|
chmod 644 /data/registration.yaml 2>/dev/null || true
|
|
fi
|
|
|
|
cd /data
|
|
exec su-exec $UID:$GID $BINARY_NAME -c /data/config.yaml
|