#!/bin/bash

#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source 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

#=================================================
# RETRIEVE ARGUMENTS
#=================================================

app=${YNH_APP_INSTANCE_NAME}

final_path=$(ynh_app_setting_get --app=$app --key=final_path)

#=================================================
# CHECK IF ARGUMENTS ARE CORRECT
#=================================================

#=================================================
# CHECK IF AN ACTION HAS TO BE DONE
#=================================================

# Check the current status of the maintenance mode

if [ ! -e "$final_path/.maintenance" ]
then
    ynh_die --message="WordPress isn't currently under maintenance." --ret_code=0
fi

#=================================================
# SPECIFIC ACTION
#=================================================
# DISABLE THE MAINTENANCE MODE
#=================================================

ynh_script_progression --message="Disabling maintenance mode..."

ynh_secure_remove --file="$final_path/.maintenance"

#=================================================
# END OF SCRIPT
#=================================================

ynh_script_progression --message="Execution completed" --last