mirror of
https://framagit.org/YunoHost-Apps/gitea_ynh.git
synced 2024-11-23 11:31:35 +01:00
85 lines
2.9 KiB
Bash
85 lines
2.9 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
|
|
# Load common variables and helpers
|
|
source ../settings/scripts/experimental_helper.sh
|
|
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)
|
|
dbpass=$(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 domain/path availability with app helper
|
|
ynh_webpath_available --domain $domain --path_url $path_url || ynh_die --message "$domain is not available as domain, please use an other domain."
|
|
|
|
# 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=/home/$app --use_shell
|
|
|
|
# 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" "$dbuser" "$dbpass"
|
|
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./db.sql
|
|
|
|
# Restore systemd files
|
|
systemctl daemon-reload
|
|
systemctl enable "$app".service --quiet
|
|
|
|
# SETUP FAIL2BAN
|
|
ynh_script_progression --message="Configuring fail2ban..."
|
|
ynh_add_fail2ban_config --logpath "/var/log/$app/gitea.log" --failregex ".*Failed authentication attempt for .* from <HOST>" --max_retry 5
|
|
|
|
#=================================================
|
|
# 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
|
|
ynh_script_progression --message="Register gitea service..."
|
|
yunohost service add "$app" --log /var/log/"$app"/gitea.log
|
|
|
|
# Reload services
|
|
ynh_script_progression --message="Reloading services..."
|
|
systemctl reload nginx.service
|
|
ynh_systemd_action -l "Starting new server: tcp:127.0.0.1:" -p "/var/log/$app/gitea.log" -t 10
|
|
sleep 1
|
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|