more example_ynh

This commit is contained in:
yalh76 2022-09-04 23:58:47 +02:00
parent ec044e95c6
commit de293c970f
15 changed files with 291 additions and 343 deletions

View file

@ -18,7 +18,7 @@ current_version=$(cat manifest.json | jq -j '.version|split("~")[0]')
repo=$(cat manifest.json | jq -j '.upstream.code|split("https://github.com/")[1]') repo=$(cat manifest.json | jq -j '.upstream.code|split("https://github.com/")[1]')
# Some jq magic is needed, because the latest upstream release is not always the latest version (e.g. security patches for older versions) # Some jq magic is needed, because the latest upstream release is not always the latest version (e.g. security patches for older versions)
version=$(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '.[] | select( .prerelease != true ) | .tag_name' | sort -V | tail -1) version=$(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '.[] | select( .prerelease != true ) | .tag_name' | sort -V | tail -1)
tarball_url="https://github.com/$repo/archive/refs/tags/$version.tar.gz" assets="https://github.com/$repo/archive/refs/tags/$version.tar.gz"
# Later down the script, we assume the version has only digits and dots # Later down the script, we assume the version has only digits and dots
# Sometimes the release name starts with a "v", so let's filter it out. # Sometimes the release name starts with a "v", so let's filter it out.
@ -31,6 +31,7 @@ fi
echo "Current version: $current_version" echo "Current version: $current_version"
echo "Latest release from upstream: $version" echo "Latest release from upstream: $version"
echo "VERSION=$version" >> $GITHUB_ENV echo "VERSION=$version" >> $GITHUB_ENV
echo "REPO=$repo" >> $GITHUB_ENV
# For the time being, let's assume the script will fail # For the time being, let's assume the script will fail
echo "PROCEED=false" >> $GITHUB_ENV echo "PROCEED=false" >> $GITHUB_ENV
@ -48,29 +49,42 @@ fi
# UPDATE SOURCE FILES # UPDATE SOURCE FILES
#================================================= #=================================================
# Let's download source tarball
asset_url=$assets
echo "Handling asset at $asset_url"
src="app"
# Create the temporary directory # Create the temporary directory
tempdir="$(mktemp -d)" tempdir="$(mktemp -d)"
# Download sources and calculate checksum # Download sources and calculate checksum
filename=${tarball_url##*/} filename=${asset_url##*/}
curl --silent -4 -L "$tarball_url" -o "$tempdir/$filename" curl --silent -4 -L $asset_url -o "$tempdir/$filename"
checksum=$(sha256sum "$tempdir/$filename" | head -c 64) checksum=$(sha256sum "$tempdir/$filename" | head -c 64)
# Delete temporary directory
rm -rf $tempdir
# Get extension
if [[ $filename == *.tar.gz ]]; then
extension=tar.gz
else
extension=${filename##*.}
fi
# Rewrite source file # Rewrite source file
cat <<EOT > conf/app.src cat <<EOT > conf/$src.src
SOURCE_URL=$tarball_url SOURCE_URL=$asset_url
SOURCE_SUM=$checksum SOURCE_SUM=$checksum
SOURCE_SUM_PRG=sha256sum SOURCE_SUM_PRG=sha256sum
SOURCE_FORMAT=tar.gz SOURCE_FORMAT=$extension
SOURCE_IN_SUBDIR=true SOURCE_IN_SUBDIR=true
SOURCE_FILENAME=mautrix-telegram.tar.gz SOURCE_FILENAME=mautrix-telegram.tar.gz
SOURCE_EXTRACT=false SOURCE_EXTRACT=false
EOT EOT
echo "... conf/$src.src updated"
echo "... conf/app.src updated"
# Delete temporary directory
rm -rf $tempdir
#================================================= #=================================================
# SPECIFIC UPDATE STEPS # SPECIFIC UPDATE STEPS

View file

@ -21,6 +21,8 @@
setup_public=0 setup_public=0
upgrade=1 upgrade=1
upgrade=1 from_commit=dfed70e3419d23349690ea2234747ac1de2d7fb0 upgrade=1 from_commit=dfed70e3419d23349690ea2234747ac1de2d7fb0
# 0.11.3~ynh2
upgrade=1 from_commit=d1892c2bdbcea8a30d4596fcd99d13f65e1ab54c
backup_restore=1 backup_restore=1
multi_instance=1 multi_instance=1
port_already_use=1 port_already_use=1

View file

@ -1,13 +1,13 @@
# Homeserver details # Homeserver details
homeserver: homeserver:
# The address that this appservice can use to connect to the homeserver. # The address that this appservice can use to connect to the homeserver.
address: __DOMAIN__ address: https://__DOMAIN__
# The domain of the homeserver (for MXIDs, etc). # The domain of the homeserver (for MXIDs, etc).
domain: __SERVER_NAME__ domain: __SERVER_NAME__
# Whether or not to verify the SSL certificate of the homeserver. # Whether or not to verify the SSL certificate of the homeserver.
# Only applies if address starts with https:// # Only applies if address starts with https://
verify_ssl: __VERIFY_SERVER_SSL_CERTIFICATES__ verify_ssl: true
asmux: __MATRIX_SERVER_SUPPORTS_ASMUX__ asmux: false
# Number of retries for all HTTP requests if the homeserver isn't reachable. # Number of retries for all HTTP requests if the homeserver isn't reachable.
http_retry_count: 4 http_retry_count: 4
# The URL to push real-time bridge status to. # The URL to push real-time bridge status to.
@ -40,7 +40,7 @@ appservice:
# Format examples: # Format examples:
# SQLite: sqlite:///filename.db # SQLite: sqlite:///filename.db
# Postgres: postgres://username:password@hostname/dbname # Postgres: postgres://username:password@hostname/dbname
database: postgres://__MAUTRIX_BRIDGE_USER__:__MAUTRIX_BRIDGE_DB_PWD__@localhost:5432/__MAUTRIX_BRIDGE_DB_NAME__ database: postgres://__DB_USER__:__DB_PWD__@localhost:5432/__DB_NAME__
# Additional arguments for asyncpg.create_pool() or sqlite3.connect() # Additional arguments for asyncpg.create_pool() or sqlite3.connect()
# https://magicstack.github.io/asyncpg/current/api/index.html#asyncpg.pool.create_pool # https://magicstack.github.io/asyncpg/current/api/index.html#asyncpg.pool.create_pool
# https://docs.python.org/3/library/sqlite3.html#sqlite3.connect # https://docs.python.org/3/library/sqlite3.html#sqlite3.connect
@ -574,7 +574,7 @@ logging:
file: file:
class: logging.handlers.RotatingFileHandler class: logging.handlers.RotatingFileHandler
formatter: normal formatter: normal
filename: __LOG_FILENAME__ filename: /var/log/__APP__/__APP__.log
maxBytes: 10485760 maxBytes: 10485760
backupCount: 10 backupCount: 10
console: console:
@ -582,11 +582,11 @@ logging:
formatter: colored formatter: colored
loggers: loggers:
mau: mau:
level: DEBUG level: INFO
telethon: telethon:
level: INFO level: INFO
aiohttp: aiohttp:
level: INFO level: INFO
root: root:
level: DEBUG level: INFO
handlers: [file, console] handlers: [file, console]

View file

@ -1,33 +1 @@
A puppeting bridge between Matrix and Telegram packaged as a YunoHost service. Messages, notifications (and sometimes media) are bridged between a Telegram user and a Matrix user. Currently the Matrix user can NOT invite other Matrix user in a bridged Telegram room, so only someone with a Telegram account can participate to Telegram group conversations. The ["Mautrix-Telegram"](https://docs.mau.fi/bridges/python/telegram/index.html) bridge is a Synapse App Service and relies on postgresql. Therefore, [Synapse for YunoHost](https://github.com/YunoHost-Apps/synapse_ynh) should be installed beforehand. A puppeting bridge between Matrix and Telegram packaged as a YunoHost service. Messages, notifications (and sometimes media) are bridged between a Telegram user and a Matrix user. Currently the Matrix user can NOT invite other Matrix user in a bridged Telegram room, so only someone with a Telegram account can participate to Telegram group conversations. The ["Mautrix-Telegram"](https://docs.mau.fi/bridges/python/telegram/index.html) bridge is a Synapse App Service and relies on postgresql. Therefore, [Synapse for YunoHost](https://github.com/YunoHost-Apps/synapse_ynh) should be installed beforehand.
## List of known public services
* Ask on one of the following rooms: #mautrix_yunohost:matrix.fdn.fr or #telegram:maunium.net
## Bridging usage
** Note that several Telegram and Matrix users can be bridged, each Telegram account has its own bot administration room. If they are in a same Telegram group, only one matrix room will be created. **
### Bridge a Telegram user and a Matrix user
* First your Matrix user or Synapse Server has to be authorized in the Configuration of the bridge (see below)
* Then, invite the bot (default @telegrambot:yoursynapse.domain) in this new Mautrix-Telegram bot administration room.
* If the Bot does bot accept, see the [troubleshooting page](https://docs.mau.fi/bridges/general/troubleshooting.html)
* Send ``!tg help`` to the bot in the created room to know how to control the bot.
See also [upstream wiki Authentication page](https://docs.mau.fi/bridges/python/telegram/authentication.html)
#### Logging into Telegram account
* Type ``login`` or ``login-qr`` (untested) in main management room (`!tg` in any bridge room)
* follow setup instructions from bot
* By defaults, only conversations with very recent messages and groups will be suggested to be bridged
* Accept invitations to the bridged chat rooms
#### Registering the Bridge as a primary device (untested)
* Type ``!tg register <phone>``, where ``<phone>`` is your phone number in the internation format with no space, e.g. ``!tg register +33612345678``
* Answer in the bot room with the verification code that you reveived in SMS.
* Set a profile name with ``!tg set-profile-name <name>``
### Double puppeting
* Log in with ``login-matrix <access token>``
* After logging in, the default Matrix puppet of your Telegram account should leave rooms and your account should join all rooms the puppet was in automatically.
### Relaybot: Bridge a group for several Matrix and several Telegram users to chat together
* see https://docs.mau.fi/bridges/python/telegram/relay-bot.html

4
doc/DESCRIPTION_fr.md Normal file
View file

@ -0,0 +1,4 @@
Une passerelle entre Matrix et Telegram empaquetée comme un service YunoHost. Les messages, médias et notifications sont relayées entre un compte Telegram et un compte Matrix.
La passerelle ["Mautrix-Telegram"](https://docs.mau.fi/bridges/python/telegram/index.html) consiste en un Service d'Application Matrix-Synapse et repose sur une base-de-données postgresql. C'est pourquoi [Synapse for YunoHost](https://github.com/YunoHost-Apps/synapse_ynh) doit être préalablemnet installé.
** Attention : sauvegardez et restaurez toujours les deux applications Yunohost matrix-synapse et mautrix_telegram en même temps!**

View file

@ -1,11 +1,44 @@
### Configuration of the bridge ## List of known public services
* Ask on one of the following rooms: #mautrix_yunohost:matrix.fdn.fr or #telegram:maunium.net
## Bridging usage
** Note that several Telegram and Matrix users can be bridged, each Telegram account has its own bot administration room. If they are in a same Telegram group, only one matrix room will be created. **
### Bridge a Telegram user and a Matrix user
* First your Matrix user or Synapse Server has to be authorized in the Configuration of the bridge (see below)
* Then, invite the bot (default @telegrambot:yoursynapse.domain) in this new Mautrix-Telegram bot administration room.
* If the Bot does bot accept, see the [troubleshooting page](https://docs.mau.fi/bridges/general/troubleshooting.html)
* Send ``!tg help`` to the bot in the created room to know how to control the bot.
See also [upstream wiki Authentication page](https://docs.mau.fi/bridges/python/telegram/authentication.html)
#### Logging into Telegram account
* Type ``login`` or ``login-qr`` (untested) in main management room (`!tg` in any bridge room)
* follow setup instructions from bot
* By defaults, only conversations with very recent messages and groups will be suggested to be bridged
* Accept invitations to the bridged chat rooms
#### Registering the Bridge as a primary device (untested)
* Type ``!tg register <phone>``, where ``<phone>`` is your phone number in the internation format with no space, e.g. ``!tg register +33612345678``
* Answer in the bot room with the verification code that you reveived in SMS.
* Set a profile name with ``!tg set-profile-name <name>``
### Double puppeting
* Log in with ``login-matrix <access token>``
* After logging in, the default Matrix puppet of your Telegram account should leave rooms and your account should join all rooms the puppet was in automatically.
### Relaybot: Bridge a group for several Matrix and several Telegram users to chat together
* see https://docs.mau.fi/bridges/python/telegram/relay-bot.html
## Configuration of the bridge
The bridge is [roughly configured at installation](https://github.com/YunoHost-Apps/mautrix_telegram_ynh/blob/master/conf/config.yaml), e.g. allowed admin and user of the bot. Finer configuration can be done by modifying the The bridge is [roughly configured at installation](https://github.com/YunoHost-Apps/mautrix_telegram_ynh/blob/master/conf/config.yaml), e.g. allowed admin and user of the bot. Finer configuration can be done by modifying the
following configuration file with SSH: following configuration file with SSH:
```/opt/yunohost/mautrix_telegram/config.yaml``` ```/opt/yunohost/mautrix_telegram/config.yaml```
and then restarting the mautrix_telegram service. and then restarting the mautrix_telegram service.
### Documentation ## Documentation
* Official "Mautrix-Telegram" documentation: https://docs.mau.fi/bridges/python/telegram/index.html * Official "Mautrix-Telegram" documentation: https://docs.mau.fi/bridges/python/telegram/index.html
* Matrix room (Matrix Bridges in Yunohost): #mautrix_yunohost:matrix.fdn.fr * Matrix room (Matrix Bridges in Yunohost): #mautrix_yunohost:matrix.fdn.fr
@ -15,6 +48,8 @@ In case you need to upload your logs somewhere, be aware that they contain your
* "Mautrix-Telegram" bridge is based on the [telegram daemon](https://gitlab.com/telegramd/telegramd) project. * "Mautrix-Telegram" bridge is based on the [telegram daemon](https://gitlab.com/telegramd/telegramd) project.
* YunoHost documentation: If more specific documentation is needed, feel free to contribute. * YunoHost documentation: If more specific documentation is needed, feel free to contribute.
## YunoHost specific features
#### Multi-user support #### Multi-user support
* Bot users are not related to Yunohost users. Any Matrix account or Synapse server autorized in the configuration of the bridge can invite/use the bot. * Bot users are not related to Yunohost users. Any Matrix account or Synapse server autorized in the configuration of the bridge can invite/use the bot.
@ -28,7 +63,7 @@ In case you need to upload your logs somewhere, be aware that they contain your
* Multi-instance installation should work. Several bridge instances could be installed for one Matrix-Synapse instance so that one Matrix user can bridge several Telegram accounts. * Multi-instance installation should work. Several bridge instances could be installed for one Matrix-Synapse instance so that one Matrix user can bridge several Telegram accounts.
* Several bridge instances could be installed for each Matrix-Synapse instance to benefit from it. But one bridge can be used by users from several Matrix-Synapse instances. * Several bridge instances could be installed for each Matrix-Synapse instance to benefit from it. But one bridge can be used by users from several Matrix-Synapse instances.
### Troubleshooting ## Troubleshooting
* Check the spelling of the bot name! * Check the spelling of the bot name!
* For slow servers it might be necessary to run ``systemctl edit mautrix_telegram.service`` (also for `coturn.service` and `coturn-synapse.service`) and insert * For slow servers it might be necessary to run ``systemctl edit mautrix_telegram.service`` (also for `coturn.service` and `coturn-synapse.service`) and insert

67
doc/DISCLAIMER_fr.md Normal file
View file

@ -0,0 +1,67 @@
## Liste de passerelles publiques
* Demandez sur un des salons suivants: #mautrix_yunohost:matrix.fdn.fr ou #telegram:maunium.net
## Usages de la passerelle
** Notez que plusieurs comptes Telegram et Matrix peuvent être pontés, chaque compte Telegram connecté a son propre Salon d'Administration. Si plusieurs utilisateur.ice.s du Robot sont dans un même groupe Signal, seul un Salon Matrix sera créé par la passerelle. **
### Bridge a Telegram user and a Matrix user
* First your Matrix user or Synapse Server has to be authorized in the Configuration of the bridge (see below)
* Then, invite the bot (default @telegrambot:yoursynapse.domain) in this new Mautrix-Telegram bot administration room.
* If the Bot does bot accept, see the [troubleshooting page](https://docs.mau.fi/bridges/general/troubleshooting.html)
* Send ``!tg help`` to the bot in the created room to know how to control the bot.
See also [upstream wiki Authentication page](https://docs.mau.fi/bridges/python/telegram/authentication.html)
#### Logging into Telegram account
* Type ``login`` or ``login-qr`` (untested) in main management room (`!tg` in any bridge room)
* follow setup instructions from bot
* By defaults, only conversations with very recent messages and groups will be suggested to be bridged
* Accept invitations to the bridged chat rooms
#### Registering the Bridge as a primary device (untested)
* Type ``!tg register <phone>``, where ``<phone>`` is your phone number in the internation format with no space, e.g. ``!tg register +33612345678``
* Answer in the bot room with the verification code that you reveived in SMS.
* Set a profile name with ``!tg set-profile-name <name>``
### Double puppeting
* Log in with ``login-matrix <access token>``
* After logging in, the default Matrix puppet of your Telegram account should leave rooms and your account should join all rooms the puppet was in automatically.
### Relaybot: Bridge a group for several Matrix and several Telegram users to chat together
* see https://docs.mau.fi/bridges/python/telegram/relay-bot.html
## Documentation
* Official "Mautrix-Telegram" documentation: https://docs.mau.fi/bridges/python/telegram/index.html
* Matrix room (Matrix Bridges in Yunohost): #mautrix_yunohost:matrix.fdn.fr
* Matrix room (upstream app): #telegram:maunium.net
In case you need to upload your logs somewhere, be aware that they contain your contacts' and your phone numbers. Strip them out with
``| sed -r 's/[0-9]{10,}/??/g' ``
* "Mautrix-Telegram" bridge is based on the [telegram daemon](https://gitlab.com/telegramd/telegramd) project.
* YunoHost documentation: If more specific documentation is needed, feel free to contribute.
## Caractéristiques spécifiques YunoHost
#### Support multi-comptes
* Bot users are not related to Yunohost users. Any Matrix account or Synapse server autorized in the configuration of the bridge can invite/use the bot.
* The Telegram bot is a local Matrix-Synapse user, but accessible through federation (synapse public or private).
* Several Telegram and Matrix users can be bridged with one bridge, each user has its own bot administration room.
* If several bot users are in a same Telegram group, only one Matrix room will be created by the bridge.
* See https://github.com/YunoHost-Apps/synapse_ynh#multi-users-support
#### Support multi-instance
* Multi-instance installation should work. Several bridge instances could be installed for one Matrix-Synapse instance so that one Matrix user can bridge several Telegram accounts.
* Several bridge instances could be installed for each Matrix-Synapse instance to benefit from it. But one bridge can be used by users from several Matrix-Synapse instances.
## Troubleshooting
* Check the spelling of the bot name!
* For slow servers it might be necessary to run ``systemctl edit mautrix_telegram.service`` (also for `coturn.service` and `coturn-synapse.service`) and insert
```
[Service]
ExecStartPre=/bin/sleep 90
```
such that it is ensured that synapse is running before the bridge tries to connect.
(If it worked after installation but broke after a restart this probably is it.)

View file

@ -1,55 +0,0 @@
---
name: Bug report
about: When creating a bug report, please use the following template to provide all the relevant information and help debugging efficiently.
---
**How to post a meaningful bug report**
1. *Read this whole template first.*
2. *Determine if you are on the right place:*
- *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change_url...), you are on the right place!*
- *Otherwise, the issue may be due to mautrix_telegram itself. Refer to its documentation or repository for help.*
- *When in doubt, post here and we will figure it out together.*
3. *Delete the italic comments as you write over them below, and remove this guide.*
---
### Describe the bug
*A clear and concise description of what the bug is.*
### Context
- Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...*
- YunoHost version: x.x.x
- I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...*
- Are you in a special context or did you perform some particular tweaking on your YunoHost instance?: *no / yes*
- If yes, please explain:
- Using, or trying to install package version/branch:
- If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`*
### Steps to reproduce
- *If you performed a command from the CLI, the command itself is enough. For example:*
```sh
sudo yunohost app install mautrix_telegram
```
- *If you used the webadmin, please perform the equivalent command from the CLI first.*
- *If the error occurs in your browser, explain what you did:*
1. *Go to '...'*
2. *Click on '...'*
3. *Scroll down to '...'*
4. *See error*
### Expected behavior
*A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.*
### Logs
*When an operation fails, YunoHost provides a simple way to share the logs.*
- *In the webadmin, the error message contains a link to the relevant log page. On that page, you will be able to 'Share with Yunopaste'. If you missed it, the logs of previous operations are also available under Tools > Logs.*
- *In command line, the command to share the logs is displayed at the end of the operation and looks like `yunohost log display [log name] --share`. If you missed it, you can find the log ID of a previous operation using `yunohost log list`.*
*After sharing the log, please copypaste directly the link provided by YunoHost (to help readability, no need to copypaste the entire content of the log here, just the link is enough...)*
*If applicable and useful, add screenshots to help explain your problem.*

View file

@ -1,18 +0,0 @@
## Problem
- *Description of why you made this PR*
## Solution
- *And how do you fix that problem*
## PR Status
- [ ] Code finished.
- [ ] Tested with Package_check.
- [ ] Fix or enhancement tested.
- [ ] Upgrade from last version tested.
- [ ] Can be reviewed and tested.
## Package_check results
---
*If you have access to [App Continuous Integration for packagers](https://yunohost.org/#/packaging_apps_ci) you can provide a link to the package_check results like below, replacing '-NUM-' in this link by the PR number and USERNAME by your username on the ci-apps-dev. Or you provide a screenshot or a pastebin of the results*
[![Build Status](https://ci-apps-dev.yunohost.org/jenkins/job/mautrix_telegram_ynh%20PR-NUM-%20(USERNAME)/badge/icon)](https://ci-apps-dev.yunohost.org/jenkins/job/mautrix_telegram_ynh%20PR-NUM-%20(USERNAME)/)

View file

@ -13,16 +13,7 @@ pkg_dependencies="postgresql python3 zlib1g-dev libjpeg-dev libwebp-dev python3-
#================================================= #=================================================
write_bridge_config () { write_bridge_config () {
domain="https://$domain"
if [ "$botusers" = "local" ]
then
botusers="$server_name"
fi
verify_server_ssl_certificates="true"
matrix_server_supports_asmux="false"
log_filename="/var/log/$app/$app.log"
log_level="error"
ynh_add_config --template="config.yaml" --destination="$mautrix_config_path"
} }
#================================================= #=================================================

View file

@ -26,9 +26,9 @@ ynh_abort_if_errors
ynh_print_info --message="Loading installation settings..." ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
app_service_registration_path=$(ynh_app_setting_get --app=$app --key=app_service_registration_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
mautrix_bridge_db_name=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_name)
#================================================= #=================================================
# DECLARE DATA AND CONF FILES TO BACKUP # DECLARE DATA AND CONF FILES TO BACKUP
@ -56,18 +56,11 @@ ynh_backup --src_path="/etc/logrotate.d/$app"
ynh_backup --src_path="/etc/systemd/system/$app.service" ynh_backup --src_path="/etc/systemd/system/$app.service"
#================================================= #=================================================
# BACKUP VARIOUS FILES # BACKUP THE POSTGRESQL DATABASE
#=================================================
# backup synapse registration file
ynh_backup --src_path="$app_service_registration_path"
#=================================================
# BACKUP THE PostrgeSQL DATABASE
#================================================= #=================================================
ynh_print_info --message="Backing up the PostgreSQL database..." ynh_print_info --message="Backing up the PostgreSQL database..."
ynh_psql_dump_db --database="$mautrix_bridge_db_name" > db.sql ynh_psql_dump_db --database="$db_name" > db.sql
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
ynh_clean_check_starting true
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -28,8 +28,6 @@ botname=$YNH_APP_ARG_BOTNAME
encryption=$YNH_APP_ARG_ENCRYPTION encryption=$YNH_APP_ARG_ENCRYPTION
botadmin=$YNH_APP_ARG_BOTADMIN botadmin=$YNH_APP_ARG_BOTADMIN
botusers=$YNH_APP_ARG_BOTUSERS botusers=$YNH_APP_ARG_BOTUSERS
# TODO new settings specific to telegram
apiid=$YNH_APP_ARG_APIID apiid=$YNH_APP_ARG_APIID
apihash=$YNH_APP_ARG_APIHASH apihash=$YNH_APP_ARG_APIHASH
bottoken=$YNH_APP_ARG_BOTTOKEN bottoken=$YNH_APP_ARG_BOTTOKEN
@ -45,22 +43,7 @@ synapse_instance="synapse__$synapsenumber"
fi fi
server_name=$(ynh_app_setting_get --app $synapse_instance --key server_name) server_name=$(ynh_app_setting_get --app $synapse_instance --key server_name)
domain=$(ynh_app_setting_get --app $synapse_instance --key domain) domain=$(ynh_app_setting_get --app $synapse_instance --key domain)
synapse_config_path="/etc/matrix-$synapse_instance" synapse_registration_path="/etc/matrix-$synapse_instance/app-service"
app_service_registration_path="/etc/matrix-$synapse_instance/app-service"
synapse_name="matrix-$synapse_instance"
synapse_user="matrix-$synapse_instance"
synapse_db_name="matrix_$synapse_instance"
synapse_db_user="matrix_$synapse_instance"
#=================================================
# SET CONSTANTS
#=================================================
#botname_synapse_db_user="@$botname:$server_name"
mautrix_bridge_user=$app
mautrix_bridge_db_name=$app
mautrix_bridge_db_user=$app
upstream_version=$(ynh_app_upstream_version)
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
@ -74,22 +57,18 @@ test ! -e "$final_path" || ynh_die --message="This path already contains a folde
# STORE SETTINGS FROM MANIFEST # STORE SETTINGS FROM MANIFEST
#================================================= #=================================================
ynh_script_progression --message="Storing installation settings..." --weight=7 ynh_script_progression --message="Storing installation settings..." --weight=7
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=server_name --value=$server_name
ynh_app_setting_set --app=$app --key=botname --value=$botname ynh_app_setting_set --app=$app --key=botname --value=$botname
ynh_app_setting_set --app=$app --key=synapse_instance --value=$synapse_instance
ynh_app_setting_set --app=$app --key=app_service_registration_path --value=$app_service_registration_path
ynh_app_setting_set --app=$app --key=encryption --value=$encryption ynh_app_setting_set --app=$app --key=encryption --value=$encryption
ynh_app_setting_set --app=$app --key=mautrix_bridge_db_name --value=$mautrix_bridge_db_name
ynh_app_setting_set --app=$app --key=botadmin --value=$botadmin ynh_app_setting_set --app=$app --key=botadmin --value=$botadmin
ynh_app_setting_set --app=$app --key=botusers --value=$botusers ynh_app_setting_set --app=$app --key=botusers --value=$botusers
ynh_app_setting_set --app=$app --key=apiid --value=$apiid ynh_app_setting_set --app=$app --key=apiid --value=$apiid
ynh_app_setting_set --app=$app --key=apihash --value=$apihash ynh_app_setting_set --app=$app --key=apihash --value=$apihash
ynh_app_setting_set --app=$app --key=bottoken --value=$bottoken ynh_app_setting_set --app=$app --key=bottoken --value=$bottoken
ynh_app_setting_set --app=$app --key=synapse_instance --value=$synapse_instance
ynh_app_setting_set --app=$app --key=mautrix_version --value=$upstream_version ynh_app_setting_set --app=$app --key=server_name --value=$server_name
ynh_app_setting_set --app=$app --key=final_path --value=$final_path ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=synapse_registration_path --value=$synapse_registration_path
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
@ -115,20 +94,19 @@ ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
ynh_script_progression --message="Configuring system user..." --weight=1 ynh_script_progression --message="Configuring system user..." --weight=1
# Create a system user # Create a system user
ynh_system_user_create --username=$mautrix_bridge_user ynh_system_user_create --username=$app --home_dir="$final_path"
#================================================= #=================================================
# CREATE A POSTGRESQL DATABASE # CREATE A POSTGRESQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Creating a PostgreSQL database..." --weight=3 ynh_script_progression --message="Creating a PostgreSQL database..." --weight=3
mautrix_bridge_db_pwd=$(ynh_string_random --length=30) db_name=$(ynh_sanitize_dbid --db_name=$app)
ynh_app_setting_set --app=$app --key=mautrix_bridge_db_pwd --value=$mautrix_bridge_db_pwd db_user=$db_name
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
# Create postgresql database
ynh_psql_test_if_first_run ynh_psql_test_if_first_run
ynh_psql_create_user $mautrix_bridge_db_user $mautrix_bridge_db_pwd ynh_psql_setup_db --db_user=$db_user --db_name=$db_name
ynh_psql_execute_as_root --sql="CREATE DATABASE ""$mautrix_bridge_db_name"" ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER ""$mautrix_bridge_db_user"";" db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
@ -136,27 +114,22 @@ ynh_psql_execute_as_root --sql="CREATE DATABASE ""$mautrix_bridge_db_name"" ENCO
ynh_script_progression --message="Setting up source files..." --weight=3 ynh_script_progression --message="Setting up source files..." --weight=3
ynh_app_setting_set --app=$app --key=final_path --value=$final_path ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# WARNING : theses command are used in INSTALL, UPGRADE (2 times)
# For any update do it in all files
#if [ -n "$(uname -m | grep 64)" ]
#then
# ynh_setup_source --dest_dir=$final_path/ --source_id="amd64_$(lsb_release --codename --short)"
#else
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path/src" ynh_setup_source --dest_dir="$final_path/src"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#================================================= #=================================================
# SPECIFIC SETUP # SPECIFIC SETUP
#================================================= #=================================================
# SET MAUTRIX-BRIDGE CONFIG # ADD A CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Configuring Mautrix-Bridge..." --weight=2 ynh_script_progression --message="Adding a configuration file..." --weight=2
# WARNING : theses command are used in INSTALL, UPGRADE, CONFIG, CHANGE-URL (4 times) # WARNING : theses command are used in INSTALL, UPGRADE, CONFIG, CHANGE-URL (4 times)
# For any update do it in all files # For any update do it in all files
mautrix_config_path="$final_path/config.yaml"
as_token="\"This value is generated when generating the registration\"" as_token="\"This value is generated when generating the registration\""
hs_token="\"This value is generated when generating the registration\"" hs_token="\"This value is generated when generating the registration\""
is_encryption_enabled="$encryption" is_encryption_enabled="$encryption"
@ -165,16 +138,26 @@ if [ $encryption -eq 1 ]; then
is_encryption_enabled="true" is_encryption_enabled="true"
fi fi
write_bridge_config domain="https://$domain"
if [ "$botusers" = "local" ]
then
botusers="$server_name"
fi
ynh_add_config --template="config.yaml" --destination="$final_path/config.yaml"
chmod 400 "$final_path/config.yaml"
chown $app:$app "$final_path/config.yaml"
#================================================= #=================================================
# INSTALL MAUTRIX-BRIDGE PYTHON MODULE # INSTALL MAUTRIX-BRIDGE PYTHON MODULE
#================================================= #=================================================
ynh_script_progression --message="Installing Mautrix-Bridge Python Module..." --weight=6
mkdir -p /var/log/$app mkdir -p /var/log/$app
# Configure Mautrix-Bridge # Configure Mautrix-Bridge
python3 -m venv $final_path python3 -m venv $final_path
export HOME=$final_path # HACK see https://github.com/mautrix/telegram/issues/661 export HOME=$final_path
$final_path/bin/pip3 install --upgrade pip setuptools wheel $final_path/bin/pip3 install --upgrade pip setuptools wheel
$final_path/bin/pip3 install --upgrade $final_path/src/mautrix-telegram.tar.gz[speedups,qr_login] # metrics,e2be,hq_thumbnails,sqlite,formattednumbers $final_path/bin/pip3 install --upgrade $final_path/src/mautrix-telegram.tar.gz[speedups,qr_login] # metrics,e2be,hq_thumbnails,sqlite,formattednumbers
@ -182,19 +165,17 @@ if [ $encryption -eq 1 ]; then
$final_path/bin/pip3 install --upgrade $final_path/src/mautrix-telegram.tar.gz[e2be] $final_path/bin/pip3 install --upgrade $final_path/src/mautrix-telegram.tar.gz[e2be]
fi fi
# -r optional-requirements.txt #=================================================
$final_path/bin/python3 -m mautrix_telegram -g -c "$mautrix_config_path" -r "$app_service_registration_path/$app.yaml" # REGISTER SYNAPSE APP-SERVICE
#=================================================
ynh_script_progression --message="Registering Synapse app-service" --weight=1
# Handled by synapse: synapse_ynh adds all registration files added in $app_service_registration_path to the app_service_config_files list $final_path/bin/python3 -m mautrix_telegram -g -c $final_path/config.yaml -r "$synapse_registration_path/$app.yaml"
/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die --message="Synapse can't restart with the appservice configuration" /opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die --message="Synapse can't restart with the appservice configuration"
#================================================= chown -R $app:$app "$final_path"
# STORE THE CONFIG FILE CHECKSUM ynh_store_file_checksum --file="$synapse_registration_path/$app.yaml"
#================================================= ynh_store_file_checksum --file="$final_path/config.yaml"
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$mautrix_config_path"
ynh_store_file_checksum --file="$app_service_registration_path/$app.yaml"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
@ -204,14 +185,6 @@ ynh_script_progression --message="Configuring a systemd service..." --weight=20
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# WARNING : theses command are used in INSTALL, UPGRADE, RESTORE
# For any update do it in all files
chown $mautrix_bridge_user:root -R $final_path
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
@ -221,15 +194,15 @@ ynh_script_progression --message="Configuring log rotation..." --weight=3
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
# TODO maybe --specific-user?? # TODO maybe --specific-user??
ynh_use_logrotate --logfile "/var/log/$app/$app.log" --specific_user $mautrix_bridge_user ynh_use_logrotate --logfile "/var/log/$app/$app.log" --specific_user $app
chown $mautrix_bridge_user:root -R /var/log/$app chown -R $app:$app /var/log/$app
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." ynh_script_progression --message="Integrating service in YunoHost..."
yunohost service add $app --description "$app daemon for bridging Telegram and Matrix messages" --log "/var/log/$app/$app.log" yunohost service add $app --description="$app daemon for bridging Telegram and Matrix messages" --log="/var/log/$app/$app.log"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
@ -237,7 +210,7 @@ yunohost service add $app --description "$app daemon for bridging Telegram and M
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name=$app --action="start" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -16,22 +16,13 @@ ynh_script_progression --message="Loading installation settings..." --weight=5
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
server_name=$(ynh_app_setting_get --app=$app --key=server_name)
synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance)
app_service_registration_path=$(ynh_app_setting_get --app=$app --key=app_service_registration_path)
botname=$(ynh_app_setting_get --app=$app --key=botname) botname=$(ynh_app_setting_get --app=$app --key=botname)
port=$(ynh_app_setting_get --app=$app --key=port) synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance)
server_name=$(ynh_app_setting_get --app=$app --key=server_name)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
synapse_registration_path=$(ynh_app_setting_get --app=$app --key=synapse_registration_path)
#=================================================
# SET CONSTANTS
#=================================================
synapse_db_name="matrix_$synapse_instance"
botname_synapse_db_user="@$botname:$server_name"
mautrix_bridge_user=$app
mautrix_bridge_db_name=$app
mautrix_bridge_db_user=$app
#================================================= #=================================================
# STANDARD REMOVE # STANDARD REMOVE
@ -68,10 +59,7 @@ ynh_remove_logrotate
ynh_script_progression --message="Removing the PostgreSQL database..." --weight=4 ynh_script_progression --message="Removing the PostgreSQL database..." --weight=4
# Remove a database if it exists, along with the associated user # Remove a database if it exists, along with the associated user
ynh_psql_remove_db --db_user=$mautrix_bridge_db_name --db_name=$mautrix_bridge_db_user ynh_psql_remove_db --db_user=$db_user --db_name=$db_name
ynh_psql_execute_as_root --database=$synapse_db_name --sql="DROP OWNED BY ""$botname"";"
ynh_psql_execute_as_root --database=$synapse_db_name --sql="DROP USER ""$botname"";"
#yunohost app action run $synapse_instance drop_user -a username=$botname
#================================================= #=================================================
# REMOVE APP MAIN DIR # REMOVE APP MAIN DIR
@ -97,10 +85,8 @@ ynh_remove_app_dependencies
ynh_script_progression --message="Removing synapse app service..." --weight=6 ynh_script_progression --message="Removing synapse app service..." --weight=6
# Remove a directory securely # Remove a directory securely
ynh_secure_remove --file="$app_service_registration_path/$app.yaml" ynh_secure_remove --file="$synapse_registration_path/$app.yaml"
/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die --message="Synapse can't restart with the appservice configuration"
/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh \
|| ynh_die --message="Synapse can't restart with the appservice configuration"
# Remove the log files # Remove the log files
ynh_secure_remove --file="/var/log/$app" ynh_secure_remove --file="/var/log/$app"
@ -113,7 +99,7 @@ ynh_secure_remove --file="/var/log/$app"
ynh_script_progression --message="Removing the dedicated system user..." --weight=5 ynh_script_progression --message="Removing the dedicated system user..." --weight=5
# Delete a system user # Delete a system user
ynh_system_user_delete --username=$mautrix_bridge_user ynh_system_user_delete --username=$app
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT

View file

@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
ynh_clean_setup () { ynh_clean_setup () {
ynh_clean_check_starting true
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script
ynh_abort_if_errors ynh_abort_if_errors
@ -27,14 +27,11 @@ ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
mautrix_bridge_user=$app
domain=$(ynh_app_setting_get --app=$app --key=domain)
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
mautrix_bridge_db_name=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
mautrix_bridge_db_user=$mautrix_bridge_db_name db_user=$db_name
mautrix_bridge_db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_pwd)
app_service_registration_path=$(ynh_app_setting_get --app=$app --key=app_service_registration_path)
synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance) synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance)
synapse_registration_path=$(ynh_app_setting_get --app=$app --key=synapse_registration_path)
#================================================= #=================================================
# CHECK IF THE APP CAN BE RESTORED # CHECK IF THE APP CAN BE RESTORED
@ -52,7 +49,7 @@ test ! -d $final_path \
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing) # Create the dedicated user (if not existing)
ynh_system_user_create --username=$app ynh_system_user_create --username=$app --home_dir="$final_path"
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
@ -61,7 +58,9 @@ ynh_script_progression --message="Restoring the app main directory..." --weight=
ynh_restore_file --origin_path="$final_path" ynh_restore_file --origin_path="$final_path"
chown $mautrix_bridge_user:root -R $final_path chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#================================================= #=================================================
# SPECIFIC RESTORATION # SPECIFIC RESTORATION
@ -74,21 +73,31 @@ ynh_script_progression --message="Reinstalling dependencies..." --weight=1
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
#================================================= #=================================================
# RESTORE THE MYSQL DATABASE # RESTORE THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Restoring the MySQL database..." --weight=1 ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=8
ynh_psql_test_if_first_run ynh_psql_test_if_first_run
ynh_psql_create_user $mautrix_bridge_db_user $mautrix_bridge_db_pwd db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
ynh_psql_execute_as_root --sql="CREATE DATABASE ""$mautrix_bridge_db_name"" ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER ""$mautrix_bridge_db_user"";" ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_psql_execute_file_as_root --file="db.sql" --database="$mautrix_bridge_db_name" ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name
#================================================= #=================================================
# RESTORE VARIOUS FILES # INSTALL MAUTRIX-BRIDGE PYTHON MODULE
#================================================= #=================================================
ynh_script_progression --message="Restoring various files..." ynh_script_progression --message="Installing Mautrix-Bridge Python Module..." --weight=6
ynh_restore_file --origin_path="$app_service_registration_path" python3 -m venv $final_path
export HOME=$final_path
$final_path/bin/pip3 install --upgrade pip setuptools wheel
#=================================================
# REGISTER SYNAPSE APP-SERVICE
#=================================================
ynh_script_progression --message="Registering Synapse app-service" --weight=1
$final_path/bin/python3 -m mautrix_telegram -g -c $final_path/config.yaml -r "$synapse_registration_path/$app.yaml"
/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || echo "Synapse can't restart with the appservice configuration"
#================================================= #=================================================
# RESTORE SYSTEMD # RESTORE SYSTEMD
@ -101,7 +110,7 @@ systemctl enable $app.service --quiet
#================================================= #=================================================
# RESTORE THE LOGROTATE CONFIGURATION # RESTORE THE LOGROTATE CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Restoring the logrotate configuration..." ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
ynh_restore_file --origin_path="/etc/logrotate.d/$app" ynh_restore_file --origin_path="/etc/logrotate.d/$app"
@ -117,22 +126,9 @@ yunohost service add $app --description "$app daemon for bridging Telegram and M
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
#=================================================
# GENERIC FINALIZATION
#=================================================
#
# also create an initial log file else the service fails
mkdir /var/log/$app
mkdir /var/log/$app/$app.log
chown $mautrix_bridge_user:root -R /var/log/$app
# after restoring files ensure synapse knows about the bot but don't die on failure
# TODO check (in manifest?) if the selected synapse instance is not already connected to a mautrix_bridge bridge
/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh \
|| echo "Synapse can't restart with the appservice configuration"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================

View file

@ -16,42 +16,38 @@ ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
server_name=$(ynh_app_setting_get --app=$app --key=server_name)
port=$(ynh_app_setting_get --app=$app --key=port)
botname=$(ynh_app_setting_get --app=$app --key=botname) botname=$(ynh_app_setting_get --app=$app --key=botname)
synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance)
app_service_registration_path=$(ynh_app_setting_get --app=$app --key=app_service_registration_path)
encryption=$(ynh_app_setting_get --app=$app --key=encryption) encryption=$(ynh_app_setting_get --app=$app --key=encryption)
mautrix_bridge_user=$app
mautrix_bridge_db_name=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_name)
mautrix_bridge_db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_pwd)
botadmin=$(ynh_app_setting_get --app=$app --key=botadmin) botadmin=$(ynh_app_setting_get --app=$app --key=botadmin)
botusers=$(ynh_app_setting_get --app=$app --key=botusers) botusers=$(ynh_app_setting_get --app=$app --key=botusers)
domain=$(ynh_app_setting_get --app=$app --key=domain)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
port=$(ynh_app_setting_get --app=$app --key=port)
synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance)
server_name=$(ynh_app_setting_get --app=$app --key=server_name)
synapse_registration_path=$(ynh_app_setting_get --app=$app --key=synapse_registration_path)
apiid=$(ynh_app_setting_get --app=$app --key=apiid) apiid=$(ynh_app_setting_get --app=$app --key=apiid)
apihash=$(ynh_app_setting_get --app=$app --key=apihash) apihash=$(ynh_app_setting_get --app=$app --key=apihash)
bottoken=$(ynh_app_setting_get --app=$app --key=bottoken) bottoken=$(ynh_app_setting_get --app=$app --key=bottoken)
upstream_version=$(ynh_app_setting_get --app=$app --key=mautrix_version)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#================================================= #=================================================
# CHECK VERSION # CHECK VERSION
#================================================= #=================================================
ynh_script_progression --message="Checking version..." ynh_script_progression --message="Checking version..." --weight=1
upgrade_type=$(ynh_check_app_version_changed) upgrade_type=$(ynh_check_app_version_changed)
#================================================= #=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#================================================= #=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=5
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade ynh_backup_before_upgrade
ynh_clean_setup () { ynh_clean_setup () {
ynh_clean_check_starting
# Restore it if the upgrade fails # Restore it if the upgrade fails
ynh_restore_upgradebackup ynh_restore_upgradebackup
} }
@ -78,7 +74,7 @@ ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
# Create a dedicated user (if not existing) # Create a dedicated user (if not existing)
ynh_system_user_create --username=$mautrix_bridge_user ynh_system_user_create --username=$app --home_dir="$final_path"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
@ -89,9 +85,13 @@ then
ynh_script_progression --message="Upgrading source files..." --weight=1 ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src # Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path" ynh_setup_source --dest_dir="$final_path/src"
fi fi
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
#================================================= #=================================================
# UPGRADE DEPENDENCIES # UPGRADE DEPENDENCIES
#================================================= #=================================================
@ -102,11 +102,33 @@ ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
#================================================= #=================================================
# SPECIFIC UPGRADE # SPECIFIC UPGRADE
#================================================= #=================================================
# UPGRADE PYTHON PACKAGE # UPDATE A CONFIG FILE
#================================================= #=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=2
# main configuration
ynh_backup_if_checksum_is_different --file="$final_path/config.yaml"
# as_token hs_token are autogenerated, save them before regenerating the config
as_token=$(grep "as_token:" "$final_path/config.yaml" | sed -r "s/ *as_token: *//")
hs_token=$(grep "hs_token:" "$final_path/config.yaml" | sed -r "s/ *hs_token: *//")
# ynh_replace_string --match_string=__AS_TOKEN__ --replace_string="$as_token" --target_file="$final_path/config.yaml"
# ynh_replace_string --match_string=__HS_TOKEN__ --replace_string="$hs_token" --target_file="$final_path/config.yaml"
is_encryption_enabled="$encryption"
if [ $encryption -eq 1 ]; then
is_encryption_enabled="true"
fi
ynh_add_config --template="../conf/config.yaml" --destination="$final_path/config.yaml"
chmod 400 "$final_path/config.yaml"
chown $app:$app "$final_path/config.yaml"
#=================================================
# UPGRADE MAUTRIX-BRIDGE PYTHON MODULE
#=================================================
ynh_script_progression --message="Upgrading Mautrix-Bridge Python Module..." --weight=2
if [ "$upgrade_type" == "UPGRADE_APP" ]; then
ynh_script_progression --message="Upgrading python packages..." --weight=1
python3 -m venv $final_path python3 -m venv $final_path
export HOME=$final_path export HOME=$final_path
$final_path/bin/pip3 install --upgrade pip setuptools wheel $final_path/bin/pip3 install --upgrade pip setuptools wheel
@ -115,36 +137,19 @@ if [ "$upgrade_type" == "UPGRADE_APP" ]; then
if [ $encryption -eq 1 ]; then if [ $encryption -eq 1 ]; then
$final_path/bin/pip3 install --upgrade $final_path/src/mautrix-telegram.tar.gz[e2be] $final_path/bin/pip3 install --upgrade $final_path/src/mautrix-telegram.tar.gz[e2be]
fi fi
fi
#================================================= #=================================================
# UPDATE A CONFIG FILE # REGISTER SYNAPSE APP-SERVICE
#================================================= #=================================================
ynh_script_progression --message="Updating a configuration file..." ynh_script_progression --message="Registering Synapse app-service" --weight=1
# main configuration $final_path/bin/python3 -m mautrix_telegram -g -c $final_path/config.yaml -r "$synapse_registration_path/$app.yaml"
mautrix_config_path="$final_path/config.yaml" /opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die --message="Synapse can't restart with the appservice configuration"
ynh_backup_if_checksum_is_different --file="$mautrix_config_path"
# as_token hs_token are autogenerated, save them before regenerating the config
as_token=$(grep "as_token:" "$mautrix_config_path" | sed -r "s/ *as_token: *//")
hs_token=$(grep "hs_token:" "$mautrix_config_path" | sed -r "s/ *hs_token: *//")
# ynh_replace_string --match_string=__AS_TOKEN__ --replace_string="$as_token" --target_file="$mautrix_config_path"
# ynh_replace_string --match_string=__HS_TOKEN__ --replace_string="$hs_token" --target_file="$mautrix_config_path"
is_encryption_enabled="$encryption"
if [ $encryption -eq 1 ]; then # Set permissions on app files
is_encryption_enabled="true" chown -R $app:$app "$final_path"
fi ynh_store_file_checksum --file="$synapse_registration_path/$app.yaml"
ynh_store_file_checksum --file="$final_path/config.yaml"
write_bridge_config
# upgrade the app-service-registration
ynh_backup_if_checksum_is_different --file="$app_service_registration_path/$app.yaml"
$final_path/bin/python3 -m mautrix_telegram -g -c "$mautrix_config_path" -r "$app_service_registration_path/$app.yaml"
# Recalculate and store the checksum of the file for the next upgrade.
ynh_store_file_checksum --file="$mautrix_config_path"
ynh_store_file_checksum --file="$app_service_registration_path/$app.yaml"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD
@ -154,13 +159,6 @@ ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_add_systemd_config
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
chown $mautrix_bridge_user:root -R $final_path
#================================================= #=================================================
# GENERIC FINALIZATION # GENERIC FINALIZATION
#================================================= #=================================================
@ -170,29 +168,23 @@ ynh_script_progression --message="Upgrading logrotate configuration..." --weight
# Use logrotate to manage app-specific logfile(s) # Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append --logfile "/var/log/$app/$app.log" ynh_use_logrotate --non-append --logfile "/var/log/$app/$app.log"
chown -R $app:$app /var/log/$app
#================================================= #=================================================
# INTEGRATE SERVICE IN YUNOHOST # INTEGRATE SERVICE IN YUNOHOST
#================================================= #=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description "$app daemon for bridging Telegram and Matrix messages" --log "/var/log/$app/$app.log" yunohost service add $app --description="$app daemon for bridging Telegram and Matrix messages" --log="/var/log/$app/$app.log"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service
ynh_systemd_action --service_name=$app --action="start" ynh_systemd_action --service_name=$app --action="start"
#=================================================
# RELOAD SYNAPSE
#=================================================
ynh_script_progression --message="Reloading synapse server..." --weight=1
/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh \
|| ynh_die --message="Synapse can't restart with the appservice configuration"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================