Commit 65d52ee8 authored by C1t1z3n 0n3's avatar C1t1z3n 0n3

Update remove

parent 7f8b8607
......@@ -6,103 +6,136 @@
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
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
#=================================================
ynh_print_info --message="Loading installation settings..."
ynh_print_info --message="Loading settings..."
app=$YNH_APP_INSTANCE_NAME
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
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
db_pwd=$(ynh_app_setting_get --app="$app" --key=db_pwd)
#=================================================
# STANDARD REMOVE
# CHECK IF THE APP CAN BE RESTORED
#=================================================
# REMOVE SERVICE FROM ADMIN PANEL
ynh_print_info --message="Validating restoration parameters..."
ynh_webpath_available --domain="$domain" --path_url="$path_url" \
|| ynh_die --message="Path not available: ${domain}${path_url}"
test ! -d "$final_path" \
|| ynh_die --message="There is already a directory: $final_path "
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
# Remove a service from the admin panel, added by `yunohost service add`
if ynh_exec_warn_less yunohost service status ${app}-horizon >/dev/null
then
ynh_print_info --message="Removing ${app}-horizon service..."
yunohost service remove "${app}-horizon"
fi
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# STOP AND REMOVE SERVICE
# RESTORE THE APP MAIN DIR
#=================================================
ynh_print_info --message="Stopping and removing the systemd service..."
ynh_print_info --message="Restoring the app main directory..."
# Remove the dedicated systemd config
ynh_remove_systemd_config --service="${app}-horizon"
ynh_restore_file --origin_path="$final_path"
#=================================================
# REMOVE THE POSTGRESQL DATABASE
# RECREATE THE DEDICATED USER
#=================================================
ynh_print_info --message="Removing the PostgreSQL database..."
ynh_print_info --message="Recreating the dedicated system user..."
# Remove a database if it exists, along with the associated user
ynh_psql_remove_db --db_user="$db_user" --db_name="$db_name"
# Create the dedicated user (if not existing)
ynh_system_user_create --username="$app"
#=================================================
# REMOVE DEPENDENCIES
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R "$app": "$final_path"
#=================================================
# INSTALL PHP
#=================================================
ynh_print_info --message="Installing php..."
ynh_install_php --phpversion="7.3" --package="$extra_pkg_dependencies"
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_restore_file --origin_path="/etc/php/7.3/fpm/pool.d/$app.conf"
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
ynh_print_info --message="Removing dependencies..."
ynh_print_info --message="Reinstalling dependencies..."
# Remove metapackage and its dependencies
ynh_remove_app_dependencies
ynh_remove_php
# Define and install dependencies
ynh_install_app_dependencies "$pkg_dependencies"
#=================================================
# REMOVE APP MAIN DIR
# RESTORE THE POSTGRESQL DATABASE
#=================================================
ynh_print_info --message="Removing app main directory..."
ynh_print_info --message="Restoring the PostgreSQL database..."
# Remove the app directory securely
ynh_secure_remove --file="$final_path"
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"
#=================================================
# REMOVE NGINX CONFIGURATION
# RESTORE SYSTEMD
#=================================================
ynh_print_info --message="Removing nginx web server configuration..."
ynh_print_info --message="Restoring the systemd configuration..."
# Remove the dedicated nginx config
ynh_remove_nginx_config
ynh_restore_file --origin_path="/etc/systemd/system/${app}-horizon.service"
systemctl enable ${app}-horizon.service
#=================================================
# REMOVE PHP-FPM CONFIGURATION
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
ynh_print_info --message="Removing php-fpm configuration..."
# Remove the dedicated php-fpm config
ynh_remove_fpm_config
yunohost service add "${app}-horizon" --log "/var/log/$app/${app}-horizon.log"
#=================================================
# RESTART PHP-FPM 7.0 FPM
# START SYSTEMD SERVICE
#=================================================
ynh_print_info --message="Start php7.0-fpm..."
ynh_print_info --message="Starting a systemd service..."
#Sometimes with package_check php7.0-fpm fail to reload and stop. So starting the service, just in case.
ynh_systemd_action --service_name=php7.0-fpm --action=start
ynh_systemd_action --service_name="${app}-horizon" --action="start" --log_path=systemd
#=================================================
# GENERIC FINALIZATION
#=================================================
# REMOVE DEDICATED USER
# RELOAD NGINX AND PHP-FPM
#=================================================
ynh_print_info --message="Removing the dedicated system user..."
ynh_print_info --message="Reloading nginx web server and php-fpm..."
# Delete a system user
ynh_system_user_delete --username="$app"
ynh_systemd_action --service_name=php7.3-fpm --action=reload
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Removal of $app completed"
\ No newline at end of file
ynh_print_info --message="Restoration completed for $app"
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment