mirror of
https://github.com/YunoHost-Apps/mautrix_telegram_ynh.git
synced 2024-09-03 19:45:55 +02:00
8a7d54dbc3
add commas to make json happy some minor enhancements hopefully fix mising bdist_wheel add zlib1g-dev as dependency needed to compile / install pillow in virtualenv libjpeg is also a dep of pillow disable packages requiring pillow for now another try with corrected config.toml add missing arguments to alembic try other options for alembic try again with the binary... final try for the alembic configuration enable failure cleaning again alembic still fails... try to fix alembic step we do not need to activate the venv in this case finally working installation use the default database options make upgrade possible bump version, to upgrade... better upgrade script remove unnecessary upgrade bits hopefully we converge remove more unused stuff upgrading should save the auto generated values... fix a type and upgrade script disable abort if errors reenable abort if errors puppeting is actually the usefull permission troubleshooting page further improve readme
255 lines
11 KiB
Bash
255 lines
11 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..." --time --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)
|
|
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
|
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)
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
|
|
### This helper will compare the version of the currently installed app and the version of the upstream package.
|
|
### $upgrade_type can have 2 different values
|
|
### - UPGRADE_APP if the upstream app version has changed
|
|
### - UPGRADE_PACKAGE if only the YunoHost package has changed
|
|
### ynh_check_app_version_changed will stop the upgrade if the app is up to date.
|
|
### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do.
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1
|
|
|
|
#
|
|
# N.B. : the followings setting migrations snippets are provided as *EXAMPLES*
|
|
# of what you may want to do in some cases (e.g. a setting was not defined on
|
|
# some legacy installs and you therefore want to initiaze stuff during upgrade)
|
|
#
|
|
|
|
# If db_name doesn't exist, create it
|
|
#if [ -z "$db_name" ]; then
|
|
# db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
# ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
#fi
|
|
|
|
# If final_path doesn't exist, create it
|
|
#if [ -z "$final_path" ]; then
|
|
# final_path=/var/www/$app
|
|
# ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
|
#fi
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1
|
|
|
|
# Backup the current version of the app
|
|
ynh_backup_before_upgrade
|
|
ynh_clean_setup () {
|
|
# Restore it if the upgrade fails
|
|
ynh_restore_upgradebackup
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Stopping a systemd service..." --time --weight=1
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_script_progression --message="Upgrading source files..." --time --weight=1
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
fi
|
|
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading dependencies..." --time --weight=1
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression --message="Making sure dedicated system user exists..." --time --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
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# ...
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
$final_path/bin/pip3 install --upgrade setuptools wheel # HACK fixes "error: invalid command 'bdist_wheel'"
|
|
$final_path/bin/pip3 install --upgrade $final_path/src/mautrix-telegram.tar.gz[postgres,speedups,webp_convert,qr_login]
|
|
fi
|
|
#
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config
|
|
|
|
#=================================================
|
|
# MODIFY A CONFIG FILE
|
|
#=================================================
|
|
|
|
### 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.
|
|
|
|
server_name=$(ynh_app_setting_get --app=$app --key=server_name)
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
|
mautrix_bridge_user=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_user)
|
|
mautrix_bridge_db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_pwd)
|
|
mautrix_bridge_db_name=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_name)
|
|
botname=$(ynh_app_setting_get --app=$app --key=botname)
|
|
botusers=$(ynh_app_setting_get --app=$app --key=botusers)
|
|
botadmin=$(ynh_app_setting_get --app=$app --key=botadmin)
|
|
apiid=$(ynh_app_setting_get --app=$app --key=apiid)
|
|
apihash=$(ynh_app_setting_get --app=$app --key=apihash)
|
|
bottoken=$(ynh_app_setting_get --app=$app --key=bottoken)
|
|
|
|
# mautrix_config_path="$final_path/config.yaml"
|
|
# cp ../conf/config.yaml "$mautrix_config_path"
|
|
# 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_BRIDGE_USER__ --replace_string=$mautrix_bridge_user --target_file="$mautrix_config_path"
|
|
# ynh_replace_string --match_string=__MAUTRIX_BRIDGE_DB_PWD__ --replace_string=$mautrix_bridge_db_pwd --target_file="$mautrix_config_path"
|
|
# ynh_replace_string --match_string=__MAUTRIX_BRIDGE_DB_NAME__ --replace_string=$mautrix_bridge_db_name --target_file="$mautrix_config_path"
|
|
# ynh_replace_string --match_string=__BOTNAME__ --replace_string=$botname --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_replace_string --match_string=__TELEGRAM_API_ID__ --replace_string=$apiid --target_file="$mautrix_config_path"
|
|
# ynh_replace_string --match_string=__TELEGRAM_API_HASH__ --replace_string=$apihash --target_file="$mautrix_config_path"
|
|
# ynh_replace_string --match_string=__TELEGRAM_BOT_TOKEN__ --replace_string=$bottoken --target_file="$mautrix_config_path"
|
|
|
|
# ynh_backup_if_checksum_is_different --file="$mautrix_config_path"
|
|
|
|
# ynh_replace_string --match_string="script_location = alembic" \
|
|
# --replace_string="script_location = $final_path/alembic" \
|
|
# --target_file="$final_path/alembic.ini"
|
|
# ynh_backup_if_checksum_is_different --file="$final_path/alembic.ini"
|
|
|
|
# upgrade the python stuff
|
|
$final_path/bin/python3 -m mautrix_telegram -g -c "$mautrix_config_path" -r "$app_service_registration_path/$app.yaml"
|
|
|
|
# update the registration file
|
|
synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance)
|
|
app_service_registration_path="/etc/matrix-$synapse_instance/app-service"
|
|
$final_path/bin/alembic -c "$final_path/alembic.ini" -x config="$mautrix_config_path" upgrade head
|
|
|
|
# upgrade the database
|
|
ynh_backup_if_checksum_is_different --file="$app_service_registration_path/$app.yaml"
|
|
|
|
|
|
# Recalculate and store the checksum of the file for the next upgrade.
|
|
ynh_store_file_checksum --file="$mautrix_config_path"
|
|
ynh_store_file_checksum --file="$final_path/alembic.ini"
|
|
|
|
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SECURE FILES AND DIRECTORIES
|
|
#=================================================
|
|
|
|
# Set permissions on app files
|
|
chown -R root: $final_path
|
|
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
ynh_use_logrotate --non-append
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --time --weight=1
|
|
|
|
yunohost service add $app --description="A short description of the app" --log="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..." --time --weight=1
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# RELOAD synapse
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading synapse server..." --time --weight=1
|
|
|
|
/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh \
|
|
|| ynh_die "Synapse can't restart with the appservice configuration"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --time --last
|