mirror of
https://github.com/YunoHost-Apps/mautrix_telegram_ynh.git
synced 2024-09-03 19:45:55 +02:00
[autopatch] Automatic patch attempt for helpers 2.1
This commit is contained in:
parent
fe10ec8b9a
commit
1e78ae4fa5
8 changed files with 188 additions and 248 deletions
|
@ -15,7 +15,8 @@ admindoc = "https://github.com/YunoHost-Apps/mautrix_telegram_ynh"
|
||||||
userdoc = "https://docs.mau.fi/bridges/python/telegram/management-commands.html"
|
userdoc = "https://docs.mau.fi/bridges/python/telegram/management-commands.html"
|
||||||
|
|
||||||
[integration]
|
[integration]
|
||||||
yunohost = ">= 11.1"
|
yunohost = ">= 11.2.18"
|
||||||
|
helpers_version = "2.1"
|
||||||
architectures = ["amd64", "arm64", "armhf"]
|
architectures = ["amd64", "arm64", "armhf"]
|
||||||
multi_instance = true
|
multi_instance = true
|
||||||
ldap = false
|
ldap = false
|
||||||
|
|
|
@ -13,7 +13,7 @@ apply_permissions() {
|
||||||
|
|
||||||
if [ -n "$newValues" ]
|
if [ -n "$newValues" ]
|
||||||
then
|
then
|
||||||
#ynh_systemd_action --service_name="$app" --action=stop
|
#ynh_systemctl --service="$app" --action=stop
|
||||||
# Get all entries between "permissions:" and "relay:" keys, remove the role part, remove commented parts, format it with newlines and clean whitespaces and double quotes.
|
# Get all entries between "permissions:" and "relay:" keys, remove the role part, remove commented parts, format it with newlines and clean whitespaces and double quotes.
|
||||||
allDefinedEntries=$(awk '/permissions:/{flag=1; next} /relaybot:/{flag=0} flag' "$install_dir/config.yaml" | sed "/: $role/d" | sed -r 's/: (admin|user|relaybot|full|puppeting)//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr ',' '\n' )
|
allDefinedEntries=$(awk '/permissions:/{flag=1; next} /relaybot:/{flag=0} flag' "$install_dir/config.yaml" | sed "/: $role/d" | sed -r 's/: (admin|user|relaybot|full|puppeting)//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr ',' '\n' )
|
||||||
# Delete everything from the corresponding role to insert the new defined values. This way we also handle deletion of users.
|
# Delete everything from the corresponding role to insert the new defined values. This way we also handle deletion of users.
|
||||||
|
@ -35,54 +35,41 @@ apply_permissions() {
|
||||||
ynh_print_info "Users with role $role added in $install_dir/config.yaml"
|
ynh_print_info "Users with role $role added in $install_dir/config.yaml"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
set__listrelaybot() {
|
set__listrelaybot() {
|
||||||
role="relaybot"
|
role="relaybot"
|
||||||
ynh_app_setting_set --app=$app --key=listrelaybot --value="$listrelaybot"
|
ynh_app_setting_set --key=listrelaybot --value="$listrelaybot"
|
||||||
apply_permissions
|
apply_permissions
|
||||||
ynh_store_file_checksum --file="$install_dir/config.yaml"
|
ynh_store_file_checksum "$install_dir/config.yaml"
|
||||||
}
|
}
|
||||||
|
|
||||||
set__listuser() {
|
set__listuser() {
|
||||||
role="user"
|
role="user"
|
||||||
ynh_app_setting_set --app=$app --key=listuser --value="$listuser"
|
ynh_app_setting_set --key=listuser --value="$listuser"
|
||||||
apply_permissions
|
apply_permissions
|
||||||
ynh_store_file_checksum --file="$install_dir/config.yaml"
|
ynh_store_file_checksum "$install_dir/config.yaml"
|
||||||
}
|
}
|
||||||
|
|
||||||
set__listpuppeting() {
|
set__listpuppeting() {
|
||||||
role="puppeting"
|
role="puppeting"
|
||||||
ynh_app_setting_set --app=$app --key=listpuppeting --value="$listpuppeting"
|
ynh_app_setting_set --key=listpuppeting --value="$listpuppeting"
|
||||||
apply_permissions
|
apply_permissions
|
||||||
ynh_store_file_checksum --file="$install_dir/config.yaml"
|
ynh_store_file_checksum "$install_dir/config.yaml"
|
||||||
}
|
}
|
||||||
|
|
||||||
set__listfull() {
|
set__listfull() {
|
||||||
role="full"
|
role="full"
|
||||||
ynh_app_setting_set --app=$app --key=listfull --value="$listfull"
|
ynh_app_setting_set --key=listfull --value="$listfull"
|
||||||
apply_permissions
|
apply_permissions
|
||||||
ynh_store_file_checksum --file="$install_dir/config.yaml"
|
ynh_store_file_checksum "$install_dir/config.yaml"
|
||||||
}
|
}
|
||||||
|
|
||||||
set__listadmin() {
|
set__listadmin() {
|
||||||
role="admin"
|
role="admin"
|
||||||
ynh_app_setting_set --app=$app --key=listadmin --value="$listadmin"
|
ynh_app_setting_set --key=listadmin --value="$listadmin"
|
||||||
apply_permissions
|
apply_permissions
|
||||||
ynh_store_file_checksum --file="$install_dir/config.yaml"
|
ynh_store_file_checksum "$install_dir/config.yaml"
|
||||||
}
|
}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# COMMON VARIABLES
|
# COMMON VARIABLES AND CUSTOM HELPERS
|
||||||
#=================================================
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# PERSONAL HELPERS
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# EXPERIMENTAL HELPERS
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# FUTURE OFFICIAL HELPERS
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -1,25 +1,16 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC START
|
|
||||||
#=================================================
|
|
||||||
# IMPORT GENERIC HELPERS
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||||
source ../settings/scripts/_common.sh
|
source ../settings/scripts/_common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
ynh_print_info "Declaring files to be backed up..."
|
||||||
# DECLARE DATA AND CONF FILES TO BACKUP
|
|
||||||
#=================================================
|
|
||||||
ynh_print_info --message="Declaring files to be backed up..."
|
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP THE APP MAIN DIR
|
# BACKUP THE APP MAIN DIR
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_backup --src_path="$install_dir"
|
ynh_backup "$install_dir"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC BACKUP
|
# SPECIFIC BACKUP
|
||||||
|
@ -27,23 +18,23 @@ ynh_backup --src_path="$install_dir"
|
||||||
# BACKUP LOGROTATE
|
# BACKUP LOGROTATE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_backup --src_path="/etc/logrotate.d/$app"
|
ynh_backup "/etc/logrotate.d/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP SYSTEMD
|
# BACKUP SYSTEMD
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_backup --src_path="/etc/systemd/system/$app.service"
|
ynh_backup "/etc/systemd/system/$app.service"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP THE POSTGRESQL DATABASE
|
# BACKUP THE POSTGRESQL DATABASE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_print_info --message="Backing up the PostgreSQL database..."
|
ynh_print_info "Backing up the PostgreSQL database..."
|
||||||
|
|
||||||
ynh_psql_dump_db --database="$db_name" > db.sql
|
ynh_psql_dump_db > db.sql
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
|
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
source _common.sh
|
source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
ynh_abort_if_errors
|
#REMOVEME? ynh_abort_if_errors
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC GETTERS FOR TOML SHORT KEY
|
# SPECIFIC GETTERS FOR TOML SHORT KEY
|
||||||
|
@ -13,7 +13,7 @@ get_config_permission() {
|
||||||
}
|
}
|
||||||
|
|
||||||
get__botname() {
|
get__botname() {
|
||||||
botname=$(ynh_app_setting_get --app $app --key botname)
|
botname=$(ynh_app_setting_get --key botname)
|
||||||
echo "${botname}"
|
echo "${botname}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,21 +71,21 @@ EOF
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
set__botname() {
|
set__botname() {
|
||||||
old_botname=$(ynh_app_setting_get --app $app --key botname)
|
old_botname=$(ynh_app_setting_get --key botname)
|
||||||
if [ "$botname" -eq "$old_botname" ] # Check to avoid updating botname when it's not needed.
|
if [ "$botname" -eq "$old_botname" ] # Check to avoid updating botname when it's not needed.
|
||||||
then
|
then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ynh_app_setting_set --app=$app --key=botname --value="$botname"
|
ynh_app_setting_set --key=botname --value="$botname"
|
||||||
synapse_instance=$(ynh_app_setting_get --app $app --key synapse_instance)
|
synapse_instance=$(ynh_app_setting_get --key synapse_instance)
|
||||||
|
|
||||||
sed -i "s/bot_username:.*/bot_username: $botname/" "$install_dir/config.yaml"
|
sed -i "s/bot_username:.*/bot_username: $botname/" "$install_dir/config.yaml"
|
||||||
"$install_dir/mautrix-whatsapp" -g -c "$install_dir/config.yaml" -r "/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
"$install_dir/mautrix-whatsapp" -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"
|
"/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh" || ynh_die "Synapse can't restart with the appservice configuration"
|
||||||
chown -R "$app:$app" "$install_dir"
|
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:$app" "$install_dir"
|
||||||
ynh_store_file_checksum --file="/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
ynh_store_file_checksum "/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
||||||
ynh_store_file_checksum --file="$install_dir/config.yaml"
|
ynh_store_file_checksum "$install_dir/config.yaml"
|
||||||
}
|
}
|
||||||
|
|
||||||
ynh_app_config_run $1
|
ynh_app_config_run $1
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC START
|
|
||||||
#=================================================
|
|
||||||
# IMPORT GENERIC HELPERS
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
|
@ -17,9 +11,9 @@ source /usr/share/yunohost/helpers
|
||||||
appserviceid=$app
|
appserviceid=$app
|
||||||
server_name=$(ynh_app_setting_get --app $synapse_instance --key server_name)
|
server_name=$(ynh_app_setting_get --app $synapse_instance --key server_name)
|
||||||
domain=$(ynh_app_setting_get --app $synapse_instance --key domain)
|
domain=$(ynh_app_setting_get --app $synapse_instance --key domain)
|
||||||
ynh_app_setting_set --app=$app --key=server_name --value=$server_name
|
ynh_app_setting_set --key=server_name --value=$server_name
|
||||||
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
ynh_app_setting_set --key=domain --value=$domain
|
||||||
ynh_app_setting_set --app=$app --key=appserviceid --value=$appserviceid
|
ynh_app_setting_set --key=appserviceid --value=$appserviceid
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SET STANDARD SETTINGS FROM DEFAULT CONFIG
|
# SET STANDARD SETTINGS FROM DEFAULT CONFIG
|
||||||
|
@ -47,42 +41,41 @@ listpuppeting="$botusers"
|
||||||
listfull=""
|
listfull=""
|
||||||
listadmin="$botadmin"
|
listadmin="$botadmin"
|
||||||
|
|
||||||
ynh_app_setting_set --app=$app --key=appserviceid --value=$appserviceid
|
ynh_app_setting_set --key=appserviceid --value=$appserviceid
|
||||||
ynh_app_setting_set --app=$app --key=async_media --value=$async_media
|
ynh_app_setting_set --key=async_media --value=$async_media
|
||||||
ynh_app_setting_set --app=$app --key=bot_displayname --value=$bot_displayname
|
ynh_app_setting_set --key=bot_displayname --value=$bot_displayname
|
||||||
ynh_app_setting_set --app=$app --key=bot_username --value=$bot_username
|
ynh_app_setting_set --key=bot_username --value=$bot_username
|
||||||
ynh_app_setting_set --app=$app --key=bot_avatar --value=$bot_avatar
|
ynh_app_setting_set --key=bot_avatar --value=$bot_avatar
|
||||||
ynh_app_setting_set --app=$app --key=device_model --value=$device_model
|
ynh_app_setting_set --key=device_model --value=$device_model
|
||||||
ynh_app_setting_set --app=$app --key=ephemeral_events --value=$ephemeral_events
|
ynh_app_setting_set --key=ephemeral_events --value=$ephemeral_events
|
||||||
ynh_app_setting_set --app=$app --key=enable_metrics --value=$enable_metrics
|
ynh_app_setting_set --key=enable_metrics --value=$enable_metrics
|
||||||
ynh_app_setting_set --app=$app --key=listen_port --value=$listen_port
|
ynh_app_setting_set --key=listen_port --value=$listen_port
|
||||||
ynh_app_setting_set --app=$app --key=alias_template --value=$alias_template
|
ynh_app_setting_set --key=alias_template --value=$alias_template
|
||||||
ynh_app_setting_set --app=$app --key=displayname_template --value=$displayname_template
|
ynh_app_setting_set --key=displayname_template --value=$displayname_template
|
||||||
ynh_app_setting_set --app=$app --key=username_template --value=$username_template
|
ynh_app_setting_set --key=username_template --value=$username_template
|
||||||
ynh_app_setting_set --app=$app --key=delivery_receipts --value=$delivery_receipts
|
ynh_app_setting_set --key=delivery_receipts --value=$delivery_receipts
|
||||||
ynh_app_setting_set --app=$app --key=telegram_link_preview --value=$telegram_link_preview
|
ynh_app_setting_set --key=telegram_link_preview --value=$telegram_link_preview
|
||||||
ynh_app_setting_set --app=$app --key=encryption_default --value=$encryption_default
|
ynh_app_setting_set --key=encryption_default --value=$encryption_default
|
||||||
ynh_app_setting_set --app=$app --key=encryption_require --value=$encryption_require
|
ynh_app_setting_set --key=encryption_require --value=$encryption_require
|
||||||
ynh_app_setting_set --app=$app --key=listrelaybot --value=$listrelaybot
|
ynh_app_setting_set --key=listrelaybot --value=$listrelaybot
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Setting up source files..." --weight=3
|
ynh_script_progression "Setting up source files..."
|
||||||
|
|
||||||
# Download, check integrity, uncompress and patch the source from app.src
|
# Download, check integrity, uncompress and patch the source from app.src
|
||||||
ynh_setup_source --dest_dir="$install_dir/src"
|
ynh_setup_source --dest_dir="$install_dir/src"
|
||||||
|
|
||||||
chmod 750 "$install_dir"
|
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 750 "$install_dir"
|
||||||
chmod -R 750 "$install_dir"
|
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R 750 "$install_dir"
|
||||||
chown -R $app:$app "$install_dir"
|
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "$install_dir"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC SETUP
|
# SPECIFIC SETUP
|
||||||
#=================================================
|
#=================================================
|
||||||
# ADD A CONFIGURATION
|
# ADD A CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Adding a configuration file..." --weight=2
|
ynh_script_progression "Adding $app's configuration..."
|
||||||
|
|
||||||
# WARNING : theses command are used in INSTALL, UPGRADE, CONFIG, CHANGE-URL (4 times)
|
# WARNING : theses command are used in INSTALL, UPGRADE, CONFIG, CHANGE-URL (4 times)
|
||||||
# For any update do it in all files
|
# For any update do it in all files
|
||||||
|
@ -99,10 +92,10 @@ then
|
||||||
botusers="$server_name"
|
botusers="$server_name"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ynh_add_config --template="config.yaml" --destination="$install_dir/config.yaml"
|
ynh_config_add --template="config.yaml" --destination="$install_dir/config.yaml"
|
||||||
|
|
||||||
chmod 400 "$install_dir/config.yaml"
|
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/config.yaml"
|
||||||
chown $app:$app "$install_dir/config.yaml"
|
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/config.yaml"
|
||||||
|
|
||||||
# This calls allows to set multiple users during install question "botusers" specifying them separated by a comma
|
# This calls allows to set multiple users during install question "botusers" specifying them separated by a comma
|
||||||
set__listrelaybot
|
set__listrelaybot
|
||||||
|
@ -114,7 +107,7 @@ set__listadmin
|
||||||
#=================================================
|
#=================================================
|
||||||
# INSTALL MAUTRIX-BRIDGE PYTHON MODULE
|
# INSTALL MAUTRIX-BRIDGE PYTHON MODULE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Installing Mautrix-Bridge Python Module..." --weight=6
|
ynh_script_progression "Installing Mautrix-Bridge Python Module..."
|
||||||
|
|
||||||
mkdir -p /var/log/$app
|
mkdir -p /var/log/$app
|
||||||
# Configure Mautrix-Bridge
|
# Configure Mautrix-Bridge
|
||||||
|
@ -126,54 +119,52 @@ $install_dir/bin/pip3 install --upgrade $install_dir/src/mautrix-telegram.tar.gz
|
||||||
#=================================================
|
#=================================================
|
||||||
# REGISTER SYNAPSE APP-SERVICE
|
# REGISTER SYNAPSE APP-SERVICE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Registering Synapse app-service" --weight=1
|
ynh_script_progression "Registering Synapse app-service"
|
||||||
|
|
||||||
$install_dir/bin/python3 -m mautrix_telegram -g -c $install_dir/config.yaml -r "/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
$install_dir/bin/python3 -m mautrix_telegram -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"
|
/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die "Synapse can't restart with the appservice configuration"
|
||||||
|
|
||||||
chown -R $app:$app "$install_dir"
|
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "$install_dir"
|
||||||
ynh_store_file_checksum --file="/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
ynh_store_file_checksum "/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
||||||
ynh_store_file_checksum --file="$install_dir/config.yaml"
|
ynh_store_file_checksum "$install_dir/config.yaml"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP SYSTEMD
|
# SETUP SYSTEMD
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Configuring a systemd service..." --weight=20
|
ynh_script_progression "Configuring $app's systemd service..."
|
||||||
|
|
||||||
# Create a dedicated systemd config
|
# Create a dedicated systemd config
|
||||||
ynh_add_systemd_config
|
ynh_config_add_systemd
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC FINALIZATION
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP LOGROTATE
|
# SETUP LOGROTATE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Configuring log rotation..." --weight=3
|
ynh_script_progression "Configuring log rotation..."
|
||||||
|
|
||||||
# Use logrotate to manage application logfile(s)
|
# Use logrotate to manage application logfile(s)
|
||||||
# TODO maybe --specific-user??
|
# TODO maybe --specific-user??
|
||||||
ynh_use_logrotate --logfile "/var/log/$app/$app.log" --specific_user $app
|
ynh_config_add_logrotate "/var/log/$app/$app.log" $app
|
||||||
chmod -R 600 "/var/log/$app"
|
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R 600 "/var/log/$app"
|
||||||
chmod 700 "/var/log/$app"
|
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 700 "/var/log/$app"
|
||||||
chown -R $app:$app /var/log/$app
|
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app /var/log/$app
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INTEGRATE SERVICE IN YUNOHOST
|
# INTEGRATE SERVICE IN YUNOHOST
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Integrating service in YunoHost..."
|
ynh_script_progression "Integrating service in YunoHost..."
|
||||||
|
|
||||||
yunohost service add $app --description="$app daemon for bridging Telegram and Matrix messages" --log="/var/log/$app/$app.log"
|
yunohost service add $app --description="$app daemon for bridging Telegram and Matrix messages" --log="/var/log/$app/$app.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# START SYSTEMD SERVICE
|
# START SYSTEMD SERVICE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
ynh_script_progression "Starting $app's systemd service..."
|
||||||
|
|
||||||
# Start a systemd service
|
# Start a systemd service
|
||||||
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
ynh_systemctl --service=$app --action="start"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_script_progression --message="Installation of $app completed" --last
|
ynh_script_progression "Installation of $app completed"
|
||||||
|
|
|
@ -1,18 +1,12 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC START
|
|
||||||
#=================================================
|
|
||||||
# IMPORT GENERIC HELPERS
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD SETTINGS
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Loading installation settings..." --weight=5
|
ynh_script_progression "Loading installation settings..."
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
|
@ -23,38 +17,38 @@ app=$YNH_APP_INSTANCE_NAME
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
|
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
|
||||||
if ynh_exec_warn_less yunohost service status $app >/dev/null
|
if ynh_hide_warnings yunohost service status $app >/dev/null
|
||||||
then
|
then
|
||||||
ynh_script_progression --message="Removing $app service integration..." --weight=3
|
ynh_script_progression "Removing $app service integration..."
|
||||||
yunohost service remove $app
|
yunohost service remove $app
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STOP AND REMOVE SERVICE
|
# STOP AND REMOVE SERVICE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
|
ynh_script_progression "Stopping and removing the systemd service..."
|
||||||
|
|
||||||
# Remove the dedicated systemd config
|
# Remove the dedicated systemd config
|
||||||
ynh_remove_systemd_config
|
ynh_config_remove_systemd
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE LOGROTATE CONFIGURATION
|
# REMOVE LOGROTATE CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Removing logrotate configuration..." --weight=1
|
ynh_script_progression "Removing logrotate configuration..."
|
||||||
|
|
||||||
# Remove the app-specific logrotate config
|
# Remove the app-specific logrotate config
|
||||||
ynh_remove_logrotate
|
ynh_config_remove_logrotate
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC REMOVE
|
# SPECIFIC REMOVE
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE VARIOUS FILES
|
# REMOVE VARIOUS FILES
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Removing various files..." --weight=6
|
ynh_script_progression "Removing various files..."
|
||||||
|
|
||||||
# Remove a directory securely
|
# Remove a directory securely
|
||||||
ynh_secure_remove --file="/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
ynh_safe_rm "/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"
|
/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die "Synapse can't restart with the appservice configuration"
|
||||||
|
|
||||||
# Remove the log files
|
# Remove the log files
|
||||||
|
|
||||||
|
@ -62,4 +56,4 @@ ynh_secure_remove --file="/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_script_progression --message="Removal of $app completed" --last
|
ynh_script_progression "Removal of $app completed"
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC START
|
|
||||||
#=================================================
|
|
||||||
# IMPORT GENERIC HELPERS
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
||||||
source ../settings/scripts/_common.sh
|
source ../settings/scripts/_common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
@ -13,51 +7,50 @@ source /usr/share/yunohost/helpers
|
||||||
#=================================================
|
#=================================================
|
||||||
# LOAD SETTINGS
|
# LOAD SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Loading installation settings..." --weight=1
|
ynh_script_progression "Loading installation settings..."
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
db_name=$(ynh_app_setting_get --key=db_name)
|
||||||
synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance)
|
synapse_instance=$(ynh_app_setting_get --key=synapse_instance)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD RESTORATION STEPS
|
# STANDARD RESTORATION STEPS
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE THE APP MAIN DIR
|
# RESTORE THE APP MAIN DIR
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Restoring the app main directory..." --weight=1
|
ynh_script_progression "Restoring the app main directory..."
|
||||||
|
|
||||||
ynh_restore_file --origin_path="$install_dir"
|
ynh_restore "$install_dir"
|
||||||
|
|
||||||
chmod 750 "$install_dir"
|
|
||||||
chmod -R 750 "$install_dir"
|
|
||||||
chown -R "$app:$app" "$install_dir"
|
|
||||||
|
|
||||||
|
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 750 "$install_dir"
|
||||||
|
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R 750 "$install_dir"
|
||||||
|
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:$app" "$install_dir"
|
||||||
#=================================================
|
#=================================================
|
||||||
# SPECIFIC RESTORATION
|
# SPECIFIC RESTORATION
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE THE POSTGRESQL DATABASE
|
# RESTORE THE POSTGRESQL DATABASE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=8
|
ynh_script_progression "Restoring the PostgreSQL database..."
|
||||||
|
|
||||||
ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name"
|
ynh_psql_db_shell " < "./db.sql""
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE THE LOGROTATE CONFIGURATION
|
# RESTORE THE LOGROTATE CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
# This section has to be always above REGISTER SYNAPSE APP-SERVICE section in order to restore successfully
|
# This section has to be always above REGISTER SYNAPSE APP-SERVICE section in order to restore successfully
|
||||||
ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
|
ynh_script_progression "Restoring the logrotate configuration..."
|
||||||
|
|
||||||
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
ynh_restore "/etc/logrotate.d/$app"
|
||||||
mkdir -p "/var/log/$app"
|
mkdir -p "/var/log/$app"
|
||||||
chmod -R 600 "/var/log/$app"
|
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R 600 "/var/log/$app"
|
||||||
chmod 700 "/var/log/$app"
|
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 700 "/var/log/$app"
|
||||||
chown -R "$app:$app" "/var/log/$app"
|
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:$app" "/var/log/$app"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REGISTER SYNAPSE APP-SERVICE
|
# REGISTER SYNAPSE APP-SERVICE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Registering Synapse app-service" --weight=1
|
ynh_script_progression "Registering Synapse app-service"
|
||||||
|
|
||||||
$install_dir/bin/python3 -m mautrix_telegram -g -c "$install_dir/config.yaml" -r "/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
$install_dir/bin/python3 -m mautrix_telegram -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 || echo "Synapse can't restart with the appservice configuration"
|
/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || echo "Synapse can't restart with the appservice configuration"
|
||||||
|
@ -65,28 +58,28 @@ $install_dir/bin/python3 -m mautrix_telegram -g -c "$install_dir/config.yaml" -r
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE SYSTEMD
|
# RESTORE SYSTEMD
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
|
ynh_script_progression "Restoring $app's systemd service..."
|
||||||
|
|
||||||
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
|
ynh_restore "/etc/systemd/system/$app.service"
|
||||||
systemctl enable $app.service --quiet
|
systemctl enable $app.service --quiet
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INTEGRATE SERVICE IN YUNOHOST
|
# INTEGRATE SERVICE IN YUNOHOST
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
ynh_script_progression "Integrating service in YunoHost..."
|
||||||
|
|
||||||
yunohost service add $app --description="$app daemon for bridging Telegram and Matrix messages" --log="/var/log/$app/$app.log"
|
yunohost service add $app --description="$app daemon for bridging Telegram and Matrix messages" --log="/var/log/$app/$app.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# START SYSTEMD SERVICE
|
# START SYSTEMD SERVICE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
ynh_script_progression "Starting $app's systemd service..."
|
||||||
|
|
||||||
# Start a systemd service
|
# Start a systemd service
|
||||||
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
ynh_systemctl --service=$app --action="start"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_script_progression --message="Restoration completed for $app" --last
|
ynh_script_progression "Restoration completed for $app"
|
||||||
|
|
177
scripts/upgrade
177
scripts/upgrade
|
@ -1,84 +1,71 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC START
|
|
||||||
#=================================================
|
|
||||||
# IMPORT GENERIC HELPERS
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
source _common.sh
|
source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
server_name=$(ynh_app_setting_get --app=$app --key=server_name)
|
server_name=$(ynh_app_setting_get --key=server_name)
|
||||||
synapse_db_name="matrix_$synapse_instance"
|
synapse_db_name="matrix_$synapse_instance"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# GET CONFIG PANEL SETTINGS
|
# GET CONFIG PANEL SETTINGS
|
||||||
#=================================================
|
#=================================================
|
||||||
async_media=$(ynh_app_setting_get --app=$app --key=async_media)
|
async_media=$(ynh_app_setting_get --key=async_media)
|
||||||
bot_displayname=$(ynh_app_setting_get --app=$app --key=bot_displayname)
|
bot_displayname=$(ynh_app_setting_get --key=bot_displayname)
|
||||||
bot_username=$(ynh_app_setting_get --app=$app --key=bot_username)
|
bot_username=$(ynh_app_setting_get --key=bot_username)
|
||||||
bot_avatar=$(ynh_app_setting_get --app=$app --key=bot_avatar)
|
bot_avatar=$(ynh_app_setting_get --key=bot_avatar)
|
||||||
device_model=$(ynh_app_setting_get --app=$app --key=device_model)
|
device_model=$(ynh_app_setting_get --key=device_model)
|
||||||
ephemeral_events=$(ynh_app_setting_get --app=$app --key=ephemeral_events)
|
ephemeral_events=$(ynh_app_setting_get --key=ephemeral_events)
|
||||||
enable_metrics=$(ynh_app_setting_get --app=$app --key=enable_metrics)
|
enable_metrics=$(ynh_app_setting_get --key=enable_metrics)
|
||||||
listen_port=$(ynh_app_setting_get --app=$app --key=listen_port)
|
listen_port=$(ynh_app_setting_get --key=listen_port)
|
||||||
alias_template=$(ynh_app_setting_get --app=$app --key=alias_template)
|
alias_template=$(ynh_app_setting_get --key=alias_template)
|
||||||
displayname_template=$(ynh_app_setting_get --app=$app --key=displayname_template)
|
displayname_template=$(ynh_app_setting_get --key=displayname_template)
|
||||||
username_template=$(ynh_app_setting_get --app=$app --key=username_template)
|
username_template=$(ynh_app_setting_get --key=username_template)
|
||||||
delivery_receipts=$(ynh_app_setting_get --app=$app --key=delivery_receipts)
|
delivery_receipts=$(ynh_app_setting_get --key=delivery_receipts)
|
||||||
telegram_link_preview=$(ynh_app_setting_get --app=$app --key=telegram_link_preview)
|
telegram_link_preview=$(ynh_app_setting_get --key=telegram_link_preview)
|
||||||
encryption_default=$(ynh_app_setting_get --app=$app --key=encryption_default)
|
encryption_default=$(ynh_app_setting_get --key=encryption_default)
|
||||||
encryption_require=$(ynh_app_setting_get --app=$app --key=encryption_require)
|
encryption_require=$(ynh_app_setting_get --key=encryption_require)
|
||||||
|
|
||||||
listrelaybot=$(ynh_app_setting_get --app=$app --key=listrelaybot)
|
listrelaybot=$(ynh_app_setting_get --key=listrelaybot)
|
||||||
listuser=$(ynh_app_setting_get --app=$app --key=listuser)
|
listuser=$(ynh_app_setting_get --key=listuser)
|
||||||
listpuppeting=$(ynh_app_setting_get --app=$app --key=listpuppeting)
|
listpuppeting=$(ynh_app_setting_get --key=listpuppeting)
|
||||||
listfull=$(ynh_app_setting_get --app=$app --key=listfull)
|
listfull=$(ynh_app_setting_get --key=listfull)
|
||||||
listadmin=$(ynh_app_setting_get --app=$app --key=listadmin)
|
listadmin=$(ynh_app_setting_get --key=listadmin)
|
||||||
|
|
||||||
#=================================================
|
ynh_script_progression "Checking version..."
|
||||||
# CHECK VERSION
|
|
||||||
#=================================================
|
|
||||||
ynh_script_progression --message="Checking version..." --weight=1
|
|
||||||
|
|
||||||
upgrade_type=$(ynh_check_app_version_changed)
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# STANDARD UPGRADE STEPS
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STOP SYSTEMD SERVICE
|
# STOP SYSTEMD SERVICE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
ynh_script_progression "Stopping $app's systemd service..."
|
||||||
|
|
||||||
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
|
ynh_systemctl --service=$app --action="stop"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# ENSURE DOWNWARD COMPATIBILITY
|
# ENSURE DOWNWARD COMPATIBILITY
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
ynh_script_progression "Ensuring downward compatibility..."
|
||||||
|
|
||||||
# If appserviceid doesn't exist, create it
|
# If appserviceid doesn't exist, create it
|
||||||
if [ -z "$appserviceid" ]
|
if [ -z "$appserviceid" ]
|
||||||
then
|
then
|
||||||
appserviceid=$app
|
appserviceid=$app
|
||||||
ynh_app_setting_set --app=$app --key=appserviceid --value=$appserviceid
|
ynh_app_setting_set --key=appserviceid --value=$appserviceid
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If db_name doesn't exist, create it
|
# If db_name doesn't exist, create it
|
||||||
if [ -z "$db_name" ]
|
if [ -z "$db_name" ]
|
||||||
then
|
then
|
||||||
db_name=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_name)
|
db_name=$(ynh_app_setting_get --key=mautrix_bridge_db_name)
|
||||||
# db_name and db_user share the same value
|
# db_name and db_user share the same value
|
||||||
db_user=$db_name
|
db_user=$db_name
|
||||||
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
ynh_app_setting_set --key=db_name --value=$db_name
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If db_pwd doesn't exist, create it
|
# If db_pwd doesn't exist, create it
|
||||||
if [ -z "$db_pwd" ]
|
if [ -z "$db_pwd" ]
|
||||||
then
|
then
|
||||||
db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_bridge_db_pwd)
|
db_pwd=$(ynh_app_setting_get --key=mautrix_bridge_db_pwd)
|
||||||
ynh_app_setting_set --app=$app --key=psqlpwd --value=$db_pwd
|
ynh_app_setting_set --key=psqlpwd --value=$db_pwd
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -88,127 +75,125 @@ fi
|
||||||
if [ -z "$async_media" ]
|
if [ -z "$async_media" ]
|
||||||
then
|
then
|
||||||
async_media="false"
|
async_media="false"
|
||||||
ynh_app_setting_set --app=$app --key=async_media --value=$async_media
|
ynh_app_setting_set --key=async_media --value=$async_media
|
||||||
fi
|
fi
|
||||||
if [ -z "$bot_username" ]
|
if [ -z "$bot_username" ]
|
||||||
then
|
then
|
||||||
bot_username="$botname"
|
bot_username="$botname"
|
||||||
ynh_app_setting_set --app=$app --key=bot_username --value=$bot_username
|
ynh_app_setting_set --key=bot_username --value=$bot_username
|
||||||
fi
|
fi
|
||||||
if [ -z "$bot_displayname" ]
|
if [ -z "$bot_displayname" ]
|
||||||
then
|
then
|
||||||
bot_displayname="Telegram bridge bot"
|
bot_displayname="Telegram bridge bot"
|
||||||
ynh_app_setting_set --app=$app --key=bot_displayname --value=$bot_displayname
|
ynh_app_setting_set --key=bot_displayname --value=$bot_displayname
|
||||||
fi
|
fi
|
||||||
if [ -z "$bot_avatar" ]
|
if [ -z "$bot_avatar" ]
|
||||||
then
|
then
|
||||||
bot_avatar="mxc://maunium.net/tJCRmUyJDsgRNgqhOgoiHWbX"
|
bot_avatar="mxc://maunium.net/tJCRmUyJDsgRNgqhOgoiHWbX"
|
||||||
ynh_app_setting_set --app=$app --key=bot_avatar --value=$bot_avatar
|
ynh_app_setting_set --key=bot_avatar --value=$bot_avatar
|
||||||
fi
|
fi
|
||||||
if [ -z "$device_model" ]
|
if [ -z "$device_model" ]
|
||||||
then
|
then
|
||||||
device_model="mautrix-telegram"
|
device_model="mautrix-telegram"
|
||||||
ynh_app_setting_set --app=$app --key=device_model --value=$device_model
|
ynh_app_setting_set --key=device_model --value=$device_model
|
||||||
fi
|
fi
|
||||||
if [ -z "$ephemeral_events" ]
|
if [ -z "$ephemeral_events" ]
|
||||||
then
|
then
|
||||||
ephemeral_events="false"
|
ephemeral_events="false"
|
||||||
ynh_app_setting_set --app=$app --key=ephemeral_events --value=$ephemeral_events
|
ynh_app_setting_set --key=ephemeral_events --value=$ephemeral_events
|
||||||
fi
|
fi
|
||||||
if [ -z "$enable_metrics" ]
|
if [ -z "$enable_metrics" ]
|
||||||
then
|
then
|
||||||
enable_metrics="false"
|
enable_metrics="false"
|
||||||
ynh_app_setting_set --app=$app --key=enable_metrics --value=$enable_metrics
|
ynh_app_setting_set --key=enable_metrics --value=$enable_metrics
|
||||||
fi
|
fi
|
||||||
if [ -z "$listen_port" ]
|
if [ -z "$listen_port" ]
|
||||||
then
|
then
|
||||||
listen_port="8000"
|
listen_port="8000"
|
||||||
ynh_app_setting_set --app=$app --key=listen_port --value=$listen_port
|
ynh_app_setting_set --key=listen_port --value=$listen_port
|
||||||
fi
|
fi
|
||||||
if [ -z "$alias_template" ]
|
if [ -z "$alias_template" ]
|
||||||
then
|
then
|
||||||
alias_template="telegram_{userid}"
|
alias_template="telegram_{userid}"
|
||||||
ynh_app_setting_set --app=$app --key=alias_template --value=$alias_template
|
ynh_app_setting_set --key=alias_template --value=$alias_template
|
||||||
fi
|
fi
|
||||||
if [ -z "$displayname_template" ]
|
if [ -z "$displayname_template" ]
|
||||||
then
|
then
|
||||||
displayname_template="{displayname} (Telegram)"
|
displayname_template="{displayname} (Telegram)"
|
||||||
ynh_app_setting_set --app=$app --key=displayname_template --value=$displayname_template
|
ynh_app_setting_set --key=displayname_template --value=$displayname_template
|
||||||
fi
|
fi
|
||||||
if [ -z "$username_template" ]
|
if [ -z "$username_template" ]
|
||||||
then
|
then
|
||||||
username_template="telegram_{userid}"
|
username_template="telegram_{userid}"
|
||||||
ynh_app_setting_set --app=$app --key=username_template --value=$username_template
|
ynh_app_setting_set --key=username_template --value=$username_template
|
||||||
fi
|
fi
|
||||||
if [ -z "$delivery_receipts" ]
|
if [ -z "$delivery_receipts" ]
|
||||||
then
|
then
|
||||||
delivery_receipts="false"
|
delivery_receipts="false"
|
||||||
ynh_app_setting_set --app=$app --key=delivery_receipts --value=$delivery_receipts
|
ynh_app_setting_set --key=delivery_receipts --value=$delivery_receipts
|
||||||
fi
|
fi
|
||||||
if [ -z "$telegram_link_preview" ]
|
if [ -z "$telegram_link_preview" ]
|
||||||
then
|
then
|
||||||
telegram_link_preview="false"
|
telegram_link_preview="false"
|
||||||
ynh_app_setting_set --app=$app --key=telegram_link_preview --value=$telegram_link_preview
|
ynh_app_setting_set --key=telegram_link_preview --value=$telegram_link_preview
|
||||||
fi
|
fi
|
||||||
if [ -z "$encryption_default" ]
|
if [ -z "$encryption_default" ]
|
||||||
then
|
then
|
||||||
encryption_default="false"
|
encryption_default="false"
|
||||||
ynh_app_setting_set --app=$app --key=encryption_default --value=$encryption_default
|
ynh_app_setting_set --key=encryption_default --value=$encryption_default
|
||||||
fi
|
fi
|
||||||
if [ -z "$encryption_require" ]
|
if [ -z "$encryption_require" ]
|
||||||
then
|
then
|
||||||
encryption_require="false"
|
encryption_require="false"
|
||||||
ynh_app_setting_set --app=$app --key=encryption_require --value=$encryption_require
|
ynh_app_setting_set --key=encryption_require --value=$encryption_require
|
||||||
fi
|
fi
|
||||||
if [ -z "$listrelaybot" ]
|
if [ -z "$listrelaybot" ]
|
||||||
then
|
then
|
||||||
listrelaybot="*"
|
listrelaybot="*"
|
||||||
ynh_app_setting_set --app=$app --key=listrelaybot --value=$listrelaybot
|
ynh_app_setting_set --key=listrelaybot --value=$listrelaybot
|
||||||
fi
|
fi
|
||||||
if [ -z "$listuser" ]
|
if [ -z "$listuser" ]
|
||||||
then
|
then
|
||||||
listuser=""
|
listuser=""
|
||||||
ynh_app_setting_set --app=$app --key=listuser --value=$listuser
|
ynh_app_setting_set --key=listuser --value=$listuser
|
||||||
fi
|
fi
|
||||||
if [ -z "$listpuppeting" ]
|
if [ -z "$listpuppeting" ]
|
||||||
then
|
then
|
||||||
listpuppeting=$(ynh_app_setting_get --app=$app --key=botusers)
|
listpuppeting=$(ynh_app_setting_get --key=botusers)
|
||||||
ynh_app_setting_set --app=$app --key=listpuppeting --value=$listpuppeting
|
ynh_app_setting_set --key=listpuppeting --value=$listpuppeting
|
||||||
ynh_app_setting_delete --app=$app --key=botusers
|
ynh_app_setting_delete --key=botusers
|
||||||
fi
|
fi
|
||||||
if [ -z "$listfull" ]
|
if [ -z "$listfull" ]
|
||||||
then
|
then
|
||||||
listfull=""
|
listfull=""
|
||||||
ynh_app_setting_set --app=$app --key=listfull --value=$listfull
|
ynh_app_setting_set --key=listfull --value=$listfull
|
||||||
fi
|
fi
|
||||||
if [ -z "$listadmin" ]
|
if [ -z "$listadmin" ]
|
||||||
then
|
then
|
||||||
listadmin=$(ynh_app_setting_get --app=$app --key=botadmin)
|
listadmin=$(ynh_app_setting_get --key=botadmin)
|
||||||
ynh_app_setting_set --app=$app --key=listadmin --value=$listadmin
|
ynh_app_setting_set --key=listadmin --value=$listadmin
|
||||||
ynh_app_setting_delete --app=$app --key=botadmin
|
ynh_app_setting_delete --key=botadmin
|
||||||
fi
|
fi
|
||||||
#=================================================
|
#=================================================
|
||||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
# FIXME: this is still supported but the recommendation is now to *always* re-setup the app sources wether or not the upstream sources changed
|
||||||
|
if ynh_app_upstream_version_changed
|
||||||
then
|
then
|
||||||
ynh_script_progression --message="Upgrading source files..." --weight=1
|
ynh_script_progression "Upgrading source files..."
|
||||||
|
|
||||||
# Download, check integrity, uncompress and patch the source from app.src
|
# Download, check integrity, uncompress and patch the source from app.src
|
||||||
ynh_setup_source --dest_dir="$install_dir/src"
|
ynh_setup_source --dest_dir="$install_dir/src"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
chmod 750 "$install_dir"
|
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 750 "$install_dir"
|
||||||
chmod -R 750 "$install_dir"
|
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R 750 "$install_dir"
|
||||||
chown -R $app:$app "$install_dir"
|
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "$install_dir"
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# SPECIFIC UPGRADE
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# UPDATE A CONFIG FILE
|
# UPDATE A CONFIG FILE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Updating a configuration file..." --weight=2
|
ynh_script_progression "Updating configuration..."
|
||||||
|
|
||||||
# reset permissions to be able to apply_permissions with app_setting values after upgrade
|
# reset permissions to be able to apply_permissions with app_setting values after upgrade
|
||||||
listrelaybot_=$listrelaybot
|
listrelaybot_=$listrelaybot
|
||||||
|
@ -223,7 +208,7 @@ listfull="@full:domain.tld"
|
||||||
listadmin="@admin:domain.tld"
|
listadmin="@admin:domain.tld"
|
||||||
|
|
||||||
# main configuration
|
# main configuration
|
||||||
ynh_backup_if_checksum_is_different --file="$install_dir/config.yaml"
|
ynh_backup_if_checksum_is_different "$install_dir/config.yaml"
|
||||||
# as_token hs_token are autogenerated, save them before regenerating the config
|
# as_token hs_token are autogenerated, save them before regenerating the config
|
||||||
as_token=$(grep "as_token:" "$install_dir/config.yaml" | sed -r "s/ *as_token: *//")
|
as_token=$(grep "as_token:" "$install_dir/config.yaml" | sed -r "s/ *as_token: *//")
|
||||||
hs_token=$(grep "hs_token:" "$install_dir/config.yaml" | sed -r "s/ *hs_token: *//")
|
hs_token=$(grep "hs_token:" "$install_dir/config.yaml" | sed -r "s/ *hs_token: *//")
|
||||||
|
@ -233,10 +218,10 @@ if [ $encryption -eq 1 ]; then
|
||||||
is_encryption_enabled="true"
|
is_encryption_enabled="true"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ynh_add_config --template="../conf/config.yaml" --destination="$install_dir/config.yaml"
|
ynh_config_add --template="config.yaml" --destination="$install_dir/config.yaml"
|
||||||
|
|
||||||
chmod 400 "$install_dir/config.yaml"
|
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/config.yaml"
|
||||||
chown $app:$app "$install_dir/config.yaml"
|
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/config.yaml"
|
||||||
|
|
||||||
listrelaybot=$listrelaybot_
|
listrelaybot=$listrelaybot_
|
||||||
listuser=$listuser_
|
listuser=$listuser_
|
||||||
|
@ -254,7 +239,7 @@ set__listadmin
|
||||||
#=================================================
|
#=================================================
|
||||||
# UPGRADE MAUTRIX-BRIDGE PYTHON MODULE
|
# UPGRADE MAUTRIX-BRIDGE PYTHON MODULE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Upgrading Mautrix-Bridge Python Module..." --weight=2
|
ynh_script_progression "Upgrading Mautrix-Bridge Python Module..."
|
||||||
|
|
||||||
python3 -m venv $install_dir
|
python3 -m venv $install_dir
|
||||||
export HOME=$install_dir
|
export HOME=$install_dir
|
||||||
|
@ -264,52 +249,50 @@ $install_dir/bin/pip3 install --upgrade $install_dir/src/mautrix-telegram.tar.gz
|
||||||
#=================================================
|
#=================================================
|
||||||
# REGISTER SYNAPSE APP-SERVICE
|
# REGISTER SYNAPSE APP-SERVICE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Registering Synapse app-service" --weight=1
|
ynh_script_progression "Registering Synapse app-service"
|
||||||
|
|
||||||
$install_dir/bin/python3 -m mautrix_telegram -g -c $install_dir/config.yaml -r "/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
$install_dir/bin/python3 -m mautrix_telegram -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"
|
/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
|
# Set permissions on app files
|
||||||
chown -R $app:$app "$install_dir"
|
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "$install_dir"
|
||||||
ynh_store_file_checksum --file="/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
ynh_store_file_checksum "/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
||||||
ynh_store_file_checksum --file="$install_dir/config.yaml"
|
ynh_store_file_checksum "$install_dir/config.yaml"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP SYSTEMD
|
# SETUP SYSTEMD
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
ynh_script_progression "Upgrading systemd configuration..."
|
||||||
|
|
||||||
# Create a dedicated systemd config
|
# Create a dedicated systemd config
|
||||||
ynh_add_systemd_config
|
ynh_config_add_systemd
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# GENERIC FINALIZATION
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# SETUP LOGROTATE
|
# SETUP LOGROTATE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
|
ynh_script_progression "Upgrading logrotate configuration..."
|
||||||
|
|
||||||
# Use logrotate to manage app-specific logfile(s)
|
# Use logrotate to manage app-specific logfile(s)
|
||||||
ynh_use_logrotate --non-append --logfile "/var/log/$app/$app.log"
|
ynh_config_add_logrotate "/var/log/$app/$app.log"
|
||||||
chown -R $app:$app /var/log/$app
|
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app /var/log/$app
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# INTEGRATE SERVICE IN YUNOHOST
|
# INTEGRATE SERVICE IN YUNOHOST
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
ynh_script_progression "Integrating service in YunoHost..."
|
||||||
|
|
||||||
yunohost service add $app --description="$app daemon for bridging Telegram and Matrix messages" --log="/var/log/$app/$app.log"
|
yunohost service add $app --description="$app daemon for bridging Telegram and Matrix messages" --log="/var/log/$app/$app.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# START SYSTEMD SERVICE
|
# START SYSTEMD SERVICE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
ynh_script_progression "Starting $app's systemd service..."
|
||||||
|
|
||||||
# Start a systemd service
|
# Start a systemd service
|
||||||
ynh_systemd_action --service_name=$app --action="start"
|
ynh_systemctl --service=$app --action="start"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# END OF SCRIPT
|
# END OF SCRIPT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_script_progression --message="Upgrade of $app completed" --last
|
ynh_script_progression "Upgrade of $app completed"
|
||||||
|
|
Loading…
Reference in a new issue