From 158e34750d689b4a66e093a9709afaaa12aec665 Mon Sep 17 00:00:00 2001 From: nathanael-h Date: Tue, 30 Nov 2021 15:52:54 +0100 Subject: [PATCH 01/12] Update sha256 source sum --- conf/app.src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/app.src b/conf/app.src index 8950e93..83d4f09 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ SOURCE_URL=https://github.com/tulir/mautrix-facebook/archive/v0.3.0.tar.gz -SOURCE_SUM=992e491a3e34bd42ddfba0b3aef7869a7a7c03171560783ec23a692d1f0d79a1 +SOURCE_SUM=0b31c0a865d71bc76bed541ee8e57dd790a67197f62883032a7ae05b9658642b SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true From 6fdffa0133c50ea971bf662586de626a950323d0 Mon Sep 17 00:00:00 2001 From: nathanael-h Date: Tue, 30 Nov 2021 23:18:40 +0100 Subject: [PATCH 02/12] Changes to match the signal_ynh package and improve backup, restore, and upgrade. It should fix issue #4 --- conf/config.yaml | 34 ++++++++------- manifest.json | 4 +- scripts/backup | 28 +++++------- scripts/install | 75 +++++++++++++------------------- scripts/remove | 27 ++++++------ scripts/restore | 111 ++++++++++++++++++++++++++++++++--------------- scripts/upgrade | 110 +++++++++++++++++++++++++++++++--------------- 7 files changed, 225 insertions(+), 164 deletions(-) diff --git a/conf/config.yaml b/conf/config.yaml index 38eb51d..ca95704 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -1,14 +1,11 @@ # Homeserver details homeserver: # The address that this appservice can use to connect to the homeserver. - # address: https://example.com - address: __DOMAIN__ + address: https://__DOMAIN__ # The domain of the homeserver (for MXIDs, etc). - # domain: example.com domain: __SERVER_NAME__ # Whether or not to verify the SSL certificate of the homeserver. # Only applies if address starts with https:// - # verify_ssl: true verify_ssl: __VERIFY_SERVER_SSL_CERTIFICATES__ # Whether or not the homeserver supports asmux-specific endpoints, # such as /_matrix/client/unstable/net.maunium.asmux/dms for atomically @@ -20,21 +17,26 @@ homeserver: # Changing these values requires regeneration of the registration. appservice: # The address that the homeserver can use to connect to this appservice. - # address: http://localhost:29319 address: http://localhost:__PORT__ + # When using https:// the TLS certificate and key files for the address. + tls_cert: false + tls_key: false # The hostname and port where this appservice should listen. - # hostname: localhost hostname: 0.0.0.0 - # port: 29319 port: __PORT__ # The maximum body size of appservice API requests (from the homeserver) in mebibytes # Usually 1 is enough, but on high-traffic bridges you might need to increase this to avoid 413s max_body_size: 1 # The full URI to the database. Only Postgres is currently supported. - # database: postgres://username:password@hostname/db - database: postgres://__MAUTRIX_FACEBOOK_USER__:__MAUTRIX_FACEBOOK_DB_PWD__@localhost:5432/__MAUTRIX_FACEBOOK_DB_NAME__ + database: postgres://__MAUTRIX_BRIDGE_USER__:__MAUTRIX_BRIDGE_DB_PWD__@localhost:5432/__MAUTRIX_BRIDGE_DB_NAME__ + # Additional arguments for asyncpg.create_pool() + # https://magicstack.github.io/asyncpg/current/api/index.html#asyncpg.pool.create_pool + database_opts: + min_size: 5 + max_size: 10 + # Public part of web server for out-of-Matrix interaction with the bridge. public: @@ -51,17 +53,19 @@ appservice: shared_secret: generate # The unique ID of this appservice. - id: __FACEBOOKBOT__ + id: __BOTNAME__ # Username of the appservice bot. - bot_username: __FACEBOOKBOT__ + bot_username: __BOTNAME__ # Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty # to leave display name/avatar as-is. bot_displayname: FB bridge bot bot_avatar: mxc://maunium.net/ygtkteZsXnGJLJHRchUwYWak # Community ID for bridged users (changes registration file) and rooms. - # Must be created manually. Example: "+facebook:example.com" - community_id: null + # Must be created manually. + # + # Example: "+fb:example.com". Set to false to disable. + community_id: +fb:__SERVER_NAME__ # Whether or not to receive ephemeral events via appservice transactions. # Requires MSC2409 support (i.e. Synapse 1.22+). @@ -244,11 +248,11 @@ logging: formatter: colored loggers: mau: - level: DEBUG + level: __LOG_LEVEL__ paho: level: INFO aiohttp: level: INFO root: - level: DEBUG + level: __LOG_LEVEL__ handlers: [file, console] diff --git a/manifest.json b/manifest.json index fc71988..259f4c4 100644 --- a/manifest.json +++ b/manifest.json @@ -15,7 +15,7 @@ "url": "https://github.com/YunoHost-Apps/mautrix_facebook_ynh" }, "requirements": { - "yunohost": ">= 4.0" + "yunohost": ">= 4.1" }, "multi_instance": true, "services": [ @@ -38,7 +38,7 @@ "default": "1" }, { - "name": "facebookbot", + "name": "botname", "type": "string", "ask": { "en": "Choose a local synapse user name for the Facebook bot", diff --git a/scripts/backup b/scripts/backup index 2e09359..2dc79e1 100755 --- a/scripts/backup +++ b/scripts/backup @@ -29,8 +29,13 @@ ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) -domain=$(ynh_app_setting_get --app=$app --key=domain) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) +app_service_registration_path=$(ynh_app_setting_get --app=$app --key=app_service_registration_path) +mautrix_config_path="$final_path/config.yaml" +#================================================= +# SET CONSTANTS +#================================================= + +mautrix_bridge_db_name=$app #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -54,7 +59,7 @@ ynh_backup --src_path="$final_path" # BACKUP LOGROTATE #================================================= -ynh_backup --src_path="/etc/logrotate.d/$app" +ynh_backup --src_path="/var/log/$app" #================================================= # BACKUP SYSTEMD @@ -63,22 +68,11 @@ ynh_backup --src_path="/etc/logrotate.d/$app" ynh_backup --src_path="/etc/systemd/system/$app.service" #================================================= -# BACKUP VARIOUS FILES +# BACKUP THE POSTGRESQL DATABASE #================================================= +ynh_print_info --message="Backing up the PostgreSQL database..." -ynh_backup --src_path="/etc/cron.d/$app" - -ynh_backup --src_path="/etc/$app/" - -#================================================= -# BACKUP THE MYSQL DATABASE -#================================================= -ynh_print_info --message="Backing up the MySQL database..." - -### (However, things like MySQL dumps *do* take some time to run, though the -### copy of the generated dump to the archive still happens later) - -ynh_mysql_dump_db --database="$db_name" > db.sql +ynh_psql_dump_db --database="$mautrix_bridge_db_name" > ${YNH_CWD}/dump.sql #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index c106c16..186fc36 100755 --- a/scripts/install +++ b/scripts/install @@ -25,7 +25,7 @@ ynh_abort_if_errors #================================================= synapsenumber=$YNH_APP_ARG_SYNAPSENUMBER -facebookbot=$YNH_APP_ARG_FACEBOOKBOT +botname=$YNH_APP_ARG_BOTNAME encryption=$YNH_APP_ARG_ENCRYPTION botadmin=$YNH_APP_ARG_BOTADMIN botusers=$YNH_APP_ARG_BOTUSERS @@ -53,10 +53,10 @@ synapse_db_user="matrix_$synapse_instance" # SET CONSTANTS #================================================= -facebookbot_synapse_db_user="@$facebookbot:$server_name" -mautrix_facebook_user=$app -mautrix_facebook_db_name=$app -mautrix_facebook_db_user=$app +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) #================================================= @@ -73,7 +73,7 @@ test ! -e "$final_path" || ynh_die --message="This path already contains a folde #================================================= ynh_script_progression --message="Configuring firewall..." --weight=1 -# Find a free port for communication between your local synapse instance (home server) and its app service mautrix_facebook. +# Find a free port for communication between your local synapse instance (home server) and its app service mautrix_bridge. port=$(ynh_find_port --port=8449) #================================================= @@ -84,11 +84,11 @@ 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=port --value=$port -ynh_app_setting_set --app=$app --key=facebookbot --value=$facebookbot +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=mautrix_facebook_db_name --value=$mautrix_facebook_db_name +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=botusers --value=$botusers ynh_app_setting_set --app=$app --key=mautrix_version --value=$upstream_version @@ -115,17 +115,17 @@ ynh_install_app_dependencies $pkg_dependencies ynh_script_progression --message="Creating a PostgreSQL database..." --weight=3 ynh_print_OFF -mautrix_facebook_db_pwd=$(ynh_string_random --length=30) -ynh_app_setting_set --app=$app --key=mautrix_facebook_db_pwd --value=$mautrix_facebook_db_pwd +mautrix_bridge_db_pwd=$(ynh_string_random --length=30) +ynh_app_setting_set --app=$app --key=mautrix_bridge_db_pwd --value=$mautrix_bridge_db_pwd ynh_print_ON # Create postgresql database ynh_psql_test_if_first_run ynh_print_OFF -ynh_psql_create_user $mautrix_facebook_db_user $mautrix_facebook_db_pwd +ynh_psql_create_user $mautrix_bridge_db_user $mautrix_bridge_db_pwd ynh_print_ON ynh_psql_execute_as_root \ ---sql="CREATE DATABASE ""$mautrix_facebook_db_name"" ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER ""$mautrix_facebook_db_user"";" +--sql="CREATE DATABASE ""$mautrix_bridge_db_name"" ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER ""$mautrix_bridge_db_user"";" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -154,63 +154,46 @@ ynh_setup_source --dest_dir="$final_path/src" ynh_script_progression --message="Configuring system user..." --weight=1 # Create a system user -ynh_system_user_create --username=$mautrix_facebook_user +ynh_system_user_create --username=$mautrix_bridge_user #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression --message="Configuring a systemd service..." --weight=20 -# Create systemd config for mautrix-facebook +# Create systemd config for Mautrix-Bridge #cp ../conf/default_mautrix-facebook /etc/default/$app ynh_add_systemd_config --service=$app #================================================= #================================================= -# SET MAUTRIX-FACEBOOK CONFIG +# SET MAUTRIX-BRIDGE CONFIG #================================================= -ynh_script_progression --message="Configuring Mautrix-FB..." --weight=2 +ynh_script_progression --message="Configuring Mautrix-Bridge..." --weight=2 # WARNING : theses command are used in INSTALL, UPGRADE, CONFIG, CHANGE-URL (4 times) # For any update do it in all files mautrix_config_path="$final_path/config.yaml" -#Copy example-config.yaml to config.yaml -cp ../conf/config.yaml "$mautrix_config_path" +verify_server_ssl_certificates="true" +matrix_server_supports_asmux="false" +log_filename="/var/log/$app/$app.log" +# https://docs.python.org/3.6/library/logging.html#logging-levels +log_level="INFO" -ynh_replace_string --match_string=__DOMAIN__ --replace_string="https://$domain" --target_file="$mautrix_config_path" -ynh_replace_string --match_string=__SERVER_NAME__ --replace_string=$server_name --target_file="$mautrix_config_path" -ynh_replace_string --match_string=__VERIFY_SERVER_SSL_CERTIFICATES__ --replace_string=true --target_file="$mautrix_config_path" -ynh_replace_string --match_string=__MATRIX_SERVER_SUPPORTS_ASMUX__ --replace_string=false --target_file="$mautrix_config_path" -ynh_replace_string --match_string=__PORT__ --replace_string=$port --target_file="$mautrix_config_path" -ynh_replace_string --match_string=__MAUTRIX_FACEBOOK_USER__ --replace_string=$mautrix_facebook_user --target_file="$mautrix_config_path" -ynh_replace_string --match_string=__MAUTRIX_FACEBOOK_DB_PWD__ --replace_string=$mautrix_facebook_db_pwd --target_file="$mautrix_config_path" -ynh_replace_string --match_string=__MAUTRIX_FACEBOOK_DB_NAME__ --replace_string=$mautrix_facebook_db_name --target_file="$mautrix_config_path" -ynh_replace_string --match_string=__FACEBOOKBOT__ --replace_string=$facebookbot --target_file="$mautrix_config_path" -ynh_replace_string --match_string=__ENCRYPTION__ --replace_string=$encryption --target_file="$mautrix_config_path" -if [ "$botusers" = "local" ] -then -ynh_replace_string --match_string=__BOTUSERS__ --replace_string=$server_name --target_file="$mautrix_config_path" -else -ynh_replace_string --match_string=__BOTUSERS__ --replace_string=$botusers --target_file="$mautrix_config_path" -fi -ynh_replace_string --match_string=__BOTADMIN__ --replace_string=$botadmin --target_file="$mautrix_config_path" -ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file="$mautrix_config_path" -ynh_replace_string --match_string=__LOG_FILENAME__ --replace_string="/var/log/$app/$app.log" --target_file="$mautrix_config_path" - # Options: debug, info, warn, error, fatal -ynh_replace_string --match_string=__LOG_LEVEL__ --replace_string="error" --target_file="$mautrix_config_path" +ynh_add_config --template="../conf/config.yaml" --destination="$mautrix_config_path" #================================================= -# INSTALL MAUTRIX-FACEBOOK PYTHON MODULE +# INSTALL MAUTRIX-BRIDGE PYTHON MODULE #================================================= mkdir -p /var/log/$app -# Configure Mautrix-Facebook +# Configure Mautrix-Bridge python3 -m venv $final_path -$final_path/bin/pip3 install --upgrade setuptools wheel +$final_path/bin/pip3 install --upgrade pip setuptools wheel $final_path/bin/pip3 install --upgrade $final_path/src/mautrix-facebook.tar.gz $final_path/bin/python3 -m mautrix_facebook -g -c $mautrix_config_path -r $app_service_registration_path/$app.yaml @@ -245,7 +228,7 @@ chown -R root: $final_path # WARNING : theses command are used in INSTALL, UPGRADE, RESTORE # For any update do it in all files -chown $mautrix_facebook_user:root -R $final_path +chown $mautrix_bridge_user:root -R $final_path #================================================= # SETUP LOGROTATE @@ -254,14 +237,14 @@ ynh_script_progression --message="Configuring log rotation..." --weight=3 # Use logrotate to manage application logfile(s) ynh_use_logrotate --logfile "/var/log/$app/$app.log" -chown $mautrix_facebook_user:root -R /var/log/$app +chown $mautrix_bridge_user:root -R /var/log/$app #================================================= # ADVERTISE SERVICE IN ADMIN PANEL #================================================= #yunohost service add $app --log "/var/log/$app/log.log" # if using yunohost version 3.2 or more in the 'manifest.json', a description can be added -yunohost service add $app --description "$app daemon for bridging FB and Matrix messages" --log "/var/log/$app/$app.log" +yunohost service add $app --description="$app daemon for bridging FB and Matrix messages" --log="$log_filename" #================================================= # START SYSTEMD SERVICE @@ -275,7 +258,7 @@ sleep 30 # # (Note that, by default, non-admins might not have your homeserver's permission to create communities.) # if [ "$bot_is_synapse_admin" = true ] # then - ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = ""$facebookbot"";" + ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = ""$botname"";" # #yunohost app action run $synapse_instance set_admin_user -a username=$facebookbot # fi ynh_systemd_action --service_name=$app --action="restart" diff --git a/scripts/remove b/scripts/remove index 57f86f1..390c084 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,26 +12,26 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=5 +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME +final_path=$(ynh_app_setting_get --app=$app --key=final_path) server_name=$(ynh_app_setting_get --app=$app --key=server_name) +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) -facebookbot=$(ynh_app_setting_get --app=$app --key=facebookbot) port=$(ynh_app_setting_get --app=$app --key=port) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # SET CONSTANTS #================================================= synapse_db_name="matrix_$synapse_instance" -facebookbot_synapse_db_user="@$facebookbot:$server_name" -mautrix_facebook_user=$app -mautrix_facebook_db_name=$app -mautrix_facebook_db_user=$app +botname_synapse_db_user="@$botname:$server_name" +mautrix_bridge_user=$app +mautrix_bridge_db_name=$app +mautrix_bridge_db_user=$app #================================================= # STANDARD REMOVE @@ -60,9 +60,11 @@ ynh_remove_systemd_config ynh_script_progression --message="Removing the PostgreSQL database..." --weight=4 # Remove a database if it exists, along with the associated user -ynh_psql_remove_db --db_user=$mautrix_facebook_db_name --db_name=$mautrix_facebook_db_user -ynh_psql_execute_as_root --database=$synapse_db_name --sql="DROP OWNED BY ""$facebookbot"";" -ynh_psql_execute_as_root --database=$synapse_db_name --sql="DROP USER ""$facebookbot"";" +ynh_psql_remove_db --db_user=$mautrix_bridge_db_name --db_name=$mautrix_bridge_db_user +ynh_psql_execute_as_root --database=$synapse_db_name --sql="DROP OWNED BY ""$mautrix_bridge_user"";" +ynh_psql_execute_as_root --database=$synapse_db_name --sql="DROP USER ""$mautrix_bridge_user"";" +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=$facebookbot #================================================= @@ -79,7 +81,6 @@ ynh_remove_app_dependencies ynh_script_progression --message="Removing app main directory..." --weight=1 # Remove the app directory securely -#ynh_secure_remove --file="/etc/$app/" ynh_secure_remove --file="$final_path" #================================================= @@ -112,10 +113,10 @@ ynh_secure_remove --file="/var/log/$app" ynh_script_progression --message="Removing the dedicated system user..." --weight=5 # Delete a system user -ynh_system_user_delete --username=$mautrix_facebook_user +ynh_system_user_delete --username=$mautrix_bridge_user #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --time --last +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index 4dfa1bf..e78c8d6 100755 --- a/scripts/restore +++ b/scripts/restore @@ -24,23 +24,37 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) 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 +# language=$(ynh_app_setting_get --app=$app --key=language) + +server_name=$(ynh_app_setting_get --app=$app --key=server_name) +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) + +ynh_print_OFF +mautrix_bridge_db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_pwd) +ynh_print_ON + +#================================================= +# SET CONSTANTS +#================================================= + +synapse_db_name="matrix_$synapse_instance" +mautrix_bridge_user=$app +mautrix_bridge_db_name=$app +mautrix_bridge_db_user=$app + #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_script_progression --message="Validating restoration parameters..." --time --weight=1 +ynh_script_progression --message="Validating restoration parameters..." --weight=1 -ynh_webpath_available --domain=$domain --path_url=$path_url \ - || ynh_die --message="Path not available: ${domain}${path_url}" test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " @@ -49,17 +63,17 @@ test ! -d $final_path \ #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." --time --weight=1 +ynh_script_progression --message="Restoring the app main directory..." --weight=1 ynh_restore_file --origin_path="$final_path" #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1 +ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 # Create the dedicated user (if not existing) -ynh_system_user_create --username=$app +ynh_system_user_create --username=$mautrix_bridge_user #================================================= # RESTORE USER RIGHTS @@ -67,64 +81,91 @@ ynh_system_user_create --username=$app # Restore permissions on app files chown -R root: $final_path +chown $mautrix_bridge_user:root -R $final_path #================================================= # SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." --time --weight=1 +ynh_script_progression --message="Reinstalling dependencies..." --weight=1 # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies +#================================================= +# RESTORE THE POSTGRESQL DATABASE +#================================================= +ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=8 + +ynh_psql_test_if_first_run +ynh_print_OFF +ynh_psql_create_user $mautrix_bridge_db_user $mautrix_bridge_db_pwd +ynh_print_ON +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_execute_file_as_root --file="${YNH_CWD}/dump.sql" --database="$mautrix_bridge_db_name" #================================================= -# RESTORE THE MYSQL DATABASE +# RESTORE MAUTRIX-BRIDGE PYTHON MODULE #================================================= -ynh_script_progression --message="Restoring the MySQL database..." --time --weight=1 -db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) -ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd -ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +ynh_restore_file --origin_path="/var/log/$app" + +python3 -m venv $final_path + + +#================================================= +# REGISTER SYNAPSE APP-SERVICE +#================================================= +$final_path/bin/python3 -m mautrix_facebook -g -c $mautrix_config_path -r $app_service_registration_path/$app.yaml + +/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh \ + || ynh_die "Synapse can't restart with the appservice configuration" +# Handled by synapse: synapse_ynh adds all registration files added in $app_service_registration_path to the app_service_config_files list #================================================= # RESTORE SYSTEMD #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --time --weight=1 +ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service --quiet +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= + +ynh_use_logrotate --logfile "/var/log/$app/$app.log" +chown $mautrix_bridge_user:root -R /var/log/$app + #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --time --weight=1 +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add $app --description="A short description of the app" --log="/var/log/$app/$app.log" +yunohost service add $app --description="$app daemon for bridging FB and Matrix messages" --log="$log_filename" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 +ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +# Start a systemd service +ynh_systemd_action --service_name=$app --action="start" +# Wait until the synapse user is created +sleep 30 +# # (Note that, by default, non-admins might not have your homeserver's permission to create communities.) +# if [ "$bot_is_synapse_admin" = true ] +# then + ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = ""$botname"";" +# #yunohost app action run $synapse_instance set_admin_user -a username=$facebookbot +# fi +ynh_systemd_action --service_name=$app --action="restart" -#================================================= -# RESTORE VARIOUS FILES -#================================================= -ynh_restore_file --origin_path="/etc/cron.d/$app" - -ynh_restore_file --origin_path="/etc/$app/" - -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= - -ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --time --last +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index cd2c370..6515c5e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,17 +12,26 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) -admin=$(ynh_app_setting_get --app=$app --key=admin) final_path=$(ynh_app_setting_get --app=$app --key=final_path) -language=$(ynh_app_setting_get --app=$app --key=language) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) +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) +mautrix_config_path="$final_path/config.yaml" +#================================================= +# SET CONSTANTS +#================================================= + +log_filename="/var/log/$app/$app.log" +synapse_db_name="matrix_$synapse_instance" +mautrix_bridge_user=$app +mautrix_bridge_db_name=$app +mautrix_bridge_db_user=$app #================================================= # CHECK VERSION #================================================= @@ -38,7 +47,7 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1 +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # # N.B. : the followings setting migrations snippets are provided as *EXAMPLES* @@ -61,7 +70,7 @@ ynh_script_progression --message="Ensuring downward compatibility..." --time --w #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1 +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 # Backup the current version of the app ynh_backup_before_upgrade @@ -77,9 +86,9 @@ ynh_abort_if_errors #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 +ynh_script_progression --message="Stopping a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="stop" --log_path="$log_filename" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -87,34 +96,26 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Upgrading source files..." --time --weight=1 + ynh_script_progression --message="Upgrading source files..." --weight=1 # 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 #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 +ynh_script_progression --message="Upgrading dependencies..." --weight=1 ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1 +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # Create a dedicated user (if not existing) -ynh_system_user_create --username=$app - -#================================================= -# PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading PHP-FPM configuration..." --time --weight=1 - -# Create a dedicated PHP-FPM config -ynh_add_fpm_config +ynh_system_user_create --username=$mautrix_bridge_user #================================================= # SPECIFIC UPGRADE @@ -125,23 +126,49 @@ ynh_add_fpm_config #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1 +ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 # Create a dedicated systemd config ynh_add_systemd_config #================================================= -# MODIFY A CONFIG FILE +# SET MAUTRIX-BRIDGE CONFIG #================================================= +ynh_script_progression --message="Configuring Mautrix-Bridge..." --weight=2 + +mautrix_config_path="$final_path/config.yaml" ### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. ### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. -ynh_backup_if_checksum_is_different --file="$final_path/CONFIG_FILE" +ynh_backup_if_checksum_is_different --file="$app_service_registration_path/$app.yaml" +ynh_backup_if_checksum_is_different --file="$mautrix_config_path" -ynh_replace_string --match_string="match_string" --replace_string="replace_string" --target_file="$final_path/CONFIG_FILE" +verify_server_ssl_certificates="true" +matrix_server_supports_asmux="false" +# https://docs.python.org/3.6/library/logging.html#logging-levels +log_level="INFO" + +ynh_add_config --template="../conf/config.yaml" --destination="$mautrix_config_path" # Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$final_path/CONFIG_FILE" +ynh_store_file_checksum --file="$app_service_registration_path/$app.yaml" +ynh_store_file_checksum --file="$mautrix_config_path" + +#================================================= +# UPGRADE MAUTRIX-BRIDGE PYTHON MODULE +#================================================= +ynh_script_progression --message="Upgrading Mautrix-Bridge..." --weight=2 + +mkdir -p /var/log/$app +# Configure Mautrix-Bridge +python3 -m venv $final_path +$final_path/bin/pip3 install --upgrade pip setuptools wheel +$final_path/bin/pip3 install --upgrade $final_path/src/mautrix-facebook.tar.gz +$final_path/bin/python3 -m mautrix_facebook -g -c $mautrix_config_path -r $app_service_registration_path/$app.yaml + +/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh \ + || ynh_die "Synapse can't restart with the appservice configuration" +# Handled by synapse: synapse_ynh adds all registration files added in $app_service_registration_path to the app_service_config_files list #================================================= # GENERIC FINALIZATION @@ -151,31 +178,42 @@ ynh_store_file_checksum --file="$final_path/CONFIG_FILE" # Set permissions on app files chown -R root: $final_path - +chown $mautrix_bridge_user:root -R $final_path #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1 +ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 -# Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --non-append +# Use logrotate to manage application logfile(s) +ynh_use_logrotate --logfile "$log_filename" +chown $mautrix_bridge_user:root -R /var/log/$app #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --time --weight=1 +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add $app --description="A short description of the app" --log="/var/log/$app/$app.log" +yunohost service add $app --description="$app daemon for bridging FB and Matrix messages" --log="$log_filename" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 +ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +# Start a systemd service +ynh_systemd_action --service_name=$app --action="start" +# Wait until the synapse user is created +sleep 30 +# # (Note that, by default, non-admins might not have your homeserver's permission to create communities.) +# if [ "$bot_is_synapse_admin" = true ] +# then + ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = ""$botname"";" +# #yunohost app action run $synapse_instance set_admin_user -a username=$facebookbot +# fi +ynh_systemd_action --service_name=$app --action="restart" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --time --last +ynh_script_progression --message="Upgrade of $app completed" --last From 85232bd3721cecde51e591f55afcb7c958a925ed Mon Sep 17 00:00:00 2001 From: nathanael-h Date: Wed, 1 Dec 2021 08:18:56 +0100 Subject: [PATCH 03/12] Change key botname in check_process to match manifest --- check_process | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_process b/check_process index 37b2a1b..38b168a 100644 --- a/check_process +++ b/check_process @@ -8,7 +8,7 @@ ; Manifest port="8449" (PORT) synapsenumber="1" - whatsappbot="whatsappbot" + botname="facebookbot" bot_synapse_adm=0 encryption=0 botadmin="@johndoe:synapsedomain.tld" (USER) From f91006c37828c042ecd32da93c0c79295cbe76be Mon Sep 17 00:00:00 2001 From: nathanael-h Date: Wed, 1 Dec 2021 08:19:29 +0100 Subject: [PATCH 04/12] Change : add settings in backup, remove, upgrade --- scripts/backup | 16 ++++++++++++++++ scripts/remove | 15 ++++++++++++++- scripts/upgrade | 13 ++++++++++++- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/scripts/backup b/scripts/backup index 2dc79e1..3b87009 100755 --- a/scripts/backup +++ b/scripts/backup @@ -28,9 +28,25 @@ ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME +domain=$(ynh_app_setting_get --app=$app --key=domain) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +# language=$(ynh_app_setting_get --app=$app --key=language) + +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) +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) +# bot_is_synapse_admin=$(ynh_app_setting_get --app=$app --key=bot_is_synapse_admin) +encryption=$(ynh_app_setting_get --app=$app --key=encryption) +botadmin=$(ynh_app_setting_get --app=$app --key=botadmin) +botusers=$(ynh_app_setting_get --app=$app --key=botusers) mautrix_config_path="$final_path/config.yaml" +mautrix_version=$(ynh_app_setting_get --app=$app --key=mautrix_version) + +ynh_print_OFF +mautrix_bridge_db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_pwd) +ynh_print_ON #================================================= # SET CONSTANTS #================================================= diff --git a/scripts/remove b/scripts/remove index 390c084..8fc4ded 100755 --- a/scripts/remove +++ b/scripts/remove @@ -16,12 +16,25 @@ ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME +domain=$(ynh_app_setting_get --app=$app --key=domain) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +# language=$(ynh_app_setting_get --app=$app --key=language) + 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) 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) -port=$(ynh_app_setting_get --app=$app --key=port) +# bot_is_synapse_admin=$(ynh_app_setting_get --app=$app --key=bot_is_synapse_admin) +encryption=$(ynh_app_setting_get --app=$app --key=encryption) +botadmin=$(ynh_app_setting_get --app=$app --key=botadmin) +botusers=$(ynh_app_setting_get --app=$app --key=botusers) +mautrix_config_path="$final_path/config.yaml" +mautrix_version=$(ynh_app_setting_get --app=$app --key=mautrix_version) + +ynh_print_OFF +mautrix_bridge_db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_pwd) +ynh_print_ON #================================================= # SET CONSTANTS diff --git a/scripts/upgrade b/scripts/upgrade index 6515c5e..e0a7e4d 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -18,12 +18,23 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +# language=$(ynh_app_setting_get --app=$app --key=language) +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) 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) +# bot_is_synapse_admin=$(ynh_app_setting_get --app=$app --key=bot_is_synapse_admin) +encryption=$(ynh_app_setting_get --app=$app --key=encryption) +botadmin=$(ynh_app_setting_get --app=$app --key=botadmin) +botusers=$(ynh_app_setting_get --app=$app --key=botusers) mautrix_config_path="$final_path/config.yaml" -#================================================= +mautrix_version=$(ynh_app_setting_get --app=$app --key=mautrix_version) + +ynh_print_OFF +mautrix_bridge_db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_pwd) +ynh_print_ON#================================================= # SET CONSTANTS #================================================= From e23e85f3a7a576965adf0d094512238c1f004152 Mon Sep 17 00:00:00 2001 From: nathanael-h Date: Wed, 1 Dec 2021 08:54:00 +0100 Subject: [PATCH 05/12] Change: remove ynh_print_{ON,OFF} as variables end with pwd and will be redacted by yunohost --- scripts/backup | 2 -- scripts/install | 4 ---- scripts/remove | 2 -- scripts/restore | 4 ---- scripts/upgrade | 4 ++-- 5 files changed, 2 insertions(+), 14 deletions(-) diff --git a/scripts/backup b/scripts/backup index 3b87009..b19e068 100755 --- a/scripts/backup +++ b/scripts/backup @@ -44,9 +44,7 @@ botusers=$(ynh_app_setting_get --app=$app --key=botusers) mautrix_config_path="$final_path/config.yaml" mautrix_version=$(ynh_app_setting_get --app=$app --key=mautrix_version) -ynh_print_OFF mautrix_bridge_db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_pwd) -ynh_print_ON #================================================= # SET CONSTANTS #================================================= diff --git a/scripts/install b/scripts/install index 186fc36..c5e7ac7 100755 --- a/scripts/install +++ b/scripts/install @@ -114,16 +114,12 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= ynh_script_progression --message="Creating a PostgreSQL database..." --weight=3 -ynh_print_OFF mautrix_bridge_db_pwd=$(ynh_string_random --length=30) ynh_app_setting_set --app=$app --key=mautrix_bridge_db_pwd --value=$mautrix_bridge_db_pwd -ynh_print_ON # Create postgresql database ynh_psql_test_if_first_run -ynh_print_OFF ynh_psql_create_user $mautrix_bridge_db_user $mautrix_bridge_db_pwd -ynh_print_ON 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"";" diff --git a/scripts/remove b/scripts/remove index 8fc4ded..f5ff8c0 100755 --- a/scripts/remove +++ b/scripts/remove @@ -32,9 +32,7 @@ botusers=$(ynh_app_setting_get --app=$app --key=botusers) mautrix_config_path="$final_path/config.yaml" mautrix_version=$(ynh_app_setting_get --app=$app --key=mautrix_version) -ynh_print_OFF mautrix_bridge_db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_pwd) -ynh_print_ON #================================================= # SET CONSTANTS diff --git a/scripts/restore b/scripts/restore index e78c8d6..248564e 100755 --- a/scripts/restore +++ b/scripts/restore @@ -36,9 +36,7 @@ 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) -ynh_print_OFF mautrix_bridge_db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_pwd) -ynh_print_ON #================================================= # SET CONSTANTS @@ -98,9 +96,7 @@ ynh_install_app_dependencies $pkg_dependencies ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=8 ynh_psql_test_if_first_run -ynh_print_OFF ynh_psql_create_user $mautrix_bridge_db_user $mautrix_bridge_db_pwd -ynh_print_ON 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_execute_file_as_root --file="${YNH_CWD}/dump.sql" --database="$mautrix_bridge_db_name" diff --git a/scripts/upgrade b/scripts/upgrade index e0a7e4d..2c5d6db 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -32,9 +32,9 @@ botusers=$(ynh_app_setting_get --app=$app --key=botusers) mautrix_config_path="$final_path/config.yaml" mautrix_version=$(ynh_app_setting_get --app=$app --key=mautrix_version) -ynh_print_OFF mautrix_bridge_db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_pwd) -ynh_print_ON#================================================= + +#================================================= # SET CONSTANTS #================================================= From fd479357a5d4c4501c4bc0fccc10bb86cb69e6a5 Mon Sep 17 00:00:00 2001 From: nathanael-h Date: Wed, 1 Dec 2021 14:10:11 +0100 Subject: [PATCH 06/12] Change: add constants in all scripts --- scripts/backup | 6 ++++++ scripts/install | 3 +++ scripts/remove | 5 ++++- scripts/restore | 3 +++ scripts/upgrade | 5 ++++- 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/scripts/backup b/scripts/backup index b19e068..3ac5f94 100755 --- a/scripts/backup +++ b/scripts/backup @@ -49,7 +49,13 @@ mautrix_bridge_db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_p # SET CONSTANTS #================================================= +botname_synapse_db_user="@$botname:$server_name" +synapse_db_name="matrix_$synapse_instance" +mautrix_bridge_user=$app mautrix_bridge_db_name=$app +mautrix_bridge_db_user=$app +upstream_version=$(ynh_app_upstream_version) +log_filename="/var/log/$app/$app.log" #================================================= # DECLARE DATA AND CONF FILES TO BACKUP diff --git a/scripts/install b/scripts/install index c5e7ac7..2ffdcf9 100755 --- a/scripts/install +++ b/scripts/install @@ -54,10 +54,13 @@ synapse_db_user="matrix_$synapse_instance" #================================================= botname_synapse_db_user="@$botname:$server_name" +synapse_db_name="matrix_$synapse_instance" mautrix_bridge_user=$app mautrix_bridge_db_name=$app mautrix_bridge_db_user=$app upstream_version=$(ynh_app_upstream_version) +log_filename="/var/log/$app/$app.log" + #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS diff --git a/scripts/remove b/scripts/remove index f5ff8c0..d7d17b9 100755 --- a/scripts/remove +++ b/scripts/remove @@ -38,11 +38,14 @@ mautrix_bridge_db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_p # SET CONSTANTS #================================================= -synapse_db_name="matrix_$synapse_instance" botname_synapse_db_user="@$botname:$server_name" +synapse_db_name="matrix_$synapse_instance" mautrix_bridge_user=$app mautrix_bridge_db_name=$app mautrix_bridge_db_user=$app +upstream_version=$(ynh_app_upstream_version) +log_filename="/var/log/$app/$app.log" + #================================================= # STANDARD REMOVE diff --git a/scripts/restore b/scripts/restore index 248564e..4b87385 100755 --- a/scripts/restore +++ b/scripts/restore @@ -42,10 +42,13 @@ mautrix_bridge_db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_p # SET CONSTANTS #================================================= +botname_synapse_db_user="@$botname:$server_name" synapse_db_name="matrix_$synapse_instance" mautrix_bridge_user=$app mautrix_bridge_db_name=$app mautrix_bridge_db_user=$app +upstream_version=$(ynh_app_upstream_version) +log_filename="/var/log/$app/$app.log" #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 2c5d6db..51b3692 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -38,11 +38,14 @@ mautrix_bridge_db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_p # SET CONSTANTS #================================================= -log_filename="/var/log/$app/$app.log" +botname_synapse_db_user="@$botname:$server_name" synapse_db_name="matrix_$synapse_instance" mautrix_bridge_user=$app mautrix_bridge_db_name=$app mautrix_bridge_db_user=$app +upstream_version=$(ynh_app_upstream_version) +log_filename="/var/log/$app/$app.log" + #================================================= # CHECK VERSION #================================================= From 192942d7effebe18ea54ea384782859736e03d79 Mon Sep 17 00:00:00 2001 From: nathanael-h Date: Wed, 1 Dec 2021 15:54:31 +0100 Subject: [PATCH 07/12] Fix mautrix_config_path var --- scripts/restore | 2 +- scripts/upgrade | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/restore b/scripts/restore index 4b87385..ec4c278 100755 --- a/scripts/restore +++ b/scripts/restore @@ -35,7 +35,7 @@ server_name=$(ynh_app_setting_get --app=$app --key=server_name) 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) - +mautrix_config_path="$final_path/config.yaml" mautrix_bridge_db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_pwd) #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 51b3692..a499993 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -150,7 +150,6 @@ ynh_add_systemd_config #================================================= ynh_script_progression --message="Configuring Mautrix-Bridge..." --weight=2 -mautrix_config_path="$final_path/config.yaml" ### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. ### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. From 64329be4744ac88e3c97965e15ec98ae0e42330e Mon Sep 17 00:00:00 2001 From: nathanael-h Date: Wed, 1 Dec 2021 18:33:59 +0100 Subject: [PATCH 08/12] Add upstream in manifest --- manifest.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/manifest.json b/manifest.json index 259f4c4..4afa942 100644 --- a/manifest.json +++ b/manifest.json @@ -8,6 +8,12 @@ }, "version": "0.3.0~ynh1", "url": "https://github.com/tulir/mautrix-facebook", + "upstream": { + "license": "AGPL-3.0-or-later", + "admindoc": "https://docs.mau.fi/bridges/python/setup/index.html?bridge=facebook", + "userdoc": "https://docs.mau.fi/bridges/python/facebook/index.html", + "code": "https://github.com/mautrix/facebook" + }, "license": "AGPL-3.0-or-later", "maintainer": { "name": "Gredin67", From 40a003d0ed5195b0b8c2b2020600e40d21eccc71 Mon Sep 17 00:00:00 2001 From: nathanael-h Date: Wed, 1 Dec 2021 18:34:30 +0100 Subject: [PATCH 09/12] Replacements in issue_template.md --- issue_template.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/issue_template.md b/issue_template.md index 4a290c4..490eff0 100644 --- a/issue_template.md +++ b/issue_template.md @@ -8,7 +8,7 @@ about: When creating a bug report, please use the following template to provide 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 REPLACEBYYOURAPP itself. Refer to its documentation or repository for help.* + - *Otherwise, the issue may be due to mautrix-facebook 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.* --- @@ -31,7 +31,7 @@ about: When creating a bug report, please use the following template to provide - *If you performed a command from the CLI, the command itself is enough. For example:* ```sh - sudo yunohost app install REPLACEBYYOURAPP + sudo yunohost app install mautrix_facebook ``` - *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:* From 3137afba12ddcf75743a4bcf142e8325524366aa Mon Sep 17 00:00:00 2001 From: nathanael-h Date: Wed, 1 Dec 2021 18:35:01 +0100 Subject: [PATCH 10/12] Fix based on linter advices --- scripts/install | 5 +---- scripts/restore | 1 - scripts/upgrade | 1 - 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/scripts/install b/scripts/install index 2ffdcf9..63c815a 100755 --- a/scripts/install +++ b/scripts/install @@ -74,7 +74,7 @@ test ! -e "$final_path" || ynh_die --message="This path already contains a folde #================================================= # FIND AND OPEN A PORT #================================================= -ynh_script_progression --message="Configuring firewall..." --weight=1 +ynh_script_progression --message="Configuring bridge port..." --weight=1 # Find a free port for communication between your local synapse instance (home server) and its app service mautrix_bridge. port=$(ynh_find_port --port=8449) @@ -222,9 +222,6 @@ ynh_store_file_checksum --file="$mautrix_config_path" ### Then, if write authorization is needed, any access should be given only to directories ### that really need such authorization. -# Set permissions to app files -chown -R root: $final_path - # 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 diff --git a/scripts/restore b/scripts/restore index ec4c278..ca83d90 100755 --- a/scripts/restore +++ b/scripts/restore @@ -81,7 +81,6 @@ ynh_system_user_create --username=$mautrix_bridge_user #================================================= # Restore permissions on app files -chown -R root: $final_path chown $mautrix_bridge_user:root -R $final_path #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index a499993..7fbfa21 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -190,7 +190,6 @@ $final_path/bin/python3 -m mautrix_facebook -g -c $mautrix_config_path -r $app_s #================================================= # Set permissions on app files -chown -R root: $final_path chown $mautrix_bridge_user:root -R $final_path #================================================= # SETUP LOGROTATE From a800efa1602a0d236add11871ef7b31c968349cb Mon Sep 17 00:00:00 2001 From: nathanael-h Date: Thu, 2 Dec 2021 18:30:27 +0100 Subject: [PATCH 11/12] Change: fix error in multi_instance install with the pre-installation of synapse. --- check_process | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_process b/check_process index 38b168a..e41f11a 100644 --- a/check_process +++ b/check_process @@ -4,7 +4,7 @@ ;; Default test serie ; pre-install sudo yunohost tools update apps - sudo yunohost app install https://github.com/YunoHost-Apps/synapse_ynh/ -a "domain=$domain&server_name=$server_name&is_public=$is_public&jitsi_server=$jitsi_server" --force + sudo yunohost app info synapse --quiet > /dev/null || sudo yunohost app install https://github.com/YunoHost-Apps/synapse_ynh/ -a "domain=$domain&server_name=$server_name&is_public=$is_public&jitsi_server=$jitsi_server" --force ; Manifest port="8449" (PORT) synapsenumber="1" From 6225aa80d33dfd6997756498da34abcd88b6799f Mon Sep 17 00:00:00 2001 From: nathanael-h Date: Fri, 3 Dec 2021 18:51:34 +0100 Subject: [PATCH 12/12] Fix systemd service failing to start --- conf/systemd.service | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/conf/systemd.service b/conf/systemd.service index cd52f4f..aa1e851 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,7 +7,6 @@ Type=simple User=__APP__ Group=__APP__ WorkingDirectory=__FINALPATH__/ -ExecStart=__FINALPATH__/bin/python3 -m mautrix_facebook >> /var/log/__APP__/__APP__.log 2>&1 - +ExecStart=__FINALPATH__/bin/python3 -m mautrix_facebook [Install] WantedBy=multi-user.target