my_webapp_ynh/scripts/restore
Éric Gaspar 0f3fc48543 cleaning
2024-06-23 21:51:49 +02:00

94 lines
2.7 KiB
Bash

#!/bin/bash
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore "/etc/nginx/conf.d/$domain.d/$app.d/"
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
if [ $database != "none" ]; then
ynh_script_progression "Restoring the database..."
db_name=$(ynh_app_setting_get --key=db_name)
db_user=$db_name
db_pwd=$(ynh_app_setting_get --key=db_pwd)
if [ $database == "mysql" ]; then
# FIXME ynh_mysql_create_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_db_shell < ./db.sql
elif [ $database == "postgresql" ]; then
# FIXME ynh_psql_create_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_psql_db_shell < ./db.sql
fi
fi
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression "Recreating the dedicated system user..."
if [ $with_sftp -eq 1 ]
then
groups="sftp.app"
else
groups=""
fi
ynh_system_user_create --username=$app --home_dir="$install_dir" --groups="$groups"
if [ -n "$password" ]
then
# Add the password to this user
chpasswd <<< "${app}:${password}"
fi
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression "Restoring the app main directory..."
ynh_restore "$install_dir"
# Restore permissions on app files
chown -R $app:www-data "$install_dir"
# Home directory of the user needs to be owned by root to allow
# SFTP connections
chown root:root "$install_dir"
setfacl -m g:$app:r-x "$install_dir"
setfacl -m g:www-data:r-x "$install_dir"
chmod 750 "$install_dir"
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
if [ $php_version != "none" ]
then
ynh_restore "/etc/php/${php_version}/fpm/pool.d/$app.conf"
fi
#=================================================
# RELOAD NGINX AND PHP-FPM
#=================================================
ynh_script_progression "Reloading NGINX web server and PHP-FPM..."
if [ $php_version != "none" ]
then
ynh_systemctl --service=php${php_version}-fpm --action=reload
fi
ynh_systemctl --service=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression "Restoration completed for $app"