yunohost-gitea_ynh/scripts/restore

82 lines
2.7 KiB
Plaintext
Raw Normal View History

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