1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/forgejo_ynh.git synced 2024-09-03 18:36:26 +02:00
This commit is contained in:
Éric Gaspar 2024-09-01 21:40:08 +02:00
parent 8573359c39
commit ef480e3c13
4 changed files with 26 additions and 106 deletions

View file

@ -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 <HOST>"
#=================================================
# 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 <HOST>" --max_retry 5
#=================================================
# LDAP CONFIGURATION
#=================================================

View file

@ -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
#=================================================

View file

@ -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
#=================================================

View file

@ -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 <HOST>"
#=================================================
# 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 <HOST>" --max_retry 5
#=================================================
# END OF SCRIPT
#=================================================