2021-01-04 12:14:25 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
2024-04-27 16:34:56 +02:00
# Satisfy shellcheck, those variables are known when starting the script:
# shellcheck disable=SC2154
echo From manifest: "$synapsenumber $bot_synapse_adm", \
From yunohost: "$app $install_dir" > /dev/null
2021-01-04 12:14:25 +01:00
#=================================================
2024-02-26 13:49:53 +01:00
# INITIALIZE AND STORE SETTINGS
2021-01-04 12:14:25 +01:00
#=================================================
2024-02-26 17:41:47 +01:00
if [[ -z "$botusers" ]] || [ "$botusers" == "admin" ]; then
2024-02-26 13:49:53 +01:00
if_botusers="# "
else
if_botusers=""
2022-01-25 09:49:10 +01:00
fi
2022-09-04 22:28:27 +02:00
2021-02-10 21:07:18 +01:00
# ToDo check (in manifest?) if the selected synapse instance is not already connected to a mautrix_bridge bridge
2024-04-27 16:34:56 +02:00
if [ "$synapsenumber" -eq "1" ]
2021-01-22 22:44:36 +01:00
then
2022-09-04 22:28:27 +02:00
synapse_instance="synapse"
2021-01-22 22:44:36 +01:00
else
2022-09-04 22:28:27 +02:00
synapse_instance="synapse__$synapsenumber"
2021-01-22 22:44:36 +01:00
fi
2024-04-21 19:57:21 +02:00
# Convert user choice boolean from the manifest into a config value
if [ "$enable_relaybot" -eq "1" ]
then
enable_relaybot="true"
else
enable_relaybot="false"
fi
2024-04-27 15:57:26 +02:00
if [ "$encryption" -eq "1" ]
then
encryption="true"
else
encryption="false"
fi
2024-04-27 16:34:56 +02:00
server_name=$(ynh_app_setting_get --app "$synapse_instance" --key server_name)
2024-02-26 14:05:59 +01:00
domain=$(ynh_app_setting_get --app $synapse_instance --key domain)
2022-01-25 09:49:10 +01:00
mautrix_version=$(ynh_app_upstream_version)
2022-09-04 22:28:27 +02:00
bot_synapse_db_user="@$botname:$server_name"
synapse_db_name="matrix_$synapse_instance"
2021-01-04 12:14:25 +01:00
2024-04-27 16:34:56 +02:00
ynh_app_setting_set --app="$app" --key=bot_synapse_adm --value="$bot_synapse_adm"
ynh_app_setting_set --app="$app" --key=encryption --value="$encryption"
2024-04-21 19:57:21 +02:00
ynh_app_setting_set --app="$app" --key=enable_relaybot --value="$enable_relaybot"
2024-04-27 16:34:56 +02:00
ynh_app_setting_set --app="$app" --key=synapse_instance --value="$synapse_instance"
ynh_app_setting_set --app="$app" --key=server_name --value="$server_name"
ynh_app_setting_set --app="$app" --key=mautrix_version --value="$mautrix_version"
2021-01-04 12:14:25 +01:00
#=================================================
2022-01-25 09:49:10 +01:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2021-01-04 12:14:25 +01:00
#=================================================
2024-04-09 22:42:50 +02:00
ynh_script_progression --message="Setting up source files..." --weight=5
2021-01-04 12:14:25 +01:00
2022-01-25 09:49:10 +01:00
# Download, check integrity, uncompress and patch the source from app.src
2024-04-09 22:42:50 +02:00
ynh_setup_source --dest_dir="$install_dir"
2024-02-26 13:49:53 +01:00
2024-04-09 22:42:50 +02:00
chmod 750 "$install_dir"
chmod -R 750 "$install_dir"
2024-04-27 16:34:56 +02:00
chown -R "$app":"$app" "$install_dir"
2021-01-04 12:14:25 +01:00
2022-01-25 09:49:10 +01:00
#=================================================
# ADD A CONFIGURATION
#=================================================
2022-09-04 22:28:27 +02:00
ynh_script_progression --message="Adding a configuration file..." --weight=2
2021-01-22 22:44:36 +01:00
2024-02-26 13:49:53 +01:00
ynh_add_config --template="config.yaml" --destination="$install_dir/config.yaml"
2021-02-06 00:40:51 +01:00
2024-02-26 13:49:53 +01:00
chmod 400 "$install_dir/config.yaml"
chown "$app:$app" "$install_dir/config.yaml"
2021-08-19 17:41:14 +02:00
2022-01-25 09:49:10 +01:00
#=================================================
# REGISTER SYNAPSE APP-SERVICE
#=================================================
2022-09-04 22:28:27 +02:00
ynh_script_progression --message="Registering Synapse app-service" --weight=1
2022-01-25 09:49:10 +01:00
2024-04-27 16:34:56 +02:00
"$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"
2022-09-04 22:28:27 +02:00
2024-04-27 16:34:56 +02:00
chown -R "$app":"$app" "$install_dir"
2022-09-04 22:28:27 +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"
2021-01-04 12:14:25 +01:00
#=================================================
2024-02-26 13:49:53 +01:00
# SYSTEM CONFIGURATION
2021-01-04 12:14:25 +01:00
#=================================================
2024-02-26 13:49:53 +01:00
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
2021-01-04 12:14:25 +01:00
2022-09-04 22:28:27 +02:00
# Create a dedicated systemd config
ynh_add_systemd_config
2024-04-27 16:34:56 +02:00
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
# Use logrotate to manage application logfile(s)
2024-04-27 16:34:56 +02:00
ynh_use_logrotate --logfile "/var/log/$app/$app.log" --nonappend --specific_user "$app/$app"
2021-01-04 12:14:25 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2024-02-26 13:49:53 +01:00
ynh_script_progression --message="Starting $app's systemd service..." --weight=2
2021-01-04 12:14:25 +01:00
# Start a systemd service
2024-02-26 13:49:53 +01:00
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
2021-01-04 12:14:25 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2021-02-05 23:47:33 +01:00
ynh_script_progression --message="Installation of $app completed" --last