docker-run.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/sh
  2. if [ ! -z "$MAUTRIX_DIRECT_STARTUP" ]; then
  3. if [ $(id -u) == 0 ]; then
  4. echo "|------------------------------------------|"
  5. echo "| Warning: running bridge unsafely as root |"
  6. echo "|------------------------------------------|"
  7. fi
  8. exec python3 -m mautrix_signal -c /data/config.yaml
  9. elif [ $(id -u) != 0 ]; then
  10. echo "The startup script must run as root. It will use su-exec to drop permissions before running the bridge."
  11. echo "To bypass the startup script, either set the `MAUTRIX_DIRECT_STARTUP` environment variable,"
  12. echo "or just use `python3 -m mautrix_signal -c /data/config.yaml` as the run command."
  13. echo "Note that the config and registration will not be auto-generated when bypassing the startup script."
  14. exit 1
  15. fi
  16. cd /opt/mautrix-signal
  17. function fixperms {
  18. chown -R $UID:$GID /data
  19. # /opt/mautrix-signal is read-only, so disable file logging if it's pointing there.
  20. if [[ "$(yq e '.logging.handlers.file.filename' /data/config.yaml)" == "./mautrix-signal.log" ]]; then
  21. yq -I4 e -i 'del(.logging.root.handlers[] | select(. == "file"))' /data/config.yaml
  22. yq -I4 e -i 'del(.logging.handlers.file)' /data/config.yaml
  23. fi
  24. }
  25. if [ ! -f /data/config.yaml ]; then
  26. cp example-config.yaml /data/config.yaml
  27. yq -I4 e -i 'del(.logging.root.handlers[] | select(. == "file"))' /data/config.yaml
  28. yq -I4 e -i 'del(.logging.handlers.file)' /data/config.yaml
  29. yq -I4 e -i '.signal.socket_path = "/signald/signald.sock"' /data/config.yaml
  30. yq -I4 e -i '.signal.outgoing_attachment_dir = "/signald/attachments"' /data/config.yaml
  31. yq -I4 e -i '.signal.avatar_dir = "/signald/avatars"' /data/config.yaml
  32. yq -I4 e -i '.signal.data_dir = "/signald/data"' /data/config.yaml
  33. echo "Didn't find a config file."
  34. echo "Copied default config file to /data/config.yaml"
  35. echo "Modify that config file to your liking."
  36. echo "Start the container again after that to generate the registration file."
  37. fixperms
  38. exit
  39. fi
  40. if [ ! -f /data/registration.yaml ]; then
  41. python3 -m mautrix_signal -g -c /data/config.yaml -r /data/registration.yaml || exit $?
  42. echo "Didn't find a registration file."
  43. echo "Generated one for you."
  44. echo "See https://docs.mau.fi/bridges/general/registering-appservices.html on how to use it."
  45. fixperms
  46. exit
  47. fi
  48. fixperms
  49. exec su-exec $UID:$GID python3 -m mautrix_signal -c /data/config.yaml