1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/timeoff_ynh.git synced 2024-09-03 20:35:59 +02:00
timeoff_ynh/scripts/restore

113 lines
3.8 KiB
Text
Raw Normal View History

2018-04-03 19:00:18 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2021-08-30 23:30:41 +02:00
source ../settings/scripts/_common.sh
2018-04-03 19:00:18 +02:00
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Loading settings..."
2018-04-03 19:00:18 +02:00
app=$YNH_APP_INSTANCE_NAME
2021-08-30 23:30:41 +02: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)
2018-04-03 19:00:18 +02:00
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Validating restoration parameters..."
2018-04-03 19:00:18 +02:00
2021-11-29 22:05:09 +01:00
test ! -d $final_path || ynh_die --message="There is already a directory: $final_path "
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# STANDARD RESTORATION STEPS
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# RESTORE THE NGINX CONFIGURATION
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Restoring the NGINX configuration..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# CREATE DEDICATED USER
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Recreating the dedicated system user..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# RESTORE THE APP MAIN DIR
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Restoring $app main directory..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
ynh_restore_file --origin_path="$final_path"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Reinstalling dependencies..."
2022-02-10 11:14:26 +01:00
ynh_install_app_dependencies $pkg_dependencies
2022-02-09 19:42:37 +01:00
2021-08-30 23:30:41 +02:00
# Install Nodejs
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# RESTORE SYSTEMD
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Restoring the systemd configuration..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# INTEGRATE SERVICE IN YUNOHOST
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Integrating service in YunoHost..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
yunohost service add $app --description="Manage employee absences" --log="/var/log/$app/$app.log"
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# START SYSTEMD SERVICE
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Starting a systemd service..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
ynh_systemd_action --service_name=$app --action=start --log_path=systemd
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# GENERIC FINALIZATION
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
2018-04-03 19:00:18 +02:00
2021-08-30 23:30:41 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
# END OF SCRIPT
2018-04-03 19:00:18 +02:00
#=================================================
2021-08-30 23:30:41 +02:00
ynh_script_progression --message="Restoration completed for $app"