#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers server_name=$(ynh_app_setting_get --app=$app --key=server_name) synapse_db_name="matrix_$synapse_instance" bot_synapse_db_user="@$botname:$server_name" appserviceid=$app async_media=$(ynh_app_setting_get --app=$app --key=async_media) listrelay=$(ynh_app_setting_get --app=$app --key=listrelay) listuser=$(ynh_app_setting_get --app=$app --key=listuser) listadmin=$(ynh_app_setting_get --app=$app --key=listadmin) upgrade_type=$(ynh_check_app_version_changed) #================================================= # STOP SYSTEMD SERVICE #================================================= 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" #================================================= # "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= if [ "$upgrade_type" == "UPGRADE_APP" ] then ynh_script_progression --message="Upgrading source files..." --weight=1 # Download, check integrity, uncompress and patch the source from manifest.toml ynh_setup_source --dest_dir="$install_dir" fi chmod 750 "$install_dir/$APP_BIN" chown -R $app:www-data "$install_dir" #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 ynh_add_systemd_config yunohost service add $app --description="Matrix Discord pupetting bridge for YunoHost" --log="/var/log/$app/$app.log" ynh_use_logrotate --non-append #================================================= # RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...) #================================================= # UPDATE A CONFIG FILE #================================================= ynh_script_progression --message="Updating a configuration file..." --weight=1 # reset permissions to be able to apply_permissions with app_setting values after upgrade listrelay_=$listrelay listuser_=$listuser listadmin_=$listadmin listrelay="*" listuser="@user:domain.tld" listadmin="@admin:domain.tld" ynh_add_config --template="config.yaml" --destination="$install_dir/config.yaml" chmod 400 "$install_dir/config.yaml" chown $app:$app "$install_dir/config.yaml" listrelay=$listrelay_ listuser=$listuser_ listadmin=$listadmin_ # apply_permissions to have correct syntax in config file set__listuser set__listrelay set__listadmin #================================================= # REGISTER SYNAPSE APP-SERVICE #================================================= ynh_script_progression --message="Registering Synapse app-service" --weight=1 $install_dir/$APP_BIN -g -c $install_dir/config.yaml -r /etc/matrix-$synapse_instance/app-service/$app.yaml /opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die "Synapse can't restart with the appservice configuration" # Set permissions on app files chown -R $app:$app "$install_dir" ynh_store_file_checksum --file="/etc/matrix-$synapse_instance/app-service/$app.yaml" ynh_store_file_checksum --file="$install_dir/config.yaml" #================================================= # START SYSTEMD SERVICE #================================================= 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" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Upgrade of $app completed" --last