1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/forgejo_ynh.git synced 2024-09-03 18:36:26 +02:00
forgejo_ynh/scripts/restore

158 lines
5.7 KiB
Text
Raw Normal View History

2023-01-05 14:48:22 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2023-01-05 14:48:22 +01:00
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
2023-01-05 14:48:22 +01:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
2023-01-05 14:48:22 +01:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
admin=$(ynh_app_setting_get --app=$app --key=admin)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
2023-01-05 14:48:22 +01:00
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_script_progression --message="Validating restoration parameters..." --weight=2
2023-01-05 14:48:22 +01:00
test ! -d $final_path \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..." --weight=6
# Define and install dependencies
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
2023-01-05 14:48:22 +01:00
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX configuration..." --weight=1
2023-01-05 14:48:22 +01:00
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
2023-01-05 14:48:22 +01:00
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
2023-01-11 19:46:20 +01:00
ynh_system_user_create --username=$app --home_dir="$datadir" --groups ssh.app --use_shell
2023-01-05 14:48:22 +01:00
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring $app main directory..." --weight=10
2023-01-05 14:48:22 +01:00
ynh_restore_file --origin_path="$final_path"
2023-01-05 14:48:22 +01:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
2023-01-05 14:48:22 +01:00
#=================================================
# RESTORE THE DATA DIRECTORY
2023-01-05 14:48:22 +01:00
#=================================================
ynh_script_progression --message="Restoring the data directory..." --weight=1
2023-01-05 14:48:22 +01:00
ynh_restore_file --origin_path="$datadir" --not_mandatory
2023-01-05 14:48:22 +01:00
mkdir -p $datadir
2023-01-05 14:48:22 +01:00
chmod 750 "$datadir"
chmod -R o-rwx "$datadir"
chown -R $app:$app "$datadir"
2023-01-05 14:48:22 +01:00
#=================================================
# RESTORE FAIL2BAN CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=1
ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
ynh_systemd_action --action=restart --service_name=fail2ban
#=================================================
# RESTORE THE DATABASE
#=================================================
ynh_script_progression --message="Restoring the database..." --weight=6
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
ynh_psql_test_if_first_run
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=5
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
ynh_restore_file --origin_path="/var/log/$app"
chown -R $app:$app "/var/log/$app"
chmod u=rwX,g=rX,o= "/var/log/$app"
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
yunohost service add $app --description="Forgejo" --log="/var/log/$app/forgejo.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=3
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/forgejo.log" --line_match="Starting new Web server: tcp:127.0.0.1:"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2023-01-05 14:48:22 +01:00
ynh_script_progression --message="Restoration completed for $app" --last