1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mautrix_discord_ynh.git synced 2024-09-03 19:36:35 +02:00

[autopatch] Automatic patch attempt for helpers 2.1

This commit is contained in:
Yunohost-Bot 2024-08-31 01:04:45 +02:00 committed by Alexandre Aubin
parent c50bcdeb42
commit ae291fae1b
9 changed files with 117 additions and 169 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
*~ *~
*.sw[op] *.sw[op]
.DS_Store

View file

@ -20,7 +20,8 @@ code = "https://github.com/mautrix/discord"
fund = "https://github.com/sponsors/tulir" fund = "https://github.com/sponsors/tulir"
[integration] [integration]
yunohost = ">= 11.1.21" 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

View file

@ -2,10 +2,6 @@
APP_BIN=mautrix-discord APP_BIN=mautrix-discord
#=================================================
# PERSONAL HELPERS
#=================================================
get_synapse_db_name() { get_synapse_db_name() {
# Parameters: synapse instance identifier # Parameters: synapse instance identifier
# Returns: database name # Returns: database name
@ -21,7 +17,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} /relay:/{flag=0} flag' "$install_dir/config.yaml" | sed "/: $role/d" | sed -r 's/: (admin|user|relay)//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr ',' '\n' ) allDefinedEntries=$(awk '/permissions:/{flag=1; next} /relay:/{flag=0} flag' "$install_dir/config.yaml" | sed "/: $role/d" | sed -r 's/: (admin|user|relay)//' | 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.
@ -45,21 +41,21 @@ apply_permissions() {
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__listrelay() { set__listrelay() {
role="relay" role="relay"
ynh_app_setting_set --app=$app --key=listrelay --value="$listrelay" ynh_app_setting_set --key=listrelay --value="$listrelay"
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"
} }

View file

@ -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)."

View file

@ -1,27 +1,21 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
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
#================================================= #=================================================
# RETRIEVE ARGUMENTS # RETRIEVE ARGUMENTS
#================================================= #=================================================
install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) install_dir=$(ynh_app_setting_get --key=install_dir)
#================================================= #=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY # SPECIFIC GETTERS FOR TOML SHORT KEY
#================================================= #=================================================
get__botname() { get__botname() {
botname=$(ynh_app_setting_get --app $app --key botname) botname=$(ynh_app_setting_get --key botname)
echo "${botname}" echo "${botname}"
} }
@ -58,21 +52,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/username:.*/username: $botname/" "$install_dir/config.yaml" sed -i "s/username:.*/username: $botname/" "$install_dir/config.yaml"
"$install_dir/$APP_BIN" -g -c "$install_dir/config.yaml" -r "/etc/matrix-$synapse_instance/app-service/$app.yaml" "$install_dir/$APP_BIN" -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

View file

@ -1,19 +1,13 @@
#!/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
# Retrieve some values from selected Synapse instance and store them # Retrieve some values from selected Synapse instance and store them
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
synapse_db_name="$(get_synapse_db_name $synapse_instance)" synapse_db_name="$(get_synapse_db_name $synapse_instance)"
synapse_version=$(yunohost app info $synapse_instance | grep -oP "version:\s*\K.*") synapse_version=$(yunohost app info $synapse_instance | grep -oP "version:\s*\K.*")
@ -24,7 +18,7 @@ synapse_version=$(yunohost app info $synapse_instance | grep -oP "version:\s*\K.
# Die if Synapse is too outdated (1.22.0 is required for ephemeral_events) # Die if Synapse is too outdated (1.22.0 is required for ephemeral_events)
if dpkg --compare-versions $synapse_version lt 1.22.0; then if dpkg --compare-versions $synapse_version lt 1.22.0; then
ynh_die --message="Unsupported Synapse version. Please upgrade." ynh_die "Unsupported Synapse version. Please upgrade."
fi fi
appserviceid=$app appserviceid=$app
@ -38,53 +32,50 @@ listrelay="*"
listadmin="$botadmin" listadmin="$botadmin"
listuser="$botusers" listuser="$botusers"
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=listrelay --value=$listrelay ynh_app_setting_set --key=listrelay --value=$listrelay
ynh_app_setting_set --app=$app --key=listadmin --value=$listadmin ynh_app_setting_set --key=listadmin --value=$listadmin
ynh_app_setting_set --app=$app --key=listuser --value=$listuser ynh_app_setting_set --key=listuser --value=$listuser
#================================================= #=================================================
# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC) # APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC)
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Setting up source files..." --weight=1 ynh_script_progression "Setting up source files..."
ynh_app_setting_set --app=$app --key=listuser --value=$listuser ynh_app_setting_set --key=listuser --value=$listuser
# Download, check integrity, uncompress and patch the source from manifest.toml # Download, check integrity, uncompress and patch the source from manifest.toml
ynh_setup_source --dest_dir="$install_dir" ynh_setup_source --dest_dir="$install_dir"
chmod 750 "$install_dir/$APP_BIN" chmod 750 "$install_dir/$APP_BIN"
chown -R $app:www-data "$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:www-data "$install_dir"
#================================================= #=================================================
# SYSTEM CONFIGURATION # SYSTEM CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 ynh_script_progression "Adding system configurations related to $app..."
ynh_add_systemd_config ynh_config_add_systemd
yunohost service add $app --description="Matrix Discord pupetting bridge for YunoHost" --log="/var/log/$app/$app.log" yunohost service add $app --description="Matrix Discord pupetting bridge for YunoHost" --log="/var/log/$app/$app.log"
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate --logfile "/var/log/$app/$app.log" --nonappend --specific_user $app/$app ynh_config_add_logrotate "/var/log/$app/$app.log" $app/$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
#================================================= #=================================================
# APP INITIAL CONFIGURATION # APP INITIAL CONFIGURATION
#================================================= #=================================================
# ADD A CONFIGURATION # ADD A CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1 ynh_script_progression "Adding $app's configuration..."
ynh_config_add --template="config.yaml" --destination="$install_dir/config.yaml"
ynh_add_config --template="config.yaml" --destination="$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"
#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"
chmod 400 "$install_dir/config.yaml"
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__listuser set__listuser
@ -92,20 +83,18 @@ set__listrelay
set__listadmin set__listadmin
$install_dir/$APP_BIN -g -c $install_dir/config.yaml -r /etc/matrix-$synapse_instance/app-service/$app.yaml $install_dir/$APP_BIN -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"
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" ynh_systemctl --service=$app --action="start"
# Wait until the synapse user is created # Wait until the synapse user is created
sleep 30 sleep 30
@ -113,12 +102,12 @@ sleep 30
# (Note that, by default, non-admins might not have your homeserver's permission to create Spaces.) # (Note that, by default, non-admins might not have your homeserver's permission to create Spaces.)
if [ "$bot_synapse_adm" = true ] if [ "$bot_synapse_adm" = true ]
then then
ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = ""$botname"";" ynh_psql_db_shell $synapse_db_name <<< "UPDATE users SET admin = 1 WHERE name = ""$botname"";"
fi fi
ynh_systemd_action --service_name=$app --action="restart" ynh_systemctl --service=$app --action="restart"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Installation of $app completed" --last ynh_script_progression "Installation of $app completed"

View file

@ -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
@ -14,25 +8,24 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# REMOVE SYSTEMD SERVICE # REMOVE SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 ynh_script_progression "Removing system configurations related to $app..."
# 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=1 ynh_script_progression "Removing $app service integration..."
yunohost service remove $app yunohost service remove $app
fi fi
ynh_remove_systemd_config ynh_config_remove_systemd
ynh_remove_logrotate ynh_config_remove_logrotate
ynh_secure_remove --file="/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"
ynh_safe_rm "/etc/matrix-$synapse_instance/app-service/$app.yaml"
/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die "Synapse can't restart with the appservice configuration"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Removal of $app completed" --last ynh_script_progression "Removal of $app completed"

View file

@ -1,90 +1,81 @@
#!/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
server_name=$(ynh_app_setting_get --app=$app --key=server_name) server_name=$(ynh_app_setting_get --key=server_name)
synapse_db_name="$(get_synapse_db_name $synapse_instance)" synapse_db_name="$(get_synapse_db_name $synapse_instance)"
bot_synapse_db_user="@$botname:$server_name" bot_synapse_db_user="@$botname:$server_name"
async_media=$(ynh_app_setting_get --app=$app --key=async_media) async_media=$(ynh_app_setting_get --key=async_media)
#================================================= #=================================================
# 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"
chown -R $app:www-data "$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:www-data "$install_dir"
chmod 750 "$install_dir/$APP_BIN" chmod 750 "$install_dir/$APP_BIN"
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"
#================================================= #=================================================
# 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""
#================================================= #=================================================
# 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/$APP_BIN -g -c $install_dir/config.yaml -r /etc/matrix-$synapse_instance/app-service/$app.yaml $install_dir/$APP_BIN -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 "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"
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"
#================================================= #=================================================
# RESTORE SYSTEM CONFIGURATIONS # RESTORE SYSTEM CONFIGURATIONS
#================================================= #=================================================
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=3 ynh_script_progression "Restoring system configurations related to $app..."
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
ynh_restore_file --origin_path="/etc/logrotate.d/$app" ynh_restore "/etc/logrotate.d/$app"
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
mkdir --parents "/var/log/$app" mkdir --parents "/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
yunohost service add $app --description="Matrix Discord pupetting bridge for YunoHost" --log="/var/log/$app/$app.log" yunohost service add $app --description="Matrix Discord pupetting bridge for YunoHost" --log="/var/log/$app/$app.log"
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#================================================= #=================================================
ynh_script_progression --message="Reloading $app's service..." --weight=1 ynh_script_progression "Reloading $app's service..."
ynh_systemctl --service=$app --action="start"
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
# Wait until the synapse user is created # Wait until the synapse user is created
sleep 30 sleep 30
# (Note that, by default, non-admins might not have your homeserver's permission to create communities.) # (Note that, by default, non-admins might not have your homeserver's permission to create communities.)
if [ "$bot_synapse_adm" = true ] if [ "$bot_synapse_adm" = true ]
then then
ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = ""$botname"";" ynh_psql_db_shell $synapse_db_name <<< "UPDATE users SET admin = 1 WHERE name = ""$botname"";"
fi fi
ynh_systemd_action --service_name=$app --action="restart" ynh_systemctl --service=$app --action="restart"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Restoration completed for $app" --last ynh_script_progression "Restoration completed for $app"

View file

@ -1,34 +1,26 @@
#!/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="$(get_synapse_db_name $synapse_instance)" synapse_db_name="$(get_synapse_db_name $synapse_instance)"
bot_synapse_db_user="@$botname:$server_name" bot_synapse_db_user="@$botname:$server_name"
appserviceid=$app appserviceid=$app
async_media=$(ynh_app_setting_get --app=$app --key=async_media) async_media=$(ynh_app_setting_get --key=async_media)
listrelay=$(ynh_app_setting_get --app=$app --key=listrelay) listrelay=$(ynh_app_setting_get --key=listrelay)
listuser=$(ynh_app_setting_get --app=$app --key=listuser) listuser=$(ynh_app_setting_get --key=listuser)
listadmin=$(ynh_app_setting_get --app=$app --key=listadmin) listadmin=$(ynh_app_setting_get --key=listadmin)
upgrade_type=$(ynh_check_app_version_changed)
#================================================= #=================================================
# 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"
#================================================= #=================================================
# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...) # "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...)
@ -36,38 +28,38 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app
# 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 manifest.toml # Download, check integrity, uncompress and patch the source from manifest.toml
ynh_setup_source --dest_dir="$install_dir" ynh_setup_source --dest_dir="$install_dir"
fi fi
chmod 750 "$install_dir/$APP_BIN" chmod 750 "$install_dir/$APP_BIN"
chown -R $app:www-data "$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:www-data "$install_dir"
#================================================= #=================================================
# REAPPLY SYSTEM CONFIGURATIONS # REAPPLY SYSTEM CONFIGURATIONS
#================================================= #=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 ynh_script_progression "Upgrading system configurations related to $app..."
ynh_add_systemd_config ynh_config_add_systemd
yunohost service add $app --description="Matrix Discord pupetting bridge for YunoHost" --log="/var/log/$app/$app.log" yunohost service add $app --description="Matrix Discord pupetting bridge for YunoHost" --log="/var/log/$app/$app.log"
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate --logfile "/var/log/$app/$app.log" --nonappend --specific_user $app/$app ynh_config_add_logrotate "/var/log/$app/$app.log" $app/$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
#================================================= #=================================================
# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...) # RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...)
#================================================= #=================================================
# UPDATE A CONFIG FILE # UPDATE A CONFIG FILE
#================================================= #=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1 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
listrelay_=$listrelay listrelay_=$listrelay
@ -77,10 +69,10 @@ listrelay="*"
listuser="@user:domain.tld" listuser="@user:domain.tld"
listadmin="@admin:domain.tld" listadmin="@admin:domain.tld"
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"
listrelay=$listrelay_ listrelay=$listrelay_
listuser=$listuser_ listuser=$listuser_
@ -94,25 +86,25 @@ set__listadmin
#================================================= #=================================================
# 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/$APP_BIN -g -c $install_dir/config.yaml -r /etc/matrix-$synapse_instance/app-service/$app.yaml $install_dir/$APP_BIN -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 "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"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression "Starting $app's 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="Upgrade of $app completed" --last ynh_script_progression "Upgrade of $app completed"