1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mautrix_signal_ynh.git synced 2024-09-03 19:46:07 +02:00
mautrix_signal_ynh/scripts/upgrade

134 lines
4.8 KiB
Text
Raw Normal View History

2021-01-04 12:14:25 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
mautrix_version=$(ynh_app_upstream_version)
2022-09-04 22:28:27 +02:00
synapse_db_name="matrix_$synapse_instance"
2024-02-26 14:56:12 +01:00
server_name=$(ynh_app_setting_get --app $synapse_instance --key server_name)
domain=$(ynh_app_setting_get --app $synapse_instance --key domain)
2021-01-04 12:14:25 +01:00
#=================================================
# CHECK VERSION
#=================================================
ynh_script_progression --message="Checking version..." --weight=1
upgrade_type=$(ynh_check_app_version_changed)
2021-01-04 12:14:25 +01:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
2021-01-04 12:14:25 +01:00
2022-09-04 22:28:27 +02:00
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
2021-01-04 12:14:25 +01:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
2021-01-04 12:14:25 +01:00
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
2021-01-04 12:14:25 +01:00
# TODO: check if there are some file that need some chown chmod
# TODO: look at whatsapp to compare
# Check if an old version of the bridge is in use
# In this case it needs to be upgraded from python to go
# Note that 0.5.0 was never released, but it makes for a good cut-off
if ynh_compare_current_package_version --comparison lt --version 0.5.0~ynh1
then
source upgrade-pre-0.5.sh
fi
2021-01-04 12:14:25 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
2021-01-04 12:14:25 +01:00
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
ynh_script_progression --message="Upgrading source files..." --weight=2
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
fi
2022-09-04 22:28:27 +02:00
chmod 750 "$install_dir"
chmod -R 750 "$install_dir"
chown -R $app:$app "$install_dir"
#=================================================
2022-09-04 22:28:27 +02:00
# UPDATE A CONFIG FILE
#=================================================
2022-09-04 22:28:27 +02:00
ynh_script_progression --message="Updating a configuration file..." --weight=2
echo "botusers=$botusers"
2024-02-26 17:41:47 +01:00
if [[ -z "$botusers" ]] || [ "$botusers" == "admin" ]; then
if_botusers="# "
else
if_botusers=""
fi
2024-02-26 13:49:53 +01:00
ynh_add_config --template="config.yaml" --destination="$install_dir/config.yaml"
2021-01-04 12:14:25 +01:00
2024-02-26 13:49:53 +01:00
chmod 400 "$install_dir/config.yaml"
chown "$app:$app" "$install_dir/config.yaml"
#=================================================
# REGISTER SYNAPSE APP-SERVICE
#=================================================
2022-09-04 23:58:20 +02:00
ynh_script_progression --message="Registering Synapse app-service" --weight=1
$install_dir/mautrix-signal -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 --message="Synapse can't restart with the appservice configuration"
2021-01-04 12:14:25 +01:00
chown -R $app:$app "$install_dir"
2022-09-04 23:58:20 +02:00
ynh_store_file_checksum --file="/etc/matrix-$synapse_instance/app-service/$app.yaml"
2024-02-26 13:49:53 +01:00
ynh_store_file_checksum --file="$install_dir/config.yaml"
2022-09-04 22:28:27 +02:00
#=================================================
# SETUP SYSTEMD
2022-09-04 22:28:27 +02:00
#=================================================
2024-02-26 13:49:53 +01:00
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
2022-09-04 22:28:27 +02:00
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
2021-01-04 12:14:25 +01:00
2022-09-04 22:28:27 +02:00
# Use logrotate to manage app-specific logfile(s)
2024-04-11 22:44:19 +02:00
ynh_use_logrotate --logfile "/var/log/$app/$app.log" --nonappend --specific_user $app/$app
chmod -R 600 "/var/log/$app"
chmod 700 "/var/log/$app"
chown -R $app:$app /var/log/$app
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add "$app" --description="$app daemon for bridging Signal and Matrix messages" --log="/var/log/$app/$app.log"
2021-01-04 12:14:25 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
2021-01-04 12:14:25 +01:00
2022-09-04 22:28:27 +02:00
# Start a systemd service
2024-02-26 13:49:53 +01:00
ynh_systemd_action --service_name="$app" --action="start"
2021-01-04 12:14:25 +01:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last