docker-run.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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_instagram -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_instagram -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. # Define functions.
  17. function fixperms {
  18. chown -R $UID:$GID /data
  19. # /opt/mautrix-instagram is read-only, so disable file logging if it's pointing there.
  20. if [[ "$(yq e '.logging.handlers.file.filename' /data/config.yaml)" == "./mautrix-instagram.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. cd /opt/mautrix-instagram
  26. if [ ! -f /data/config.yaml ]; then
  27. cp example-config.yaml /data/config.yaml
  28. echo "Didn't find a config file."
  29. echo "Copied default config file to /data/config.yaml"
  30. echo "Modify that config file to your liking."
  31. echo "Start the container again after that to generate the registration file."
  32. fixperms
  33. exit
  34. fi
  35. if [ ! -f /data/registration.yaml ]; then
  36. python3 -m mautrix_instagram -g -c /data/config.yaml -r /data/registration.yaml || exit $?
  37. echo "Didn't find a registration file."
  38. echo "Generated one for you."
  39. echo "See https://docs.mau.fi/bridges/general/registering-appservices.html on how to use it."
  40. fixperms
  41. exit
  42. fi
  43. fixperms
  44. exec su-exec $UID:$GID python3 -m mautrix_instagram -c /data/config.yaml