From ae68974bf8f90d0cb337f5dcb2855587dbf7dc0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Tue, 24 Oct 2023 08:34:51 +0200 Subject: [PATCH] fix --- scripts/upgrade | 212 ++++++------------------------------------------ 1 file changed, 23 insertions(+), 189 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 7976573..e7bafb2 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -29,166 +29,22 @@ ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$a #================================================= ynh_script_progression --message="Ensuring downward compatibility..." -# Upgrade from <0.2.1~ynh4: -if ynh_compare_current_package_version --comparison lt --version 0.2.1~ynh4 || [ -z "$db_user" ] -then - # import old parameters -#REMOVEME? registration_open=$(ynh_app_setting_get --app="$app" --key=registration_open) -#REMOVEME? registration_approval=$(ynh_app_setting_get --app="$app" --key=registration_approval) -#REMOVEME? registration_reason=$(ynh_app_setting_get --app="$app" --key=registration_reason) - # declaration of new parameters - client_max_body_size="100M" - media_image_max_size="2097152" - media_video_max_size="10485760" - media_description_min_chars="0" - media_description_max_chars="500" - media_remote_cache_days="30" - statuses_max_chars="5000" - statuses_cw_max_chars="100" - statuses_poll_max_options="6" - statuses_poll_option_max_chars="50" - statuses_media_max_files="6" - # conversion of old parameters - registration_open=$(convert_bool "$registration_open") - registration_approval=$(convert_bool "$registration_approval") - registration_reason=$(convert_bool "$registration_reason") - # fix db_user existence - db_user=$db_name -#REMOVEME? ynh_app_setting_set --app="$app" --key=db_user --value="$db_user" - # registration of new parameters - ynh_app_setting_set --app="$app" --key=client_max_body_size --value="$client_max_body_size" - ynh_app_setting_set --app="$app" --key=media_image_max_size --value="$media_image_max_size" - ynh_app_setting_set --app="$app" --key=media_video_max_size --value="$media_video_max_size" - ynh_app_setting_set --app="$app" --key=media_description_min_chars --value="$media_description_min_chars" - ynh_app_setting_set --app="$app" --key=media_description_max_chars --value="$media_description_max_chars" - ynh_app_setting_set --app="$app" --key=media_remote_cache_days --value="$media_remote_cache_days" - ynh_app_setting_set --app="$app" --key=statuses_max_chars --value="$statuses_max_chars" - ynh_app_setting_set --app="$app" --key=statuses_cw_max_chars --value="$statuses_cw_max_chars" - ynh_app_setting_set --app="$app" --key=statuses_poll_max_options --value="$statuses_poll_max_options" - ynh_app_setting_set --app="$app" --key=statuses_poll_option_max_chars --value="$statuses_poll_option_max_chars" - ynh_app_setting_set --app="$app" --key=statuses_media_max_files --value="$statuses_media_max_files" - # registration of converted parameters - ynh_app_setting_set --app="$app" --key=registration_open --value="$registration_open" - ynh_app_setting_set --app="$app" --key=registration_approval --value="$registration_approval" - ynh_app_setting_set --app="$app" --key=registration_reason --value="$registration_reason" +# If accounts_registration_open doesn't exist, create it +if [ -z "${accounts_registration_open:-}" ]; then + accounts_registration_open="false" + ynh_app_setting_set --app=$app --key=accounts_registration_open --value=$accounts_registration_open fi -# Upgrade from <0.3.7~ynh1: -if ynh_compare_current_package_version --comparison lt --version 0.3.7~ynh1 || [ -z "$instance_expose_peers" ] -then - # import old parameters -#REMOVEME? registration_open=$(ynh_app_setting_get --app="$app" --key=registration_open) -#REMOVEME? registration_approval=$(ynh_app_setting_get --app="$app" --key=registration_approval) -#REMOVEME? registration_reason=$(ynh_app_setting_get --app="$app" --key=registration_reason) - # declaration of new parameters - instance_expose_peers="false" - instance_expose_suspended="false" - # conversion of old parameters - if [ "$registration_open" = "true" ] || [ "$registration_open" = "false" ]; then - accounts_registration_open=$registration_open - accounts_approval_required=$registration_approval - accounts_reason_required=$registration_reason - else - accounts_registration_open="false" - accounts_approval_required="true" - accounts_reason_required="false" - fi - # registration of new parameters - ynh_app_setting_set --app="$app" --key=instance_expose_peers --value="$instance_expose_peers" - ynh_app_setting_set --app="$app" --key=instance_expose_suspended --value="$instance_expose_suspended" - # registration of converted parameters - ynh_app_setting_set --app="$app" --key=accounts_registration_open --value="$accounts_registration_open" - ynh_app_setting_set --app="$app" --key=accounts_approval_required --value="$accounts_approval_required" - ynh_app_setting_set --app="$app" --key=accounts_reason_required --value="$accounts_reason_required" - # deletion of old parameters - ynh_app_setting_delete --app="$app" --key=registration_open - ynh_app_setting_delete --app="$app" --key=registration_approval - ynh_app_setting_delete --app="$app" --key=registration_reason +# If accounts_approval_required doesn't exist, create it +if [ -z "${accounts_approval_required:-}" ]; then + accounts_approval_required="true" + ynh_app_setting_set --app=$app --key=accounts_approval_required --value=$accounts_approval_required fi -# Upgrade from <0.5.0~ynh1: -if ynh_compare_current_package_version --comparison lt --version 0.5.0~ynh1 || [ -z "$accounts_allow_custom_css" ] -then - # declaration of new parameters - accounts_allow_custom_css="false" - instance_deliver_to_shared_inboxes="true" - media_emoji_local_max_size="51200" - media_emoji_remote_max_size="102400" - # registration of new parameters - ynh_app_setting_set --app="$app" --key=accounts_allow_custom_css --value="$accounts_allow_custom_css" - ynh_app_setting_set --app="$app" --key=instance_deliver_to_shared_inboxes --value="$instance_deliver_to_shared_inboxes" - ynh_app_setting_set --app="$app" --key=media_emoji_local_max_size --value="$media_emoji_local_max_size" - ynh_app_setting_set --app="$app" --key=media_emoji_remote_max_size --value="$media_emoji_remote_max_size" -fi - -# Upgrade from <0.7.1~ynh1: -if ynh_compare_current_package_version --comparison lt --version 0.7.1~ynh1 || [ -z "$instance_expose_suspended_web" ] -then - # updating parameters - advanced_rate_limit_requests="300" - # declaration of new parameter - instance_expose_suspended_web="false" - # registration of parameters - ynh_app_setting_set --app="$app" --key=advanced_rate_limit_requests --value="$advanced_rate_limit_requests" - ynh_app_setting_set --app="$app" --key=instance_expose_suspended_web --value="$instance_expose_suspended_web" -fi - -# Upgrade from <0.8.0~ynh3: -if ynh_compare_current_package_version --comparison lt --version 0.8.0~ynh3 -then - # get settings from problem key -#REMOVEME? allow_custom_css=$(ynh_app_setting_get --app="$app" --key=allow_custom_css) -#REMOVEME? approval_required=$(ynh_app_setting_get --app="$app" --key=approval_required) -#REMOVEME? reason_required=$(ynh_app_setting_get --app="$app" --key=reason_required) -#REMOVEME? registration_open=$(ynh_app_setting_get --app="$app" --key=registration_open) - # apply setting to correct key if set on old key - if [ -n "$allow_custom_css" ] - then - ynh_app_setting_set --app="$app" --key=accounts_allow_custom_css --value="$allow_custom_css" - ynh_app_setting_delete --app="$app" --key=allow_custom_css - fi - if [ -n "$approval_required" ] - then - ynh_app_setting_set --app="$app" --key=accounts_approval_required --value="$approval_required" - ynh_app_setting_delete --app="$app" --key=approval_required - fi - if [ -n "$reason_required" ] - then - ynh_app_setting_set --app="$app" --key=accounts_reason_required --value="$reason_required" - ynh_app_setting_delete --app="$app" --key=reason_required - fi - if [ -n "$registration_open" ] - then - ynh_app_setting_set --app="$app" --key=accounts_registration_open --value="$registration_open" - ynh_app_setting_delete --app="$app" --key=registration_open - fi -fi - -# Upgrade from <0.10.0~ynh1: -if ynh_compare_current_package_version --comparison lt --version 0.10.0~ynh1 || [ -z "$accounts_custom_css_length" ] -then - # declaration of new parameter - accounts_custom_css_length="10000" - # registration of parameter - ynh_app_setting_set --app="$app" --key=accounts_custom_css_length --value="$accounts_custom_css_length" -fi - -# Upgrade from <0.11.0~ynh1: -if ynh_compare_current_package_version --comparison lt --version 0.11.0~ynh1 || [ -z "$cache_memory_target" ] -then - # declaration of new parameter - cache_memory_target="100MiB" - instance_inject_mastodon_version="false" - # update default config - if [ "$media_remote_cache_days" == "30" ]; then - # "30" is the old default value, "7" the new one - # updating to the new default only if the old default value is used (to not overwrite an user modified value) - media_remote_cache_days="7" - ynh_app_setting_set --app="$app" --key=media_remote_cache_days --value="$media_remote_cache_days" - fi - # registration of parameter - ynh_app_setting_set --app="$app" --key=cache_memory_target --value="$cache_memory_target" - ynh_app_setting_set --app="$app" --key=instance_inject_mastodon_version --value="$instance_inject_mastodon_version" +# If accounts_reason_required doesn't exist, create it +if [ -z "${accounts_reason_required:-}" ]; then + accounts_reason_required="true" + ynh_app_setting_set --app=$app --key=accounts_reason_required --value=$accounts_reason_required fi #================================================= @@ -214,6 +70,17 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." # Create a dedicated NGINX config for the main domain ynh_add_nginx_config +# Create a dedicated systemd config +ynh_add_systemd_config + +# Use logrotate to manage app-specific logfile(s) +ynh_use_logrotate --non-append + +# Create a dedicated Fail2Ban config +ynh_add_fail2ban_config --logpath="/var/log/${app}/${app}.log" --failregex="statusCode=401 path=/auth/sign_in clientIP= .* msg=\"Unauthorized:" --max_retry=5 + +yunohost service add "$app" --description="Gotosocial server" --log="/var/log/$app/$app.log" + #================================================= # UPDATE A CONFIG FILE #================================================= @@ -224,39 +91,6 @@ ynh_add_config --template="config.yaml" --destination="$install_dir/config.yaml" chmod 400 "$install_dir/config.yaml" chown "$app:$app" "$install_dir/config.yaml" -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Upgrading systemd configuration..." - -# Create a dedicated systemd config -ynh_add_systemd_config - -#================================================= -# GENERIC FINALIZATION -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." - -# Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --non-append - -#================================================= -# SETUP FAIL2BAN -#================================================= -ynh_script_progression --message="Upgrading fail2ban configuration..." - -# Create a dedicated Fail2Ban config -ynh_add_fail2ban_config --logpath="/var/log/${app}/${app}.log" --failregex="statusCode=401 path=/auth/sign_in clientIP= .* msg=\"Unauthorized:" --max_retry=5 - -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." - -yunohost service add "$app" --description="Gotosocial server" --log="/var/log/$app/$app.log" - #================================================= # START SYSTEMD SERVICE #=================================================