2021-03-24 22:49:07 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
2023-11-13 21:34:20 +01:00
|
|
|
# Retrieve some values from selected Synapse instance and store them
|
|
|
|
appserviceid=$app
|
2021-03-24 22:49:07 +01:00
|
|
|
server_name=$(ynh_app_setting_get --app $synapse_instance --key server_name)
|
|
|
|
domain=$(ynh_app_setting_get --app $synapse_instance --key domain)
|
2022-09-04 23:58:47 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=server_name --value=$server_name
|
|
|
|
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
2023-11-13 21:34:20 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=appserviceid --value=$appserviceid
|
2021-03-24 22:49:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=3
|
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
2023-11-13 21:34:20 +01:00
|
|
|
ynh_setup_source --dest_dir="$install_dir/src"
|
2021-03-24 22:49:07 +01:00
|
|
|
|
2023-11-13 21:34:20 +01:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R 750 "$install_dir"
|
|
|
|
chown -R $app:$app "$install_dir"
|
2022-09-04 23:58:47 +02:00
|
|
|
|
2021-03-24 22:49:07 +01:00
|
|
|
#=================================================
|
2022-07-16 01:38:42 +02:00
|
|
|
# SPECIFIC SETUP
|
2021-03-24 22:49:07 +01:00
|
|
|
#=================================================
|
2022-09-04 23:58:47 +02:00
|
|
|
# ADD A CONFIGURATION
|
2021-03-24 22:49:07 +01:00
|
|
|
#=================================================
|
2022-09-04 23:58:47 +02:00
|
|
|
ynh_script_progression --message="Adding a configuration file..." --weight=2
|
2021-03-24 22:49:07 +01:00
|
|
|
|
|
|
|
# WARNING : theses command are used in INSTALL, UPGRADE, CONFIG, CHANGE-URL (4 times)
|
|
|
|
# For any update do it in all files
|
2021-04-05 15:20:06 +02:00
|
|
|
as_token="\"This value is generated when generating the registration\""
|
|
|
|
hs_token="\"This value is generated when generating the registration\""
|
2022-08-27 21:49:13 +02:00
|
|
|
is_encryption_enabled="$encryption"
|
2022-04-12 18:25:33 +02:00
|
|
|
|
|
|
|
if [ $encryption -eq 1 ]; then
|
2022-08-27 21:49:13 +02:00
|
|
|
is_encryption_enabled="true"
|
2022-04-12 18:25:33 +02:00
|
|
|
fi
|
|
|
|
|
2022-09-04 23:58:47 +02:00
|
|
|
if [ "$botusers" = "local" ]
|
|
|
|
then
|
|
|
|
botusers="$server_name"
|
|
|
|
fi
|
|
|
|
|
2023-11-13 21:34:20 +01:00
|
|
|
ynh_add_config --template="config.yaml" --destination="$install_dir/config.yaml"
|
2022-09-04 23:58:47 +02:00
|
|
|
|
2023-11-13 21:34:20 +01:00
|
|
|
chmod 400 "$install_dir/config.yaml"
|
|
|
|
chown $app:$app "$install_dir/config.yaml"
|
2021-04-05 13:28:00 +02:00
|
|
|
|
2021-03-24 22:49:07 +01:00
|
|
|
#=================================================
|
|
|
|
# INSTALL MAUTRIX-BRIDGE PYTHON MODULE
|
|
|
|
#=================================================
|
2022-09-04 23:58:47 +02:00
|
|
|
ynh_script_progression --message="Installing Mautrix-Bridge Python Module..." --weight=6
|
2021-03-24 22:49:07 +01:00
|
|
|
|
|
|
|
mkdir -p /var/log/$app
|
|
|
|
# Configure Mautrix-Bridge
|
2023-11-13 21:34:20 +01:00
|
|
|
python3 -m venv $install_dir
|
|
|
|
export HOME=$install_dir
|
|
|
|
$install_dir/bin/pip3 install --upgrade pip setuptools wheel
|
|
|
|
$install_dir/bin/pip3 install --upgrade $install_dir/src/mautrix-telegram.tar.gz[e2be,speedups,qr_login] # metrics,hq_thumbnails,sqlite,formattednumbers
|
2022-04-12 18:25:33 +02:00
|
|
|
|
2021-03-24 22:49:07 +01:00
|
|
|
#=================================================
|
2022-09-04 23:58:47 +02:00
|
|
|
# REGISTER SYNAPSE APP-SERVICE
|
2021-03-24 22:49:07 +01:00
|
|
|
#=================================================
|
2022-09-04 23:58:47 +02:00
|
|
|
ynh_script_progression --message="Registering Synapse app-service" --weight=1
|
|
|
|
|
2023-11-13 21:34:20 +01:00
|
|
|
$install_dir/bin/python3 -m mautrix_telegram -g -c $install_dir/config.yaml -r "/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
2022-09-04 23:58:47 +02:00
|
|
|
/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die --message="Synapse can't restart with the appservice configuration"
|
2021-03-24 22:49:07 +01:00
|
|
|
|
2023-11-13 21:34:20 +01:00
|
|
|
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"
|
2021-03-24 22:49:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
2022-07-16 01:38:42 +02:00
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring a systemd service..." --weight=20
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
2021-03-24 22:49:07 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring log rotation..." --weight=3
|
|
|
|
|
|
|
|
# Use logrotate to manage application logfile(s)
|
2021-04-05 15:20:06 +02:00
|
|
|
# TODO maybe --specific-user??
|
2022-09-04 23:58:47 +02:00
|
|
|
ynh_use_logrotate --logfile "/var/log/$app/$app.log" --specific_user $app
|
2023-11-13 21:34:20 +01:00
|
|
|
chmod -R 600 "/var/log/$app"
|
|
|
|
chmod 700 "/var/log/$app"
|
2022-09-04 23:58:47 +02:00
|
|
|
chown -R $app:$app /var/log/$app
|
2021-03-24 22:49:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
2022-07-16 01:38:42 +02:00
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
2021-03-24 22:49:07 +01:00
|
|
|
#=================================================
|
2022-07-16 01:38:42 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
|
2022-09-04 23:58:47 +02:00
|
|
|
yunohost service add $app --description="$app daemon for bridging Telegram and Matrix messages" --log="/var/log/$app/$app.log"
|
2021-03-24 22:49:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
|
|
|
|
|
|
|
# Start a systemd service
|
2022-09-04 23:58:47 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
2021-03-24 22:49:07 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Installation of $app completed" --last
|