forgejo_ynh/scripts/restore

83 lines
2.7 KiB
Text
Raw Normal View History

2023-01-05 14:48:22 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# Load common variables and helpers
source ../settings/scripts/_common.sh
# IMPORT GENERIC HELPERS
source /usr/share/yunohost/helpers
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
ynh_script_progression --message="Loading settings..."
# Retrieve old app settings
domain=$(ynh_app_setting_get --app $app --key domain)
path_url=$(ynh_app_setting_get --app $app --key path)
db_password=$(ynh_app_setting_get --app $app --key mysqlpwd)
admin=$(ynh_app_setting_get --app $app --key adminusername)
port=$(ynh_app_setting_get --app $app --key web_port)
upstream_version=$(ynh_app_setting_get $app upstream_version)
# Check user parameter
ynh_user_exists "$admin" \
|| ynh_die --message "The chosen admin user does not exist."
# Check Final Path availability
test ! -e "$final_path" || ynh_die --message "This path already contains a folder"
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# Add users
ynh_script_progression --message="Configuring system user..."
ynh_system_user_create --username=$app --home_dir=$datadir --use_shell
# Add ssh permission for forgejo user
adduser $app ssh.app
2023-01-05 14:48:22 +01:00
# Restore all files
ynh_script_progression --message="Restoring files..." --weight=10
ynh_restore
# Create and restore the database
ynh_script_progression --message="Restoring database..." --weight=3
ynh_mysql_create_db "$dbname" "$db_user" "$db_password"
ynh_mysql_connect_as "$db_user" "$db_password" "$dbname" < ./db.sql
# Restore systemd files
systemctl daemon-reload
systemctl enable "$app".service --quiet
# SETUP FAIL2BAN
ynh_script_progression --message="Configuring fail2ban..."
2023-01-06 10:12:01 +01:00
ynh_add_fail2ban_config --logpath "/var/log/$app/forgejo.log" --failregex ".*Failed authentication attempt for .* from <HOST>" --max_retry 5
2023-01-05 14:48:22 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# Set permissions
ynh_script_progression --message="Protecting directory..."
set_permission
# Configure logrotate
ynh_script_progression --message="Configuring log rotation..."
ynh_use_logrotate --logfile "/var/log/$app"
# Add gitea to YunoHost's monitored services
2023-01-06 10:12:01 +01:00
ynh_script_progression --message="Register Forgejo service..."
yunohost service add "$app" --log=/var/log/$app/forgejo.log
2023-01-05 14:48:22 +01:00
# Reload services
ynh_script_progression --message="Reloading services..."
systemctl reload nginx.service
2023-01-06 10:12:01 +01:00
ynh_systemd_action -l "Starting new Web server: tcp:127.0.0.1:" -p "/var/log/$app/forgejo.log" -t 10
2023-01-05 14:48:22 +01:00
sleep 1
ynh_script_progression --message="Restoration completed for $app" --last