From ef480e3c1365fdd5abd4da110a60661cc332a193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Sun, 1 Sep 2024 21:40:08 +0200 Subject: [PATCH] cleaning --- scripts/install | 43 ++++++++++--------------------------------- scripts/remove | 14 ++------------ scripts/restore | 49 ++++++++++++------------------------------------- scripts/upgrade | 26 ++------------------------ 4 files changed, 26 insertions(+), 106 deletions(-) diff --git a/scripts/install b/scripts/install index 721e1ec..8ee2665 100644 --- a/scripts/install +++ b/scripts/install @@ -1,18 +1,16 @@ #!/bin/bash #================================================= -# GENERIC START +# IMPORT GENERIC HELPERS #================================================= -# Load common variables and helpers -source ./_common.sh - -# IMPORT GENERIC HELPERS +source _common.sh source /usr/share/yunohost/helpers #================================================= -# Create install and data subdirs +# DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression "Setting up source files..." ynh_setup_source --dest_dir="$install_dir" @@ -38,9 +36,9 @@ ynh_app_setting_set --key=internal_token --value="$internal_token" ynh_app_setting_set --key=oauth2_jwt_secret --value="$oauth2_jwt_secret" #================================================= -# ADD A CONFIGURATION +# APP INITIAL CONFIGURATION #================================================= -ynh_script_progression "Adding $app's configuration..." +ynh_script_progression "Adding $app's configuration files..." ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+") ynh_config_add --template="app.ini" --destination="$install_dir/custom/conf/app.ini" @@ -49,34 +47,20 @@ chmod 640 "$install_dir/custom/conf/app.ini" chown "$app:$app" "$install_dir/custom/conf/app.ini" #================================================= -# SETUP SYSTEMD +# SYSTEM CONFIGURATION #================================================= -ynh_script_progression "Upgrading systemd configuration..." +ynh_script_progression "Adding system configurations related to $app..." ynh_config_add_systemd -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression "Upgrading NGINX web server configuration..." - ynh_config_add_nginx -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression "Configuring log rotation..." - -# Use logrotate to manage application logfile(s) ynh_config_add_logrotate "/var/log/$app" -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression "Integrating service in YunoHost..." - yunohost service add "$app" --description="Forgejo" --log="/var/log/$app/forgejo.log" +ynh_config_add_fail2ban --logpath "/var/log/$app/forgejo.log" --failregex ".*Failed authentication attempt for .* from " + #================================================= # START SYSTEMD SERVICE #================================================= @@ -85,13 +69,6 @@ ynh_script_progression "Starting $app's systemd service..." # Start a systemd service ynh_systemctl --service="$app" --action="start" --log_path="/var/log/$app/forgejo.log" --wait_until="Starting new Web server: tcp:127.0.0.1:" -#================================================= -# SETUP FAIL2BAN -#================================================= -ynh_script_progression "Configuring Fail2Ban..." - -ynh_config_add_fail2ban --logpath "/var/log/$app/forgejo.log" --failregex ".*Failed authentication attempt for .* from " --max_retry 5 - #================================================= # LDAP CONFIGURATION #================================================= diff --git a/scripts/remove b/scripts/remove index b446f0b..d6e975d 100644 --- a/scripts/remove +++ b/scripts/remove @@ -4,32 +4,22 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# STANDARD REMOVE -#================================================= -# REMOVE SERVICE INTEGRATION IN YUNOHOST +# REMOVE SYSTEM CONFIGURATIONS #================================================= +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`) if ynh_hide_warnings yunohost service status "$app" >/dev/null then ynh_script_progression "Removing $app service integration..." yunohost service remove "$app" fi -# Remove the dedicated systemd config -ynh_script_progression "Removing systemd configuration..." ynh_config_remove_systemd -# Remove the app-specific logrotate config -ynh_script_progression "Removing logrotate configuration..." ynh_config_remove_logrotate -# Remove the dedicated NGINX config -ynh_script_progression "Removing NGINX web server configuration..." ynh_config_remove_nginx -# Remove the dedicated Fail2Ban config -ynh_script_progression "Removing Fail2Ban configuration..." ynh_config_remove_fail2ban #================================================= diff --git a/scripts/restore b/scripts/restore index c67ac58..fcf3c29 100644 --- a/scripts/restore +++ b/scripts/restore @@ -3,15 +3,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression "Restoring the NGINX configuration..." - -ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" - #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -23,18 +14,11 @@ ynh_restore "$install_dir" # RESTORE THE DATA DIRECTORY #================================================= ynh_script_progression "Restoring the data directory..." + ynh_restore "$data_dir" + chown -R "$app:$app" "$data_dir" -#================================================= -# RESTORE FAIL2BAN CONFIGURATION -#================================================= -ynh_script_progression "Restoring the Fail2Ban configuration..." - -ynh_restore "/etc/fail2ban/jail.d/$app.conf" -ynh_restore "/etc/fail2ban/filter.d/$app.conf" -ynh_systemctl --action=restart --service=fail2ban - #================================================= # RESTORE THE DATABASE #================================================= @@ -43,39 +27,30 @@ ynh_script_progression "Restoring the database..." ynh_psql_db_shell < "./db.sql" #================================================= -# RESTORE SYSTEMD +# RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression "Restoring $app's systemd service..." +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 + +ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore "/etc/systemd/system/$app.service" systemctl enable "$app.service" --quiet -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression "Restoring the logrotate configuration..." - ynh_restore "/etc/logrotate.d/$app" -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression "Integrating service in YunoHost..." - yunohost service add "$app" --description="Forgejo" --log="/var/log/$app/forgejo.log" +ynh_restore "/etc/fail2ban/jail.d/$app.conf" +ynh_restore "/etc/fail2ban/filter.d/$app.conf" +ynh_systemctl --action=restart --service=fail2ban + #================================================= -# START SYSTEMD SERVICE +# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= -ynh_script_progression "Starting $app's systemd service..." +ynh_script_progression "Reloading NGINX web server and $app's service..." ynh_systemctl --service="$app" --action="start" --log_path="/var/log/$app/forgejo.log" --wait_until="Starting new Web server: tcp:127.0.0.1:" -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression "Reloading NGINX web server..." - ynh_systemctl --service=nginx --action=reload #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index e1a04d1..48c9b8e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -83,34 +83,19 @@ ynh_script_progression "Upgrading systemd configuration..." ynh_config_add_systemd -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression "Upgrading NGINX web server configuration..." - ynh_config_add_nginx -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression "Configuring log rotation..." - -# Use logrotate to manage application logfile(s) ynh_config_add_logrotate "/var/log/$app" -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression "Integrating service in YunoHost..." - yunohost service add "$app" --description="Forgejo" --log="/var/log/$app/forgejo.log" +ynh_config_add_fail2ban --logpath "/var/log/$app/forgejo.log" --failregex ".*Failed authentication attempt for .* from " + #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression "Starting $app's systemd service..." -# Start a systemd service ynh_systemctl --service="$app" --action="start" --log_path="/var/log/$app/forgejo.log" --wait_until="Starting new Web server: tcp:127.0.0.1:" #================================================= @@ -124,13 +109,6 @@ set_users_login_source synchronize_users -#================================================= -# SETUP FAIL2BAN -#================================================= -ynh_script_progression "Configuring Fail2Ban..." - -ynh_config_add_fail2ban --logpath "/var/log/$app/forgejo.log" --failregex ".*Failed authentication attempt for .* from " --max_retry 5 - #================================================= # END OF SCRIPT #=================================================