#!/bin/bash

set -e
set -x

if [ "$1" = "remove" ] || [ "$1" = "upgrade" ]; then
    # Eliminar enlaces simbólicos creados en postinst
    rm -f /etc/nginx/sites-enabled/ogcore.conf
    rm -f /etc/php/8.3/fpm/pool.d/ogcore-fpm.conf
    # Deshabilitar el servicio antes de eliminarlo
    systemctl disable og-mercure || true
    systemctl stop og-mercure || true
    systemctl restart nginx || true
    systemctl restart php8.3-fpm || true
    rm -f /etc/systemd/system/og-mercure.service
    systemctl daemon-reload
fi

exit 0
