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)
|
2021-08-30 23:49:05 +02:00
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
|
|
db_user=$db_name
|
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
|
|
|
|
|
|
|
test ! -d $final_path \
|
2021-08-30 23:30:41 +02:00
|
|
|
|| 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..."
|
|
|
|
|
|
|
|
# Install Nodejs
|
|
|
|
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
|
2018-04-03 19:00:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORE
|
|
|
|
#=================================================
|
|
|
|
# HANDLE LOG FILES AND LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
mkdir -p /var/log/$app
|
2018-04-03 19:18:35 +02:00
|
|
|
touch /var/log/$app/timeoff.log
|
2018-04-03 19:00:18 +02:00
|
|
|
install_log=/var/log/$app/installation.log
|
|
|
|
touch $install_log
|
|
|
|
chown $app -R /var/log/$app
|
|
|
|
chown admin -R $install_log
|
|
|
|
|
|
|
|
# Restore logrotate configuration
|
|
|
|
ynh_restore_file "/etc/logrotate.d/$app"
|
|
|
|
|
2021-08-30 23:49:05 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE THE MYSQL DATABASE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoring the MySQL database..."
|
|
|
|
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
|
|
|
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
|
|
|
|
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
|
|
|
|
|
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"
|