From a96678e79dc91d9e77f0ff120d43a9b1ebad3bfa Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 4 Sep 2022 23:58:34 +0200 Subject: [PATCH] More example_ynh --- .github/workflows/updater.sh | 2 +- doc/.gitkeep | 0 doc/screenshots/.gitkeep | 0 scripts/backup | 2 +- scripts/install | 12 +++++------- scripts/remove | 5 +---- scripts/restore | 19 ++++++++++--------- scripts/upgrade | 18 +++++++++++------- 8 files changed, 29 insertions(+), 29 deletions(-) delete mode 100644 doc/.gitkeep delete mode 100644 doc/screenshots/.gitkeep diff --git a/.github/workflows/updater.sh b/.github/workflows/updater.sh index 3bcfb57..54fddd7 100644 --- a/.github/workflows/updater.sh +++ b/.github/workflows/updater.sh @@ -18,7 +18,7 @@ current_version=$(cat manifest.json | jq -j '.version|split("~")[0]') repo=$(cat manifest.json | jq -j '.upstream.code|split("https://github.com/")[1]') # Some jq magic is needed, because the latest upstream release is not always the latest version (e.g. security patches for older versions) version=$(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '.[] | select( .prerelease != true ) | .tag_name' | sort -V | tail -1) -assets="https://github.com/mautrix/facebook/archive/$version.tar.gz" +assets="https://github.com/$repo/archive/$version.tar.gz" # Later down the script, we assume the version has only digits and dots # Sometimes the release name starts with a "v", so let's filter it out. diff --git a/doc/.gitkeep b/doc/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/doc/screenshots/.gitkeep b/doc/screenshots/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/scripts/backup b/scripts/backup index dddb0c8..917677c 100755 --- a/scripts/backup +++ b/scripts/backup @@ -47,7 +47,7 @@ ynh_backup --src_path="$final_path" # BACKUP LOGROTATE #================================================= -ynh_backup --src_path="/var/log/$app" +ynh_backup --src_path="/etc/logrotate.d/$app" #================================================= # BACKUP SYSTEMD diff --git a/scripts/install b/scripts/install index e1dee4b..a6a5d84 100755 --- a/scripts/install +++ b/scripts/install @@ -81,7 +81,7 @@ ynh_app_setting_set --app=$app --key=port --value=$port #================================================= ynh_script_progression --message="Installing dependencies..." --weight=97 -ynh_install_app_dependencies $pkg_dependencies +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER @@ -131,7 +131,7 @@ chown $app:$app "$final_path/config.yaml" #================================================= # INSTALL MAUTRIX-BRIDGE PYTHON MODULE #================================================= -ynh_script_progression --message="Installing Mautrix-Bridge Python Module..." --weight=1 +ynh_script_progression --message="Installing Mautrix-Bridge Python Module..." --weight=6 mkdir -p /var/log/$app # Configure Mautrix-Bridge @@ -146,9 +146,7 @@ $final_path/bin/pip3 install --upgrade $final_path/src/mautrix-facebook.tar.gz ynh_script_progression --message="Registering Synapse app-service" --weight=1 $final_path/bin/python3 -m mautrix_facebook -g -c $final_path/config.yaml -r $synapse_registration_path/$app.yaml - -/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die "Synapse can't restart with the appservice configuration" -# Handled by synapse: synapse_ynh adds all registration files added in $synapse_registration_path to the app_service_config_files list +/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die --message="Synapse can't restart with the appservice configuration" chown -R $app:$app "$final_path" ynh_store_file_checksum --file="$synapse_registration_path/$app.yaml" @@ -171,7 +169,7 @@ ynh_script_progression --message="Configuring log rotation..." --weight=3 # Use logrotate to manage application logfile(s) ynh_use_logrotate --logfile "/var/log/$app/$app.log" -chown $app:$app -R /var/log/$app +chown -R $app:$app /var/log/$app #================================================= # INTEGRATE SERVICE IN YUNOHOST @@ -186,7 +184,7 @@ yunohost service add $app --description="$app daemon for bridging FB and Matrix ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$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 sleep 30 # # (Note that, by default, non-admins might not have your homeserver's permission to create communities.) diff --git a/scripts/remove b/scripts/remove index 328f661..402e60e 100755 --- a/scripts/remove +++ b/scripts/remove @@ -17,11 +17,8 @@ ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME botname=$(ynh_app_setting_get --app=$app --key=botname) -botadmin=$(ynh_app_setting_get --app=$app --key=botadmin) -botusers=$(ynh_app_setting_get --app=$app --key=botusers) synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance) server_name=$(ynh_app_setting_get --app=$app --key=server_name) -domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name final_path=$(ynh_app_setting_get --app=$app --key=final_path) @@ -89,7 +86,7 @@ ynh_script_progression --message="Removing various files..." --weight=6 # Remove a directory securely ynh_secure_remove --file="$synapse_registration_path/$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 --message="Synapse can't restart with the appservice configuration" # Remove the log files ynh_secure_remove --file="/var/log/$app" diff --git a/scripts/restore b/scripts/restore index a50f922..c873713 100755 --- a/scripts/restore +++ b/scripts/restore @@ -73,7 +73,7 @@ chown -R $app:$app "$final_path" ynh_script_progression --message="Reinstalling dependencies..." --weight=1 # Define and install dependencies -ynh_install_app_dependencies $pkg_dependencies +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies #================================================= # RESTORE THE POSTGRESQL DATABASE @@ -88,17 +88,19 @@ ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name #================================================= # INSTALL MAUTRIX-BRIDGE PYTHON MODULE #================================================= -ynh_script_progression --message="Installing Mautrix-Bridge Python Module..." --weight=1 - -ynh_restore_file --origin_path="/var/log/$app" +ynh_script_progression --message="Installing Mautrix-Bridge Python Module..." --weight=6 python3 -m venv $final_path export HOME=$final_path $final_path/bin/pip3 install --upgrade pip setuptools wheel -$final_path/bin/python3 -m mautrix_facebook -g -c $final_path/config.yaml -r $synapse_registration_path/$app.yaml +#================================================= +# REGISTER SYNAPSE APP-SERVICE +#================================================= +ynh_script_progression --message="Registering Synapse app-service" --weight=1 + +$final_path/bin/python3 -m mautrix_facebook -g -c $final_path/config.yaml -r $synapse_registration_path/$app.yaml /opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die "Synapse can't restart with the appservice configuration" -# Handled by synapse: synapse_ynh adds all registration files added in $synapse_registration_path to the app_service_config_files list #================================================= # RESTORE SYSTEMD @@ -113,8 +115,7 @@ systemctl enable $app.service --quiet #================================================= ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1 -ynh_use_logrotate --logfile "/var/log/$app/$app.log" -chown $app:$app -R /var/log/$app +ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # INTEGRATE SERVICE IN YUNOHOST @@ -129,7 +130,7 @@ yunohost service add $app --description="$app daemon for bridging FB and Matrix ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$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 sleep 30 # # (Note that, by default, non-admins might not have your homeserver's permission to create communities.) diff --git a/scripts/upgrade b/scripts/upgrade index 4a8de92..bf4dc9f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -41,7 +41,7 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=5 # Backup the current version of the app ynh_backup_before_upgrade @@ -95,7 +95,7 @@ chown -R $app:$app "$final_path" #================================================= ynh_script_progression --message="Upgrading dependencies..." --weight=1 -ynh_install_app_dependencies $pkg_dependencies +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies #================================================= # SPECIFIC UPGRADE @@ -112,21 +112,25 @@ chown $app:$app "$final_path/config.yaml" #================================================= # UPGRADE MAUTRIX-BRIDGE PYTHON MODULE #================================================= -ynh_script_progression --message="Upgrading Mautrix-Bridge..." --weight=2 +ynh_script_progression --message="Upgrading Mautrix-Bridge Python Module..." --weight=2 -mkdir -p /var/log/$app -# Configure Mautrix-Bridge python3 -m venv $final_path export HOME=$final_path $final_path/bin/pip3 install --upgrade pip setuptools wheel $final_path/bin/pip3 install --upgrade $final_path/src/mautrix-facebook.tar.gz -$final_path/bin/python3 -m mautrix_facebook -g -c $final_path/config.yaml -r $synapse_registration_path/$app.yaml +#================================================= +# REGISTER SYNAPSE APP-SERVICE +#================================================= +ynh_script_progression --message="Registering Synapse app-service" --weight=1 + +$final_path/bin/python3 -m mautrix_facebook -g -c $final_path/config.yaml -r $synapse_registration_path/$app.yaml /opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die "Synapse can't restart with the appservice configuration" -# Handled by synapse: synapse_ynh adds all registration files added in $synapse_registration_path to the app_service_config_files list # Set permissions on app files chown -R $app:$app "$final_path" +ynh_store_file_checksum --file="$synapse_registration_path/$app.yaml" +ynh_store_file_checksum --file="$final_path/config.yaml" #================================================= # SETUP SYSTEMD