yunohost-gitea_ynh/scripts/restore

78 lines
2.6 KiB
Plaintext
Raw Normal View History

2018-02-25 21:45:24 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
source /usr/share/yunohost/helpers
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
# Load common variables and helpers
source ../settings/scripts/experimental_helper.sh
source ../settings/scripts/_common.sh
# 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)
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)
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 domain/path availability with app helper
2019-08-01 14:01:59 +02:00
ynh_webpath_available $domain $path_url || ynh_die --message "$domain is not available as domain, please use an other domain."
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-02-14 09:49:57 +01:00
# We can't use the official helper (for now) because we need to set the shell for the login
test getent passwd "$app" &>/dev/null || \
useradd -d "$DATADIR" --system --user-group "$app" --shell /bin/bash || \
2019-08-01 14:01:59 +02:00
ynh_die --message "Unable to create $app system account"
2019-02-14 09:49:57 +01:00
# Should be replaced by this when getops is available in the helper ynh_system_user_create (probably in Yunohost 3.5)
# ynh_system_user_create --username= $app --home_dir=/opt/yunohost/$app --use_shell
2018-02-25 21:45:24 +01:00
# Restore all files
ynh_restore
# Create and restore the database
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
2019-02-03 15:05:38 +01:00
# SETUP 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
set_permission
# Configure logrotate
ynh_use_logrotate "/var/log/$app"
2018-06-15 22:08:34 +02:00
# Add gitea to YunoHost's monitored services
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
systemctl reload nginx.service
ynh_systemd_action -l "Serving \[::\]:$port with pid" -p "/var/log/$app/gitea.log" -t 10
2019-02-16 13:43:04 +01:00
sleep 1